Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PDFtk Server Install Workaround for Mac OS X

Installing PDFtk Server edittion on your Mac

This workaround install is necessary because PDFtk was pulled from homebrew-cask due to issues with it aggressively overwriting file permissions that could impact other installed libraries. See this homebrew-cask issue.
The following steps worked on Mac OS X 10.10.1 with a standard brew installation for the PDFtk Mac OS X server libary version 2.02.
All Terminal commands separated by a full line space. Some commands wrap into multiple lines.

Download and extract the Mac OS X server install pacakge

curl -o ~/Downloads/pdftk_download.pkg https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.6-setup.pkg
pkgutil --expand ~/Downloads/pdftk_download.pkg ~/Downloads/pdftk_package

Now create directories for where it would go with a proper brew install.

*NOTE: I had no prior install of PDFtk via brew-cask when doing this. Not sure how having multiple versions installed might affect brew link and these instructions.

cd ~ && mkdir /usr/local/Cellar/pdftk /usr/local/Cellar/pdftk/2.02 /usr/local/Cellar/pdftk/2.02/bin /usr/local/Cellar/pdftk/2.02/lib /usr/local/Cellar/pdftk/2.02/share /usr/local/Cellar/pdftk/2.02/share/man /usr/local/Cellar/pdftk/2.02/share/man/man1

Here are the individual directories being created above (assume being in cd ~ directory).

mkdir /usr/local/Cellar/pdftk

mkdir /usr/local/Cellar/pdftk/2.02

mkdir /usr/local/Cellar/pdftk/2.02/bin

mkdir /usr/local/Cellar/pdftk/2.02/lib

mkdir /usr/local/Cellar/pdftk/2.02/share

mkdir /usr/local/Cellar/pdftk/2.02/share/man

mkdir /usr/local/Cellar/pdftk/2.02/share/man/man1

Give the Payload file the proper gzip file extension and unzip it

mv ~/Downloads/pdftk_package/pdftk.pkg/Payload ~/Downloads/pdftk_package/pdftk.pkg/payload.gz
gunzip ~/Downloads/pdftk_package/pdftk.pkg/payload.gz

Use cpio to unarchive the resulting file

cd ~/Downloads/pdftk_package/pdftk.pkg/ && cpio -iv < ~/Downloads/pdftk_package/pdftk.pkg/payload && cd ~

Move the relevant extracted files to their appropriate locations within the Cellar/pdftk directory

