cfexecute command line

5k Views Asked by At

I've just installed wkhtmltopdf which converts webpages to pdfs.

I can run it from the command line on the server like so:

wkhtmltopdf http://www.google.co.uk c:\google.pdf

wkhtmltopdf was added added to the path environmental variable. The real path to the exe is C:\Program Files\wkhtmltopdf\wkhtmltopdf.exe

I now want to run this with ColdFusion 8 using cfexecute.

<cfexecute name="c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe"
        arguments="wkhtmltopdf http://www.google.com c:\google.pdf"
        timeout="10" />

I've tried a few different variations but can't seem to get it to work.

I've also had some "error 5 access is denied" messages but I understand this still might be a syntax issue rather than a rights issue.

Can anyone see issues with my code?

2

There are 2 best solutions below

1
On

OK GOT IT WORKING!...

<cfexecute name="c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" 
        arguments="http://www.google.com C:\google.pdf"
        timeout="10" />

Syntax is a bit different from the command line I ran in windows.

1
On

Did you know that ColdFusion has the ability to convert HTML to PDF built-in? See the cfdocument tag.

Here is a very simple example that should work:

<cfhttp method="get" url="http://www.google.com" timeout="10" />
<cfif cfhttp.StatusCode EQ "200 OK">
    <cfdocument format="PDF" localurl="false">
        <cfoutput>#cfhttp.FileContent#</cfoutput>
    </cfdocument>
<cfelse>
    <p>http request failed [<cfoutput>#cfhttp.StatusCode#</cfoutput>]</p>
</cfif>

I don't know the extent of the functionality that you need from the PDF converter but for simple conversions the cfdocument tag works pretty well.