Skip to content

Instantly share code, notes, and snippets.

@jvenator
Last active June 14, 2024 13:31
Show Gist options
  • Save jvenator/9672772a631c117da151 to your computer and use it in GitHub Desktop.
Save jvenator/9672772a631c117da151 to your computer and use it in GitHub Desktop.
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

@dvska
Copy link

dvska commented Apr 27, 2017

@muzimuzhi
Copy link

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
Copy link

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
Copy link

how to unistall this thing from mac ?

@meGAmeS1
Copy link

@abhinav098 brew uninstall pdftk ?

@rosco
Copy link

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
Copy link

+1 for @rosco link

@ricopicone
Copy link

+1 for @rosco link

@joshdcuneo
Copy link

+1 for @rosco link

@codenathan
Copy link

+1 for @rosco link

@jthomerson
Copy link

Huge props for writing this up for us. Thanks!

@jthomerson
Copy link

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
Copy link

@jthomerson thanks!

Work fine for me!

@nachiket
Copy link

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

@LucasCioffi
Copy link

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

@allealdine
Copy link

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

@kurmanka
Copy link

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
Copy link

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

@eleftrik
Copy link

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
Copy link

thank you!

@barriault
Copy link

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
Copy link

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
Copy link

varp commented Oct 30, 2020

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

@kkbt
Copy link

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

@mrlimbani
Copy link

For OSX BigSur (11.6.4), 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

@cameo69
Copy link

cameo69 commented Nov 1, 2022

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

worked for me: brew install pdftk-java

@medoror-fountain
Copy link

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

worked for me: brew install pdftk-java

This worked for me on an M1 mac. Seems like if you attempt to do a brew install pdftk the recommendation from homebrew is to use the pdftk-java

@caballeroe359
Copy link

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

worked for me: brew install pdftk-java

This worked for me on an M1 mac. Seems like if you attempt to do a brew install pdftk the recommendation from homebrew is to use the pdftk-java

Can double that. M1 and brew install pdftk-java works.

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