How To Install and Run wkhtmltopdf on Mac OsX 10.7.3 for use in a PHP Application
Asked Answered
K

8

37

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.

Keel answered 29/4, 2012 at 19:19 Comment(3)
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?Flit
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.Keel
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).Flit
P
77

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
Plastered answered 7/6, 2012 at 11:55 Comment(5)
Brew is now installing version 0.11.0_rc1. The QT problem seems to have been fixed now too.Schnorkle
What if I need the wkhtmltoimage and not the wkhtmltopdf? what should I download?Reneta
Heavy to say: Looks like you should compile it from source. *(Plastered
Note: wkhtmltopdf --version outputs the wrong version. It's a bug in the released source: code.google.com/p/wkhtmltopdf/issues/…Sartorius
I installed one of the packages here wkhtmltopdf.org/downloads.html and it installed straight to /usr/local/bin So for me yuяi answer below is quicker than this solution. Also the link provided points to an old version 0.11.0-rc1 (Latest is 0.12.1 I think?)Mohr
E
39

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.

Earpiece answered 11/10, 2016 at 23:0 Comment(3)
brew cask install wkhtmltopdf suffices. This will also install wkhtmltoimage. Your password will be required as it simply installs the package appropriate for your system from wkhtmltopdf.org downloads page. Presumably this verifies the checksum of the downloaded pkg file for you though I haven't read the homebrew formula to verify that.Congelation
If anyone is installing wkhtmltopdf as of Dec 5 '19, this solution worksYost
I had had problems with brew install Caskroom/cask/wkhtmltopdf. Removing it, and installing with brew cask install wkhtmltopdf worked wellGalloway
C
15

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.

Counterpoint answered 14/8, 2014 at 19:7 Comment(3)
unclear why this is downvoted, works for me. wkhtmltopdf available via cli after installing pkg.Histrionic
This also worked for me. Upvoted to get it out of the negatives. My copy of homebrew couldn't find the package to install it.Mohr
Running this package messes up your /usr/local directory pretty hardcore. It install everything with sudo, giving ownership of all of it's installed components to root:wheel. Additionally, it changes ownership of /usr/local/lib, /usr/local/include, and other directories to root. I did a brew doctor after installing this package and everything was messed up. I do not recommend using this package if you use brew for other packages.Watch
P
5

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);
Poohpooh answered 5/9, 2016 at 13:31 Comment(0)
C
3

The command works for me fine:

brew install --cask wkhtmltopdf
Coercion answered 9/7, 2021 at 3:41 Comment(1)
Getting a warning Warning: wkhtmltopdf has been deprecated because it is discontinued upstream! Selfconceit
C
2

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 -
Coercion answered 31/5, 2020 at 12:5 Comment(1)
this will give an error "Error: brew cask is no longer a brew command. Use brew <command> --cask instead." the new command is brew install wkhtmltopdf --caskWittman
C
1

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

brew install wkhtmltopdf --cask
Constrict answered 6/1, 2021 at 5:25 Comment(0)
G
0

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

Grieve answered 29/4, 2012 at 19:56 Comment(4)
On Lion, brew install wkhtmltopdf installs version 0.11.0_rc1 and qt dependency version 4.8.3.Schnorkle
@MikeCauser: brew is best & simplest way to install it. thanksQuickel
Hahaha Feedback loop. Years later i needed wkhtmltopdf for a project dep and what do I find but this question that I answered 2 years ago. Yeah, still no port available via macports. I used @Plastered answer and got it up and running.Grieve
Update! currently brew cask install wkhtmltopdf works for MAC OSx CatalinaWellthoughtof

© 2022 - 2024 — McMap. All rights reserved.