问题
How to install pdftk on heroku stack?
Because of other dependencies, I cannot downgrade stack to Cedar, I need to run on heroku-16
.
回答1:
Answer is here, I only want to archive it for future generations if it disappears. So special thanks to Derek Barber!
The first step is to download a binary of pdftk that will work on heroku and add it to your Rails app:
mkdir -p [my_project]/vendor/pdftk/lib [my_project]vendor/pdftk/bin
cd /tmp
git clone https://github.com/millie/pdftk-source.git
cd pdftk-source
tar xzvf pdftk.tar.gz
mv bin/pdftk [my_project]/vendor/pdftk/bin/
mv lib/libgcj.so.12 [my_project]/vendor/pdftk/lib/
cd [my_project]
git add -f vendor/pdftk/
git commit -m "Add pdftk dependencies"
Once that is done you can push up your changes to heroku and then set up the necessary environment variables so that heroku knows where to find this new binary:
git push heroku master
heroku config:set LD_LIBRARY_PATH=/app/.heroku/vendor/lib:/app/vendor/pdftk/lib
heroku config:set PATH=/app/.heroku/python/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/pdftk/bin
Finally you can try it out and confirm that pdftk is now working on your heroku instance by running bash and trying it out:
heroku run bash
$ pdftk
If pdftk is working then you should see a bunch of help output from pdftk and that means you are now good to go. Your deployed app should be able to work with pdfs and generate beautifully filled out pdf forms.
回答2:
If you want the latest version of PDFtk, you'll have to modify @DonPaulie's answer just a little bit, because Derek Barber's article will install PDFtk version 1.4 and the latest version is 2.02. Otherwise it works perfectly. I also added these instructions to the comments in that article.
To get version 2.02, use the instructions found in Derek Barber's article. HOWEVER, do NOT clone the source from https://github.com/millie/pdftk-source.git as they do in the article. Instead, get your source from this repository. That repo has the compiled the binaries for the latest version.
For example, modify the bash script just a little as follows.
mkdir -p [my_project]/vendor/pdftk/lib [my_project]vendor/pdftk/bin
cd /tmp
git clone https://github.com/Aesthetikx/heroku-pdftk-buildpack.git
cd heroku-pdftk-buildpack/binaries-[your_heroku_stack]
mv pdftk [my_project]/vendor/pdftk/bin/
mv libgcj.so.17 [my_project]/vendor/pdftk/lib/
cd [my_project]
git add -f vendor/pdftk/
git commit -m "Add pdftk dependencies"
Then follow the rest of the instructions in the Derek Barber article verbatim. IF you get a "permission denied" error after you test pdftk from the heroku bash, then grant permission to the project owner with
$ chmod u+x /app/vendor/pdftk/bin/pdftk
from the heroku bash.
来源:https://stackoverflow.com/questions/45838005/pdftk-installation-on-heroku