Last active
October 5, 2017 15:58
-
-
Save ckunte/994a0894575555f27dda2b6de9239ece to your computer and use it in GitHub Desktop.
Save both files in the folder containing Word files and run .\w2p.bat in PowerShell to batch convert all Word files in the folder to PDF files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo off | |
for %%X in (*.doc) do cscript.exe //nologo word2pdf.js "%%X" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fso = new ActiveXObject("Scripting.FileSystemObject"); | |
var docPath = WScript.Arguments(0); | |
docPath = fso.GetAbsolutePathName(docPath); | |
var pdfPath = docPath.replace(/\.doc[^.]*$/, ".pdf"); | |
var objWord = null; | |
try | |
{ | |
WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'..."); | |
objWord = new ActiveXObject("Word.Application"); | |
objWord.Visible = false; | |
var objDoc = objWord.Documents.Open(docPath); | |
var wdFormatPdf = 17; | |
objDoc.SaveAs(pdfPath, wdFormatPdf); | |
objDoc.Close(); | |
WScript.Echo("Done."); | |
} | |
finally | |
{ | |
if (objWord != null) | |
{ | |
objWord.Quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment