74

I want to install pdftk with MacPorts, but this command does not work:

 sudo apt-get install pdftk

Is it possible to install it on a Mac?

My system specifications are:

Processor: 2.5 GHz Intel Core i5
Memory:    8 GB 1600 MHz DDR3
Graphics:  Intel HD Graphics 4000 768 MB
Sean Leather
  • 1,082
  • 1
  • 9
  • 22
user3061922
  • 911
  • 1
  • 6
  • 10
  • 7
    `apt-get` is for linux, have you tried `sudo port install pdftk`? – Stedy Dec 27 '13 at 16:57
  • yes, you are right. i made mistake.Great! – user3061922 Dec 27 '13 at 19:24
  • PyPDF2 provides an alternative script `pdfcat` https://pythonhosted.org/PyPDF2/Easy%20Concatenation%20Script.html just in case people still get attracted here from google search result. – Dyno Fu Mar 17 '15 at 22:39
  • You can install it from the official site https://www.pdflabs.com/tools/pdftk-server/ – ndnenkov Jan 17 '19 at 13:48
  • 2021 Jan 12: Only thing that worked on macOS Big Sur was the link from this answer: https://stackoverflow.com/a/60889993/293280. Using the download link from the official website downloads an old installer and you get a `zsh: bad CPU type in executable: pdftk` error. – Joshua Pinter Jan 12 '21 at 15:58

3 Answers3

79

From quantiverge PR on brew:

