How do I download wkhtmltopdf on a Mac OS X?

You can install wkhtmltopdf with homebrew-cask

brew install caskroom/cask/brew-cask
brew cask install wkhtmltopdf

Note: This cask appears to mess up the permissions in your /usr/local directory. Change the owner of /usr/local and subdirectories to yourself after installing:

chown -R your_user_name:admin /usr/local

I just needed to install the same thing for a project that converts bunch of HTML pages to a PDF.

I had to do several things to get it working on my machine. First of all, I downloaded the DMG.

After download, just click on it, it should mount automatically (if not, check out the mount commando). Now it's like a "disk" attached to your machine, usually available on your desktop.

Open it in your Finder, and inside is a wkhtmltopdf.app. You need to copy this to your Applications where all your other programs (should) reside.

Inside your terminal you can then execute the command to use wkhtmltopdf

For example:

/Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf "http://www.google.com" google.pdf

This will create a PDF called "google.pdf" from the provided URL. This is sort of annoying to type the whole path, so what I tend to do is create a symbolic link to it so I can shorten my type work (especially since I use it fairly often nowadays)

ln -s /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf wkhtmltopdf

This will create a symbolic link to wkhtmltopdf in my current directory and is called wkhtmltopdf.

The terminal input is now shortened to: wkhtmltopdf "http://www.google.com" google.pdf

There are also several params you can enter, for example when you want to convert a page that requires a user and password in order for you to access it. Note that the username & password is used to access the page, not to login in the page itself.

Your command would then look like this:

wkhtmltopdf --username "mydomain\myusername" --password "mypassword" "https://my-secure-url" ../Reports/my-pdf-name.pdf

This is basically the same as before. Just now I was required to enter my username and password for the secure site. I put the resulting PDF inside a Reports folder which is located a level above of my current location in the tree structure of folders.


You can also install it with Homebrew.

brew install wkhtmltopdf
wkhtmltopdf http://www.example.com test.pdf

wkpdf is native to OS X and has a few more options.

sudo gem install wkpdf
wkpdf --source http://www.example.com --margins 15 --output test.pdf