How do I download wkhtmltopdf on a Mac OS X?
Solution 1
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.
Solution 2
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
Solution 3
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
Solution 4
brew install wkhtmltopdf
fails.
I documented on StackOverflow the correct way to install wkhtmltopdf using Homebrew here: https://stackoverflow.com/a/14043085/307308
Related videos on Youtube
Nick Manning
Updated on September 18, 2022Comments
-
Nick Manning over 1 year
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 gettingwkhtmltopdf: 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!
-
Simon over 11 yearsThis 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.
-
-
scarver2 over 11 yearsCorrect 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.
-
Nick Manning over 11 yearsThank you sir. How did you know to write this stuff in the terminal?
-
3xil3 over 11 yearsI 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)
-
gdelfino over 10 yearsI suggest creating the symbolic link into the /usr/local/bin directory. The current working directory may not and should not be on your path.
-
Trip almost 9 yearsThis is no longer available in Brew
-
Davi Lima over 7 years@Trip, it's been updated to
brew install Caskroom/cask/wkhtmltopdf