prerequisites: you have to have ms office with the version which lets you save docs as pdf
two steps
first create this script file to use ms office plugin and name it as conv.js
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();
}
}
then run this powershell command
Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true } | ForEach-Object -Process {$_.FullName} | %{cscript //nologo conv.js $_}
two steps
first create this script file to use ms office plugin and name it as conv.js
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();
}
}
then run this powershell command
Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true } | ForEach-Object -Process {$_.FullName} | %{cscript //nologo conv.js $_}
Comments
Post a Comment