Saturday, October 6, 2012

The incredible batch call of wkhtmltopdf

Like extra credit, this command line combined nearly everything I've done recently all at once. Within cygwin, I'm using find on a directory with the -exec option, and calling wkhtmltopdf on every file found. The only clunky thing about this method is that it makes .htm.pdf files which I have to rename to .pdf.

find . -name "D*.htm" -exec cmd /C "C:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" -s Letter {} {}.pdf \;

The awesome trick was doing this in cygwin. For some reason, wkhtmltopdf wasn't running in cygwin naitive mode (it is a GnuWin utility in the form that I have it in), so I found from the below blog how to use cmd /C and I stuck the whole thing into the -exec of find and it somehow worked.

Yes, well, the downside is that I have to trim an extra .htm out of the pdf filename, I suppose that a real unix master would run the result of find through something else to trim the orignal suffix off before passing it into cmd /C, I should figure that out some day.

http://siddesh-bg.blogspot.com/2012/07/how-to-run-dos-commands-from-cygwin.html