3

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?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Sam
  • 444
  • 1
  • 4
  • 14
  • 1
    Your cfexecute is wrong - check [the docs](http://cfdocs.org/cfexecute) and you'll see the `variable` attribute is the CFML variable any response is stored in; you want `arguments` for the parameters passed to the executable. – Peter Boughton Dec 14 '12 at 17:52
  • oops yeah I forgot to swap that over. I've made the edit above. Still no good. – Sam Dec 14 '12 at 17:59

2 Answers2

5

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.

Sam
  • 444
  • 1
  • 4
  • 14
0

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.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63