I need to be able to automatically generate pdf files which contain puzzles with random numbers. The best way I can think of do to this given my knowledge is to make it with Javascript/HTML/CSS and convert this to a PDF with a program, but other suggestions are welcome.

Anyway, so I tried downloading the program from this website but I ran into a few problems. First of all, from the list on the side, what should I download? I just see a bunch of random numbers and file extensions that don't mean anything to me. I tried the top one on the list and the one called "wkhtmltopdf.dmg".

Secondly, once I download the file, how do I install and use the program? It seems that on most files I have downloaded, it gives me a .dmg file. I don't know what a .dmg file is, but usually when I download stuff I just somehow know what to click on and suddenly the program is running. In this case, the .dmg file doesn't lead to anything, and I think I am expected to go into the terminal and work some magic. I tried using terminal but I just don't understand how it works. I was able to "cd" my way to the folder containing the file I downloaded. Then I tried running the commands that the link above told me to run: wkhtmltopdf www.myhomepage.com myhomepage.pdf. However, I keep getting wkhtmltopdf: command not found.

It's a common theme in my life that I can't figure out how to install anything unless it is wildly obvious how to install it (click icon, installer leads through steps, drag to application folder, run program). What is the piece of knowledge that I am missing? What is the book I haven't read yet that explains why I don't understand something so simple?

Thank you!

  • This article written recently on October 3rd 2012 may be useful Convert HTML Page To a PDF Using Open Source Tool [ Linux / OS X / Windows ] cyberciti.biz/open-source/… Usually once you downloaded a.dmg file you double click on it, and there should be an app inside to drag n drop to the applications folder or drag n drop to applications folder inside your finder window. Then u launch the program from inside the applications folder.
    – Simon
    Dec 11, 2012 at 18:26

6 Answers 6


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.

  • Thank you sir. How did you know to write this stuff in the terminal? Dec 28, 2012 at 0:48
  • I know it's a bit late to answer but here goes. when it comes to using wkhtmltopdf in the terminal, you should see a basic help when trying to execute the wkhtmltodpf without arguments. You can also get more detailed info by using the -H argument (extended-help)
    – 3xil3
    Jan 7, 2013 at 11:53
  • I suggest creating the symbolic link into the /usr/local/bin directory. The current working directory may not and should not be on your path.
    – gdelfino
    Dec 2, 2013 at 7:34

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

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 
  • 9
    This is no longer available in Brew
    – Trip
    Jun 11, 2015 at 13:31
  • 13
    @Trip, it's been updated to brew install Caskroom/cask/wkhtmltopdf
    – Davi Lima
    Dec 13, 2016 at 14:45

brew install wkhtmltopdf fails.

I documented on StackOverflow the correct way to install wkhtmltopdf using Homebrew here: https://stackoverflow.com/a/14043085/307308


Uh, guys, a .dmg is a disk image. You mount the disk image first. You do this by double clicking on it. Then go to Finder, find the newly mounted disk image (something that is there that wasn't there before is a dead give away). Click on the image to see what's inside. Most of the time you'll find an Application in there (or an app installer).

  • 1
    Correct about installing an app from a DMG. In this case the DMG of wkhtmltopdf contains a version that has known issues. The last working version of wkhtmltopdf on OS X is 0.9.9.
    – scarver2
    Dec 27, 2012 at 14:42

This is no longer available in Brew. As correctly pointed out by @Davi Lima, the new command is

brew install Caskroom/cask/wkhtmltopdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.