Skip to content

Instantly share code, notes, and snippets.

@jeffcoughlin
Created January 27, 2017 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffcoughlin/636335576815833cbdf2ec35d251f893 to your computer and use it in GitHub Desktop.
Save jeffcoughlin/636335576815833cbdf2ec35d251f893 to your computer and use it in GitHub Desktop.
wkhtml2pdf example for CF on Windows
<cfscript>
var aOptions = [
'--load-error-handling "ignore"',
'--margin-top "20mm"',
'--margin-bottom "15mm"',
'--page-size "Letter"',
'--header-html "#uriWithoutFile#/header_all.cfm"',
'--header-spacing "5"',
'--footer-html "#uriWithoutFile#/footer_all.cfm"',
'--footer-spacing "3"',
'--title "#title##((subTitle neq "") ? ", #subTitle#" : "")#"',
'cover "#uriWithoutFile#/cover.cfm?title=#title#&subTitle=#subTitle#"',
'toc',
'"#uriWithoutFile#/index.cfm?recordId=#arguments.recordId#"',
'"#destinationFolder#\#filename#"'
];
// Generate the PDF
cfexecute(name='#executable#', arguments='#arrayToList(aOptions, " ")#', timeout = "300"); // 5 minute timeout
// Final code runs something like the next line (I'm running my code on Windows, but it can be easily modified for other OS's). You should be able to just copy and paste this at the command prompt and it will generate the PDF (just make sure to replace [DOMAIN_NAME] accordingly):
// ./wkhtmltopdf --margin-top "20mm" --margin-bottom "15mm" --page-size "Letter" --header-html "http://[DOMAIN_NAME]/pdf/header.cfm" --header-spacing "5" --footer-html "http://[DOMAIN_NAME]/pdf/footer.cfm" --footer-spacing "3" --title "My Cool Title, 1st Quarter 2017" cover "http://[DOMAIN_NAME]/pdf/cover.cfm" toc "http://[DOMAIN_NAME]/pdf/index.cfm" "E:\my\destination\path\test1.pdf"
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment