Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Dec 11 '12 at 17:57

This question came from our site for professional and enthusiast programmers.

    
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 '12 at 18:26
add comment

4 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
Thank you sir. How did you know to write this stuff in the terminal? –  Nick Manning Dec 28 '12 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 '13 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 '13 at 7:34
add comment

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 
share|improve this answer
add comment

brew install wkhtmltopdf fails.

I documented on StackOverflow the correct way to install wkhtmltopdf using Homebrew here: http://goo.gl/z4Fpc

share|improve this answer
add comment

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).

share|improve this answer
    
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 '12 at 14:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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