i have a batch file preparing word files by renaming and relocating them. so that i make pdf for this files using a javascript code i ve found in this website. i call it as follows;
for %%g in ("test\*.doc") do (cscript.exe //nologo "SAVEASPDF.js" "%%~fg")
this JavaScript code is in another file as saveaspdf.js
to make PDF.
can i embed a JS code inside the batch file (e.g. as a :FUNCTION
) to keep all the code in a single file only?
here is the JS i m trying to embed, i found it here in this website.
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();
}
}