Copy link to clipboard
Copied
I have batch file which run script to convert word to pdf .When directly run batch file conversion done perfectly.
When I try to use coldfusion cfexecute to run the batchfile it take continuously execute until browser close no error and no output .
My cfm file and bat file location is D drive
<cfexecute name="C:\Windows\System32\cmd.exe" timeout="2000">
cd /D D:\home\docxtopdf
bulk-convert-Word2PDF.bat
</cfexecute>
My batch file :
echo off
for %%X in (*.docx) do cscript.exe //nologo SaveAsPDF.js "%%X"
for %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js "%%X"
My SaveAsPDF.js
ar obj = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
docPath = obj.GetAbsolutePathName(docPath);
var pdfPath = docPath.replace(/\.doc[^.]*$/, ".pdf");
var objWord = null;
var wdAlignPageNumberCenter = 1;
var wdPageNumberStyleLowercaseRoman=46
try
{
objWord = new ActiveXObject("Word.Application");
objWord.Visible = false;
var objDoc = objWord.Documents.Open(docPath);
objDoc.Sections(1).Footers(1).PageNumbers.Add(wdAlignPageNumberCenter);
objDoc.Sections(1).Footers(1).PageNumbers.NumberStyle = wdPageNumberStyleLowercaseRoman;
var format = 17;
objDoc.SaveAs(pdfPath, format);
objDoc.Close();
WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
}
finally
{
if (objWord != null)
{
objWord.Quit();
}
}
Help me with some solution to work with it
@defaultne3mldqroexz , I modified your code just a little bit, and it works! 🙂
The steps:
1. Change the contents of the batch file bulk-convert-Word2PDF.bat to:
@echo off
cd /D D:\home
for %%X in (*.docx) do cscript.exe //nologo SaveAsPDF.js "%%X"
for %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js "%%X"
2. Ensure that the file paths are as follows (where testDoc1.docx and testDoc2.doc are the files to be converted to PDF):
D:\home\SaveAsPDF.js
D:\home\bulk-convert-Word2PDF.bat
...
Copy link to clipboard
Copied
I think you should let ColdFusion execute the batch directly. Assuming that the batch file is in D:\home\, I would try something like:
<cfexecute name="D:\home\bulk-convert-Word2PDF.bat" arguments="D:\home\docxtopdf" timeout="2000">
Copy link to clipboard
Copied
Hi I tried already to exceute it, no error throw , in browser it shows C:\ColdFusion2016\cfusion\bin>echo off
conversion never done.
Copy link to clipboard
Copied
Hmm, you're right. I, too, had the same experience with a batch conversion in C:\temp. The ColdFusion path "C:\ColdFusion2021\cfusion\bin" was thrown into the mix.
In spite of this, I did a trick and it got the conversions with cfexecute to work. I am sure yours will, too. But there is still a problem we have to solve.
The procedure to try is as follows:
<!--- Timeout of 120 seconds should be sufficient --->
<cfexecute name="D:\home\bulk-convert-Word2PDF.bat" timeout="120" />
Did that work for you?
If so, then the problem that remains to be solved is how to do a DOS cd to avoid having to use C:\ColdFusion2016\cfusion\bin.
Copy link to clipboard
Copied
I would recommend putting the "cd /D D:\home\docxtopdf" after the "echo off" line in the batch file.
You can even add a "pwd" command to display the current working directory.
Also, add variable="variables.result" to your cfexecute tag and then do the following in your CF script:
<cfoutput>
<pre>#variables.result#</pre>
</cfoutput>
That way you will see the output from the batch file.
Copy link to clipboard
Copied
I already try it take long time to run. no error.
If I change the path in javacript file to D location it throw error
C:\Coldfusion2016\cfusion\bin>echo off CScript Error:Execution of the Windows Script Host Failed ()x80020102)
Copy link to clipboard
Copied
I try your method it run for long time no output.
Copy link to clipboard
Copied
I try to use com object Word Application for alternate method but it also throw class not registered,
I am using Coldfsuion2016 64bit and Ms office standard 2013
Copy link to clipboard
Copied
@defaultne3mldqroexz , I modified your code just a little bit, and it works! 🙂
The steps:
1. Change the contents of the batch file bulk-convert-Word2PDF.bat to:
@echo off
cd /D D:\home
for %%X in (*.docx) do cscript.exe //nologo SaveAsPDF.js "%%X"
for %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js "%%X"
2. Ensure that the file paths are as follows (where testDoc1.docx and testDoc2.doc are the files to be converted to PDF):
D:\home\SaveAsPDF.js
D:\home\bulk-convert-Word2PDF.bat
D:\home\testDoc1.docx
D:\home\testDoc2.doc
3) Launch a CFM page containing the code:
<cfexecute name="D:\home\bulk-convert-Word2PDF.bat" timeout="120" />