brew install https://raw.github.com/quantiverge/homebrew-binary/pdftk/pdftk.rb
Dorian
  • 19,009
  • 8
  • 108
  • 111
  • 2
    Worked for me on Mavericks. Sadly compiling from source has so many dependencies that it takes forever, so this is a nice shortcut for the meantime. – Stefan Schmidt Mar 12 '14 at 12:48
  • 2
    Still working on 10.9.5 – tdc Nov 11 '14 at 17:20
  • 9
    Works on Yosemite (OS X 10.10) as well.. :) – SexyBeast Dec 24 '14 at 07:36
  • We used the answer provided by Sean Leather, sorry couldn't find his @username it is the bottom answer on this post (as of this comment) – covard Feb 17 '15 at 16:28
  • works on Yosemite 10.10.4 (y) – Jasdeep Singh Jul 08 '15 at 17:26
  • 1
    The official install does NOT work on 10.11 beta and any and all brew installs/work arounds that I've found do NOT work either. I've had pdftk working on 10.9 and 10.10 without issues. – Aaron Sep 10 '15 at 21:12
  • 2
    Works on El Capitan 10.11 just fine! – yannis Oct 12 '15 at 21:23
  • @yannis I unfortunately had the same experience myself. Seems like it works and then just hangs. – jamescampbell Oct 20 '15 at 00:02
  • 1
    Works on Sierra 10.12 – Danny Ocean Sep 28 '16 at 13:19
  • 8
    The formula doesn't work with current brew, use `brew install https://raw.githubusercontent.com/youtux/homebrew-binary/pdftk/pdftk.rb` from [youtux's PR](https://github.com/Homebrew/homebrew-binary/pull/344) instead. – tan9 Dec 17 '16 at 14:16
  • 1
    That just installs pdftk using the official pkg installer. – kossmoboleat Apr 23 '17 at 19:56
  • 14
    Up-to-date version of this solution here: https://stackoverflow.com/a/41243285/1492782 Command is: `brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb` – Josh Buchea Jun 27 '17 at 21:03
  • 16
    Please note as of Aug 2017, none of the above works. The link posted by @JoshBuchea is the only thing that works. – SmallChess Aug 09 '17 at 01:49
  • 2018-06-12: @JoshBuchea's link worked for me: brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb – Jeffrey Knight Jun 12 '18 at 14:56
  • 11
    Error: pdftk: undefined method `sha1' for # – Krishnadas PC Sep 19 '18 at 12:59
  • 2021 Jan 12: Only thing that worked on macOS Big Sur was the link from this answer: https://stackoverflow.com/a/60889993/293280. Using the download link from the official website downloads an old installer and you get a `zsh: bad CPU type in executable: pdftk` error. – Joshua Pinter Jan 12 '21 at 15:58
65

You can use the official installer from PDF Labs.

Edit: It’s now available through homebrew-cask too. If you have that installed, you can just run

brew cask install pdftk

to install pdftk.

There is no longer a Cask package available, so you will have to defer to the original solution or follow this workaround

sjagr
  • 14,280
  • 4
  • 37
  • 63
bdesham
  • 13,980
  • 10
  • 70
  • 116
  • 3
    Looks like it's now available via homebrew-cask, which is nice if you like to keep your CLI software in a managed state. – Peter Jan 27 '14 at 14:04
  • @Peter I’ve edited my answer. Thanks for the tip! – bdesham Jan 27 '14 at 14:54
  • 5
    just adding something that came up to me - I needed run `brew update && brew upgrade brew-cask` – Jonatas CD May 20 '14 at 17:23
  • 1
    @JonatasCD Thanks for the command. It worked after I updated and upgraded. – johnnygoodman Jul 01 '14 at 15:34
  • thanks for pointing me out to homebrew-cask! nice addon – geekymartian Sep 13 '14 at 00:56
  • 6
    An anonymous user points out that pdftk has temporarily been removed from homebrew-cask due to [this issue](https://github.com/caskroom/homebrew-cask/issues/7707). Follow that link for more information. – bdesham Dec 04 '14 at 18:18
  • 10
    It is not working anymore. – Puce Jan 12 '15 at 11:14
  • @Puce I get an error trying to install also. What is the best way to install it? – covard Feb 17 '15 at 00:44
  • @covard In our project decided to use a pure Ubuntu VM through Vagrant as pdftk and other plugins have issues in Mac. – Puce Feb 17 '15 at 09:50
  • @covard Have you tried the PDF Labs installer I mentioned at the beginning of the answer? – bdesham Feb 17 '15 at 14:37
  • Here's a [step-by-step copy-paste `brew cask install pdftk` workaround](https://gist.github.com/jvenator/9672772a631c117da151) -- worked perfectly for me. – Joel Purra Apr 15 '15 at 11:04
  • 1
    @JoelPurra I [forked the gist](https://gist.github.com/scottgwald/631123afbe3038bc3ed4) and added all the commands to a script. That can be run instead of doing 15 copy-pastes. – scottgwald May 18 '15 at 10:16
  • @scottgwald: didn't have the time when I found the gist, so happy that you did it. Great, thanks! – Joel Purra May 18 '15 at 13:09
  • @JoelPurra sure thing! time will tell how brittle all of those paths are, haha – scottgwald May 18 '15 at 18:36
  • The official install does NOT work on 10.11 beta and any and all brew installs/work arounds that I've found do NOT work either. I've had pdftk working on 10.9 and 10.10 without issues. – Aaron Sep 10 '15 at 21:11
  • 11
    In case anyone is still looking, this is the download link that works on El Capitan. [https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg) – jamescampbell Nov 25 '15 at 13:53
  • 2021 Jan 12: Only thing that worked on macOS Big Sur was the link from this answer: https://stackoverflow.com/a/60889993/293280. Using the download link from the official website downloads an old installer and you get a `zsh: bad CPU type in executable: pdftk` error. – Joshua Pinter Jan 12 '21 at 15:58
39

I created a pdftk homebrew tap:

brew tap spl/pdftk
brew install pdftk

The current formula depends on a specific compiler (gcc48) with a specific build flag (enable-all-languages). This is only be a problem if you happen to already have gcc48 without the flag or if you have a different version of gcc. You can, of course, clone the formula and change it for your situation. But, unfortunately, nobody has answered my question about alternative dependencies, so I don't know how to resolve this.

Update 1 (2015-03-19): As of this change (described in my solution to alternative dependencies), the formula now supports multiple versions of gcc and different flags.

Update 2 (2016-01-12): For OS X 10.11 El Capitan users, the source build of pdftk does not seem to work. There is a .pkg available at https://stackoverflow.com/a/33248310/545794 . As of this date, PDF Labs has not yet released a source update that fixes the build.

Community
  • 1
  • 1
Sean Leather
  • 1,082
  • 1
  • 9
  • 22
  • 2
    it takes forever on my pro late 2011 to install gcc, not my way – gaussblurinc Apr 08 '15 at 20:26
  • I have found the same as @gaussblurinc. Mid 2011 iMac - taking an age to install the gcc dependency. Far more tempted to ditch pdftk and find a lighter alternative. – freethebees Jun 02 '15 at 14:39
  • This took forever for me too. I used the answer below (install from `raw.github.com` and it's working fine) – jraede Jul 10 '15 at 02:31
  • @Aaron, Does my Homebrew tap also not work? It installs from source and not from the `.pkg`. – Sean Leather Sep 11 '15 at 10:34
  • 4
    I tried to install from Homebrew and the install worked on 10.11, yes -- but the actual executable just hangs anytime you try to run commands. Warning: I've been using pdftk for over a year and installed from Homebrew and from www.pdflabs.com at times, and things worked fine. After 10.11 nothing works no matter how you install it. So pdftk is broke on 10.11. Here's my SO question on the topic: http://stackoverflow.com/questions/32505951/pdftk-server-on-os-x-10-11 – Aaron Sep 11 '15 at 20:50
  • @Aaron I've had the same broken experience myself so far. – jamescampbell Oct 20 '15 at 00:02
  • @Poulsbo see: http://stackoverflow.com/questions/32505951/pdftk-server-on-os-x-10-11 – Aaron Dec 02 '15 at 15:29
  • @Aaron Thanks! Yes, this worked for me: http://stackoverflow.com/a/33248310/177203 – Poulsbo Dec 02 '15 at 19:23
  • Thanks for the comments, folks. I've updated my answer to point to the other answer. If you discover a way to build a working (possibly patched) `pdftk` from source on El Capitan, please let me know (either here or on GitHub). – Sean Leather Jan 12 '16 at 07:27
  • Thanks for the second update... the docmunch cask tap seems to be hanging on an OSX patch. But the link to the .pkg helped me get it installed. – Ben Johnson Jan 25 '16 at 19:56
  • @SeanLeather the installation does not work anymore. It gets stuck at installing gcc 6.3.0 – hyde Jan 31 '17 at 16:21
  • 2021 Jan 12: Only thing that worked on macOS Big Sur was the link from this answer: https://stackoverflow.com/a/60889993/293280. Using the download link from the official website downloads an old installer and you get a `zsh: bad CPU type in executable: pdftk` error. – Joshua Pinter Jan 12 '21 at 15:58