30
votes

I've written a PHP/MySQL application that utilizes wkhtmltopdf to generate reports from data entered into the database. The client asked that I also install it to run as a standalone on a Mac that he has. Currently have the PHP/MySQL portion running without difficulty using XAMMP, but am having incredible difficulty getting wkhtmltopdf even installed on the system.

I have zero experience with Macs, and despite five hours of Googling and trying different approaches, I cannot even copy the most recent wkhtmltopdf .i386 into the /usr folder. Oddly, the laptop doesn't have a /usr/local/bin folder.

Unless I've missed it, I can't find simple instructions on how to get this thing working and would greatly appreciate any help that could be offered.

8
From what I can remember, I just copied a binary from their download page and popped it into my personal bin folder (~/bin). I may have had to chmod u+x but that was it, I believe. If you're copying to /usr/* then you may need to do sudo cp, but other than that, can you outline specifically what your trouble is?halfer
I've tried using the dmg file and drag and drop to apps folder, but I don't get something that's executable. When I browse the contents I can see the wkhtmltopdf unix app...if I move this to usr/local/bin I can run it from the Terminal, but then I get an error that "qt_meni.nib" could not be loaded. I tried the previous version .i386 binary and put it in usr/local/bin --- but get a "comman not found" when I try to run it from terminal. I'm totally dying here; something that took all of two minutes in Win7 has already sucked like 8 hours of time without a resolution.brizandt
Hmm, not sure - I forget how I did mine. There was zero hassle, afair. Try downloading the source version and compiling it (see the README for instructions, usually it's make and make install).halfer

8 Answers

73
votes

Homebrew only has wkhtmltopdf-0,9,9 and it fails with QT patched options by default. So if you need HEAD version with fully suppoorted options just

  • Grab yourself a copy of fresh wkhtmltopdf
  • Open it and drag to Applications
  • Then cd /usr/local/bin && ln -s /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf wkhtmltopdf
27
votes

If you have Homebrew installed run: brew install wkhtmltopdf

That will also install wkhtmltoimage.

Alternatively, you can download the compiled binaries from http://wkhtmltopdf.org/downloads.html and place them somewhere in your path like /usr/local/bin. If you plan on running your script in another environment like a server or App Engine, this is the way to go.

14
votes

This seems to have easy to install packages:

http://wkhtmltopdf.org/downloads.html

I successfully installed the OS X 10.6+ (Cocoa) 64-bit on my OSX 10.9.4 by simply running the pkg. Using it for the PDFKit Rails gem.

3
votes

For anyone trying to use mikehaertl\wkhtmlto\Pdf with MAMP make sure you install the latest version for Mac http://wkhtmltopdf.org/downloads.html and define the binary parameter.

$options = array(
    'page-size' => 'Letter',
    'orientation' => 'portrait',
    'binary' => '/usr/local/bin/wkhtmltopdf'
);

$pdf = new Pdf($options);
1
votes

You will need to run the command in the terminal before the PDF creation:

brew cask install wkhtmltopdf

When I create the PDF, I get this log in the server:

2020-05-31 17:20:10.657  INFO 11168 --- [io-8080-exec-10] c.g.jhonnymertz.wkhtmltopdf.wrapper.Pdf  : Initialized with {xvfbConfig=null, wkhtmltopdfCommand='/usr/local/bin/wkhtmltopdf'}
2020-05-31 17:20:20.166  INFO 11168 --- [io-8080-exec-10] c.g.jhonnymertz.wkhtmltopdf.wrapper.Pdf  : PDF successfully generated with: /usr/local/bin/wkhtmltopdf -B 0 -L 0 -R 0 -T 0 --page-width 148 --page-height 212 /var/folders/0c/_vpt6xnj71ng91nm9kk5jw3w0000gn/T/java-wkhtmltopdf-wrapper6721963b-6a8c-4260-9ac6-a545920d1ab117331429448032181725.html -
1
votes

The command works for me fine:

brew install --cask wkhtmltopdf
0
votes

Lion (10.7) doesnt make /usr/local anymore, but you can create it.

If the package you want doesnt have a an installer for the binaries then you'll have to compile from source. Im which case all the instructions you need should be available from the download site for the package.

The other option would be to see if its available in any of the OS X package managers (Fink, MacPorts, Homebrew). If it is you could install everything that way. I can say its not in the MacPorts repository - i checked :-)

UPDATE: Homebrew seems to have it...

0
votes

I was struggling to install wkhtmltopdf but after some research this helped me to install it on a MAC OSx

brew install wkhtmltopdf --cask