This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOffice2PDF.ahk
51 lines (45 loc) · 1.54 KB
/
Office2PDF.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Msgbox, 请关闭所有需要转换的文档
FileSelectFolder, officeFolder,,, 选择原始文档所在目录
FileSelectFolder, pdfFolder,,, 选择PDF输出目录
ComObjError(false)
wordApp:=comobjcreate("word.application")
Loop, %officeFolder%\*.doc?, , 1
{
StringReplace, outFolder, A_LoopFileDir, %officeFolder%, , All
SplitPath, A_LoopFileName,,,, outNameNoExt
FileCreateDir, %pdfFolder%%outFolder%
outputFile:= pdfFolder . outFolder . "\" . OutNameNoExt
doc2pdf(wordApp, A_LoopFileLongPath, outputFile)
}
wordApp.quit(0)
pptApp:=comobjcreate("Powerpoint.Application")
Loop, %officeFolder%\*.ppt?, , 1
{
StringReplace, outFolder, A_LoopFileDir, %officeFolder%, , All
SplitPath, A_LoopFileName,,,, outNameNoExt
FileCreateDir, %pdfFolder%%outFolder%
outputFile:= pdfFolder . outFolder . "\" . OutNameNoExt
ppt2pdf(pptApp, A_LoopFileLongPath, outputFile)
}
pptApp.quit
Loop, %officeFolder%\*.pdf, , 1
{
StringReplace, outFolder, A_LoopFileDir, %officeFolder%, , All
FileCreateDir, %pdfFolder%%outFolder%
outFolder:= pdfFolder . outFolder . "\"
FileCopy, %A_LoopFileLongPath%, %outFolder%
}
Run, %pdfFolder%
doc2pdf(wordApp, docFile, pdfFile){
wdFormatPDF:=17
wordApp.documents.Open(docFile)
wordApp.documents(1).ExportAsFixedFormat(pdfFile, wdFormatPDF)
wordApp.visible:=0
word.documents(1).Close
}
ppt2pdf(pptApp, pptFile, pdfFile){
ppSaveAsPDF:=32
pptApp.Presentations.Open(pptFile,,,0)
pptApp.Presentations(1).SaveAs(pdfFile, ppSaveAsPDF)
pptApp.Presentations(1).Close
}