Wednesday, 26 June 2013

batch pdf maker from command line


Every once and a while i have about 50 pdf files i need to create from a bunch of .html files i have locally on my machine.   Here's a quick and easy way to convert those html files into pdf from the osx command line.

firstly install wkpdf.   Its free.

wkpdf is an open-source software project. Its source code is hosted at github.com. For easy installation wkpdf is available as a Ruby gem package from rubygems.org, which means that wkpdf can be easily installed on Mac OS X 10.5.x and later with the RubyGems package manager that comes pre-installed with Mac OS X.

Installing wkpdf requires a recent version of RubyGems. If you don't have installed RubyGems version 1.3.3 or later, you need to update to the latest version with:

sudo gem update --system
Now you are ready to proceed with the installation of wkpdf with the the following command:

sudo gem install wkpdf
After wkpdf has been installed once, you can always update to the latest version with:

gem update wkpdf


for a list of options simply type:
wkpdf --help

but a standard way to use it might look something like this:
wkpdf --source http://www.slashdot.org --print-background yes --no-paginate --output sd.pdf


now that you've got wkpdf installed and working here's a simple for-loop command to process any number of .html files in a folder.

type the following into your terminal window after you've navigated to the folder of html files:
for i in *.html; do wkpdf --source "$i" --print-background yes --no-paginate --output $i.pdf; done

and now you have 50 pdf files that are scaled to the size of each html file and you don't have to worry about acrobat or safari and their pagination issues regarding the default 8.5x11 page size.

No comments:

Post a Comment