Batch Convert HTML files to PDF with wkhtmltopdf in Mac OSX

The open source (LGPL) command line tool wkhtmltopdf can quickly and robustly transform HTML files to PDF. To transform a set of files, navigate to the desired folder and enter into the Terminal app the syntax:

for f in *F1F*.html; do wkhtmltopdf -g -s Letter --no-background "$f" "${f/_*_/_}.pdf";done

The syntax takes every HTML file in a folder and generates from it a PDF file. The wkhtmltopdf command options modify the files generated: -g sets greyscale, -s Letter sets paper size, and --no-background omits background content. For more options check out the wkhtmltopdf auto-generated manual.

Advertisement