cd ~ && mv Downloads/pdftk_package/pdftk.pkg/bin/pdftk /usr/local/Cellar/pdftk/2.02/bin/pdftk && mv Downloads/pdftk_package/pdftk.pkg/lib/* /usr/local/Cellar/pdftk/2.02/lib/ && mv Downloads/pdftk_package/pdftk.pkg/man/pdftk.1 /usr/local/Cellar/pdftk/2.02/share/man/man1/pdftk.1

Or the individual file moves (assume being in cd ~ directory)

mv Downloads/pdftk_package/pdftk.pkg/bin/pdftk /usr/local/Cellar/pdftk/2.02/bin/pdftk
mv Downloads/pdftk_package/pdftk.pkg/lib/* /usr/local/Cellar/pdftk/2.02/lib/
mv Downloads/pdftk_package/pdftk.pkg/man/pdftk.1 /usr/local/Cellar/pdftk/2.02/share/man/man1/pdftk.1

Create the appropriate symlinks through brew

brew doctor

and most likely then

brew link pdftk

@covard

This comment has been minimized.

Copy link

@covard covard commented Feb 20, 2015

Thank you for this. It helped out a ton.

@suburbanworrier

This comment has been minimized.

Copy link

@suburbanworrier suburbanworrier commented Feb 23, 2015

Me too. Thanks

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Apr 18, 2015

Thank you.

@noisufnoc

This comment has been minimized.

Copy link

@noisufnoc noisufnoc commented Apr 24, 2015

Great info, thanks!

@tylerhoran

This comment has been minimized.

Copy link

@tylerhoran tylerhoran commented May 17, 2015

Thanks!

@fro

This comment has been minimized.

Copy link

@fro fro commented Jun 17, 2015

Awesome, thank you for sharing

@lavary

This comment has been minimized.

Copy link

@lavary lavary commented Jul 1, 2015

Thanks!

@dcorlett

This comment has been minimized.

Copy link

@dcorlett dcorlett commented Aug 6, 2015

The cpio command didn't work for me... it wanted payload.gz explicitly. I just changed cd ~/Downloads/pdftk_package/pdftk.pkg/ && cpio -iv < ~/Downloads/pdftk_package/pdftk.pkg/payload && cd ~ to cd ~/Downloads/pdftk_package/pdftk.pkg/ && cpio -iv < ~/Downloads/pdftk_package/pdftk.pkg/payload.gz && cd ~ and it worked perfectly. Thanks!

@Malcriado415

This comment has been minimized.

Copy link

@Malcriado415 Malcriado415 commented Aug 11, 2015

This is great. Thank you so much.

@arieljatib

This comment has been minimized.

Copy link

@arieljatib arieljatib commented Aug 26, 2015

great stuff - ¡muchas gracias!

@aadamsx

This comment has been minimized.

Copy link

@aadamsx aadamsx commented Sep 8, 2015

I've been doing form fills with pdftk for a while now, and prior to 10.11 beta everything was fine. Once I installed the beta I can't execute anything from command line (or in my application -- it just hangs. There's an issue with the beta. I've filed a issue but no response from Apple. I can run the same commands from my windows box and everything is fine too. I'm not sure what's going on.

@aadamsx

This comment has been minimized.

Copy link

@aadamsx aadamsx commented Sep 10, 2015

This method doesn't work on OSX 10.11

@grantmcconnaughey

This comment has been minimized.

Copy link

@grantmcconnaughey grantmcconnaughey commented Oct 6, 2015

No such luck. 😦 Trying to use the fill_form command. Just hangs.

@sethetter

This comment has been minimized.

Copy link

@sethetter sethetter commented Oct 6, 2015

pdftk is just hanging for me as well. I've tried installing a number of different ways, most recently this method. Everything went through just fine, but same result.

If anyone has any idea how to fix this it'd be greatly appreciated. Really jamming me up at work right now.

@sethetter

This comment has been minimized.

Copy link

@sethetter sethetter commented Oct 6, 2015

I've tried disabled SIP (new in El Capitan) to see if that had anything to do with it, but same result.

@sethetter

This comment has been minimized.

Copy link

@sethetter sethetter commented Oct 6, 2015

As an FYI, I'm following this SO thread to keep updated on a fix from PDF Labs -> https://stackoverflow.com/questions/32505951/pdftk-server-on-os-x-10-11

@rmehner

This comment has been minimized.

Copy link

@rmehner rmehner commented Oct 29, 2015

Thank you @sethetter & @jvenator. I've made this whole thing into a gist and it works with El Capitan (10.11) and previous versions. Gist is here: https://gist.github.com/rmehner/fed9d1ac70eaa296306a

Invoke like this:

  • OSX 10.11 (El Capitan): install_pdftk.sh https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
  • OSX < 10.11: install_pdftk.sh https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.6-setup.pkg
@harigopalakrishna

This comment has been minimized.

Copy link

@harigopalakrishna harigopalakrishna commented Nov 7, 2015

Works Great!, Thanks for the fix

I uninstalled pdftk and performed a fresh install on my OXS 10.11 (install_pdftk.sh https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg)

@iamitava

This comment has been minimized.

Copy link

@iamitava iamitava commented Dec 27, 2015

Tip: You can use mkdir -p to specify just the leaf directories, like this:

mkdir -p /usr/local/Cellar/pdftk/2.02/bin
mkdir /usr/local/Cellar/pdftk/2.02/lib
mkdir -p /usr/local/Cellar/pdftk/2.02/share/man/man1

Thanks for the workaround!

@mhct

This comment has been minimized.

Copy link

@mhct mhct commented Apr 22, 2016

Great stuff. Thanks.

@rfabbri

This comment has been minimized.

@akarazeev

This comment has been minimized.

Copy link

@akarazeev akarazeev commented Jun 3, 2016

Thank you!

@adedip

This comment has been minimized.

Copy link

@adedip adedip commented Jun 17, 2016

Best solution ever! thanks!

@deepak07

This comment has been minimized.

Copy link

@deepak07 deepak07 commented Oct 4, 2016

Thank you... Worked perfectly...

@gripedthumbtacks

This comment has been minimized.

Copy link

@gripedthumbtacks gripedthumbtacks commented Oct 12, 2016

This DOES NOT WORK. The install will finish, but trying to combine any PDF using the cat function has failed for me every time. pdftk appears broken in newer releases of macOS.

@barijaona

This comment has been minimized.

Copy link

@barijaona barijaona commented Jan 2, 2017

Unfortunately, this seems broken.
There seems to be no real alternative at the time. Technically, cpdf (source code available here) is similar to PDFtk server edition, but its licence is quite different.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Apr 25, 2017

This brew should set it up:
brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb

@dvska

This comment has been minimized.

Copy link

@dvska dvska commented Apr 27, 2017

@muzimuzhi

This comment has been minimized.

Copy link

@muzimuzhi muzimuzhi commented Jul 4, 2017

This installation routine still messes up permissions on /usr/local on macOS 10.12.5, as described in homebrew-cask #7707.

@meGAmeS1

This comment has been minimized.

Copy link

@meGAmeS1 meGAmeS1 commented Nov 22, 2017

I was trying to follow this procedure on my macOS 10.13 - High Sierra but when trying to execute a command, pdftk was hanging out doing apparently nothing. If verbose mode, it was stuck in Creating Output .... I found this stackoverflow topic, where it suggested to download the latest version still not listed on the official website) : https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg

So replace the first command with the following one and it will be okay:

curl -o ~/Downloads/pdftk_download.pkg https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
@abhinav098

This comment has been minimized.

Copy link

@abhinav098 abhinav098 commented Mar 28, 2018

how to unistall this thing from mac ?

@meGAmeS1

This comment has been minimized.

Copy link

@meGAmeS1 meGAmeS1 commented Apr 11, 2018

@abhinav098 brew uninstall pdftk ?

@rosco

This comment has been minimized.

Copy link

@rosco rosco commented Jun 21, 2018

Thank you for
download the latest version still not listed on the official website) : https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg

Worked perfectly for me.

@gamesover

This comment has been minimized.

Copy link

@gamesover gamesover commented Jul 25, 2018

+1 for @rosco link

@ricopicone

This comment has been minimized.

Copy link

@ricopicone ricopicone commented Sep 22, 2018

+1 for @rosco link

@joshdcuneo

This comment has been minimized.

Copy link

@joshdcuneo joshdcuneo commented Feb 4, 2019

+1 for @rosco link

@codenathan

This comment has been minimized.

Copy link

@codenathan codenathan commented Feb 28, 2019

+1 for @rosco link

@jthomerson

This comment has been minimized.

Copy link

@jthomerson jthomerson commented Aug 11, 2019

Huge props for writing this up for us. Thanks!

@jthomerson

This comment has been minimized.

Copy link

@jthomerson jthomerson commented Aug 11, 2019

For OSX Mojave (10.14), just substitute the URL in the curl command with this one: https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg.

curl -o ~/Downloads/pdftk_download.pkg https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg && \
pkgutil --expand ~/Downloads/pdftk_download.pkg ~/Downloads/pdftk_package && \
cd ~ && \
mkdir /usr/local/Cellar/pdftk \
      /usr/local/Cellar/pdftk/2.02 \
      /usr/local/Cellar/pdftk/2.02/bin \
      /usr/local/Cellar/pdftk/2.02/lib \
      /usr/local/Cellar/pdftk/2.02/share \
      /usr/local/Cellar/pdftk/2.02/share/man \
      /usr/local/Cellar/pdftk/2.02/share/man/man1 && \
mv ~/Downloads/pdftk_package/pdftk.pkg/Payload ~/Downloads/pdftk_package/pdftk.pkg/payload.gz && \
gunzip ~/Downloads/pdftk_package/pdftk.pkg/payload.gz && \
cd ~/Downloads/pdftk_package/pdftk.pkg/ && \
   cpio -iv < ~/Downloads/pdftk_package/pdftk.pkg/payload && \
cd ~ && \
   mv Downloads/pdftk_package/pdftk.pkg/bin/pdftk /usr/local/Cellar/pdftk/2.02/bin/pdftk && \
   mv Downloads/pdftk_package/pdftk.pkg/lib/* /usr/local/Cellar/pdftk/2.02/lib/ && \
   mv Downloads/pdftk_package/pdftk.pkg/man/pdftk.1 /usr/local/Cellar/pdftk/2.02/share/man/man1/pdftk.1 && \
brew doctor
brew link pdftk
@deyvisonrocha

This comment has been minimized.

Copy link

@deyvisonrocha deyvisonrocha commented Oct 14, 2019

@jthomerson thanks!

Work fine for me!

@nachiket

This comment has been minimized.

Copy link

@nachiket nachiket commented Nov 12, 2019

I'm getting the error "zsh: bad CPU type in executable: pdftk" in MacOS Catalina. Anyone else facing a similar issue?

@LucasCioffi

This comment has been minimized.

Copy link

@LucasCioffi LucasCioffi commented Nov 12, 2019

@nachiket yes unfortunately we have the same challenge with Catalina.

@allealdine

This comment has been minimized.

Copy link

@allealdine allealdine commented Nov 14, 2019

Same here. -bash: /usr/local/bin/pdftk: Bad CPU type in executable

@kurmanka

This comment has been minimized.

Copy link

@kurmanka kurmanka commented Nov 16, 2019

I also had this Bad CPU type in executable error. Then I picked this package:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
installed it, and it works fine. (picked this URL here: https://stackoverflow.com/a/58236185/284595 )

The official PDFtk Server page (as of 16 Nov 2019) offers this link as the Mac OS installer:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.6-setup.pkg

@allealdine

This comment has been minimized.

Copy link

@allealdine allealdine commented Nov 18, 2019

Perfect, it works like a charm now. Thanks @kurmanka.

@eleftrik

This comment has been minimized.

Copy link

@eleftrik eleftrik commented Dec 23, 2019

I also had this Bad CPU type in executable error. Then I picked this package:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
installed it, and it works fine. (picked this URL here: https://stackoverflow.com/a/58236185/284595 )

The official PDFtk Server page (as of 16 Nov 2019) offers this link as the Mac OS installer:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.6-setup.pkg

Thank you!!!

@javiercriado

This comment has been minimized.

Copy link

@javiercriado javiercriado commented Jan 28, 2020

thank you!

@barriault

This comment has been minimized.

Copy link

@barriault barriault commented Jan 29, 2020

I also had this Bad CPU type in executable error. Then I picked this package:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.11-setup.pkg
installed it, and it works fine. (picked this URL here: https://stackoverflow.com/a/58236185/284595 )

The official PDFtk Server page (as of 16 Nov 2019) offers this link as the Mac OS installer:
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk_server-2.02-mac_osx-10.6-setup.pkg

As of January 29, 2020, the official PDFtk Server page still has the old 10.6 link . . .

@anquegi

This comment has been minimized.

Copy link

@anquegi anquegi commented Mar 23, 2020

Thanks for this gists, this also work and be carefull to install 10.11 pkg

this also worked on my OSX Catalina, maybe you need to do reintall

brew install https://raw.githubusercontent.com/turforlag/homebrew-cervezas/master/pdftk.rb

This owrked for me prefectly, I also hac it installed so

@varp

This comment has been minimized.

Copy link

@varp varp commented Oct 30, 2020

I just used pdftk-java port of pdftk. https://gitlab.com/pdftk-java/pdftk

@kkbt

This comment has been minimized.

Copy link

@kkbt kkbt commented May 16, 2021

Version of pdftk running on macOS Big Sur (= macOS 11) with the Apple M1 chip:
https://apple.stackexchange.com/questions/414272/bad-cpu-type-in-executable-when-running-pdftk/420712#420712

Using the pdftk-java port with homebrew on the Apple M1 architecture:
https://stackoverflow.com/questions/60859527/how-to-solve-pdftk-bad-cpu-type-in-executable-on-mac/67561373#67561373

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment