Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Cfexecute problem

Community Beginner ,
Jun 29, 2021 Jun 29, 2021

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

 

 

 

 

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 03, 2021 Jul 03, 2021

@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

 

...
Translate
Community Expert ,
Jun 30, 2021 Jun 30, 2021

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">

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 30, 2021 Jun 30, 2021

Hi  I tried already to exceute it, no error throw , in browser it shows C:\ColdFusion2016\cfusion\bin>echo off

conversion never done.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2021 Jul 01, 2021

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:

 

  1. Taking the hint from ColdFusion, copy the files bulk-convert-Word2PDF.bat and SaveAsPDF.js to C:\ColdFusion2016\cfusion\bin.
  2. Copy some *.docx and/or *.doc files to C:\ColdFusion2016\cfusion\bin.
  3. Execute the batch file from any location where it is present, for example, from D:\home\bulk-convert-Word2PDF.bat:
<!--- 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 01, 2021 Jul 01, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2021 Jul 01, 2021

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2021 Jul 01, 2021

I try your method it run for long time no output.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2021 Jul 01, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2021 Jul 03, 2021
LATEST

@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" />

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources