PDFtk on CentOS 7

I recently migrated my website to a new Bluehost account. This broke some PHP scripts that used PDFtk as described previously on this blog. It took some searching but found this article and comment to be the beyond helpful. Here are the steps to bring it all together.

  1. Download the RPM
  2. Upload the RPM to Bluehost accounts home directory
  3. Create file pdftk.sh (see code snippet below for contents)
  4. Upload pdftk.sh to ~/usr/bin
  5. SSH into server and run the following commands
    • rpm2cpio pdftk-2.02-1.el7.x86_64.rpm | cpio -idmv
    • cd usr
    • cd bin
    • mv pdftk pdftk.target
    • chmod 755 pdftk.sh
    • ./pdftk.sh –version
  6. Edit pdfForm.php (location specific to your site)
    • Line 51 – exec(“~/usr/bin/pdftk.sh …
    • Line 66 – exec(“~/usr/bin/pdftk.sh …
  7. Edit filename in other scripts calling pdftk directly.
  8. Test PHP scripts.

pdftk.sh contents

export PATH=~/usr/bin:$PATH;
export LD_LIBRARY_PATH=~/lib:~/usr/lib64:$LD_LIBRARY_PATH;
~/usr/bin/pdftk.target "$@"


No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *