UPDATE 2010-09-03: I updated a couple links to reflect newer downloads. Because 1and1 shared hosting is on an older debian (etch) system I had to tweak the steps for using lenny based packages. ENJOY!
There are some cases where you might need a powerful pdf toolkit to use with php. 1and1 does not come with any built in pdf processors or pdf libraries built into php. Here is the process I used to integrate phptk into my 1and1 shared hosting account.
Requirements: 1and1 shared plan that has ssh support
– Download pdftk deb file for debian lenny:
wget http://ftp.us.debian.org/debian/pool/main/p/pdftk/pdftk_1.41-3_i386.deb
– Extract the pdftk deb file:
ar xv pdftk_1.41-3_i386.deb
– Extract the data.tar.gz file:
tar xvzf data.tar.gz
– Download libgcj deb file for debian lenny:
wget http://ftp.us.debian.org/debian/pool/main/g/gcj-4.2/libgcj8-1_4.2.4-4_i386.deb
– Extract the libgcj deb file:
ar xv libgcj7-0_4.1.1-20_i386.deb
– Extract the data.tar.gz file:
tar xvzf data.tar.gz
– Download libstdc++ deb file for debian lenny (backport file http://packages.debian.org/lenny-backports/i386/libstdc++6/download):
wget http://mirror.linux.org.au/backports.org/pool/main/g/gcc-4.3/libstdc++6_4.3.4-6~bpo50+1_i386.deb
– Extract the libstdc++6 deb file:
ar xv libstdc++6_4.3.4-6~bpo50+1_i386.deb
– Extract the data.tar.gz file:
tar xvzf data.tar.gz
– Create a script to link libgcj and libstdc++6 for pdftk (use nano or vi):
#!/bin/bash
LD_LIBRARY_PATH="usr/lib:$LD_LIBRARY_PATH" usr/bin/pdftk $*
– Chmod the pdftk script so it can run:
chmod 755 pdftk
Now you can run pdftk from your main directory and process files from php or cronjobs.
If you run into any problems try running the pdftk command with some test files. If you have any problems please leave a comment. Thanks!
thanks for the tutorial. i think that really helps me with the installation. good post!
Thank you! I’m not with 1and1 but this is still really useful for any linux shared hosting. It saved me from needing to ask my provider to install pdftk. And who knows if they would have done so, if had I asked.
I changed my version of the shell script to use absolute paths instead. That way I can invoke pdftk from any folder, without needing to chdir first.
ah.. i don`t still understand… ugh..
Thanks for the tutorial! I have a few questions.
“- Create a script to link libgcj and libstdc++6 for pdftk (use nano or vi):”
I don’t know what this means but I just typed “#!/bin/bash” into the PuTTY window. Is that right?
Then I put in chmod 755 pdftk and it said “chmod: cannot access `pdftk’: No such file or directory”
Is this right? Help please….i’m a noob
Mickey:
Create a script means to put the text into a file. So on the command line you would type:
nano pdftk
then enter this into that file:
#!/bin/bash
LD_LIBRARY_PATH=”usr/lib:$LD_LIBRARY_PATH” usr/bin/pdftk $*
then hit Ctrl-o to save then Ctrl-x to exit
The chmod 755 pdftk should work then.
Thanks for the quick response! I have 1and1 business shared hosting
Okay so I got that working and I can use commands like
“pdftk 1.pdf 2.pdf cat output 3.pdf”
In the putty window and it works great BUT I put those same commands in test.php
and nothing happens BUT if I put something like
It will make a 3.pdf file
I checked and the php.ini file says i’m not in safe_mode so I can’t figure out why pdftk isn’t working. Any suggestions??
Thanks
looks like the post erased my php commands.
exec(“pdftk 1.pdf 2.pdf cat output 3.pdf”) – Doesn’t work
exec(“cp 1.pdf 3.pdf”) – Does work
Others have had issues with the memory_limit in php. Try running the exec with small pdfs and see if it still works. I think I had used passthru command in php versus the exec command. You may also need to put the absolute path in front of pdftk. So instead of
exec(“pdftk ….
put
exec(“/home/username/usr/bin/pdftk ….
Great instructions, just what I needed. Thanks!
Hi,
Thank you for this tutorial. I’m on 1&1, “virtual server”.
I’m quite a beginner but I think I understand your tuto. But could you explain into which directory you extract the packages ? and where you put your script ?
Thanks
brigitte,
In a 1and1 virtual server setting you should be able to add pdftk from your linux package management. If you are using CentOS try ssh’ing in run:
yum install pdftk
If you are running ubuntu or debian try:
apt-get install pdftk
Otherwise you’ll have to lookup how to install pdftk in your particular distribution or OS.
Thanks for your reply Jeremy.
I’m afraid I’m not able to do this : I only use the plesk front end and know very little about linux. but i’ll have a look
Thanks
Following these instructions with a slight exception, I was able to install PDFTK and run it from the command line, but not from a Web script using either exec() or passthru() functions.
The exception was that when I downloaded the libgcj deb file (http://ftp.us.debian.org/debia.....4_i386.deb), I could only extract a file name listed in that ftp.* url, not the “Extract the libgcj deb file” command listed (ar xv libgcj7-0_4.1.1-20_i386.deb). I.E. I extracted libgcj8-1_4.2.4-4_i386.deb.
I followed the same instructions on another shared host, which also successfully uploaded and unpacked the files, but there they didn’t run at all. I’ll focus my comments here on debugging the 1and1 installation…
One thing I noticed is that, when I create a pdftk file with nano (nano pdftk) I don’t find that file with those few lines (!#/bin/bash LIBRARY_ ) I enter in the file aren’t in the file that appears in the file directory via ftp client or console (ld -lart). Instead, I find a very large pdftk file with the same name.
I noticed other odd behavior that raised my suspicions about 1and1’s memory limits, which I’ve otherwise encountered when using large PHP systems like Drupal with a ton of modules enabled. But I was only copying small files here, from console and by PHP exec(‘cp 1.txt 2.txt’) etc. and it worked sometimes but not others. That’s just not right!
This is similar to Mickey’s Dec. 2010 experience. Thanks for any insights anyone might offer.
Joey,
Try going back to your user directory on your server and create the file nano pdftk with the lines:
#!/bin/bash
LD_LIBRARY_PATH=”usr/lib:$LD_LIBRARY_PATH” usr/bin/pdftk $*
in it.
The LD_LIBRARY_PATH needs to match up to the location you expanded the libgcj and libstdc++6 library files (ie the usr/lib is a relative path to the php root described above). I’m suspecting that php is loading pdftk but cannot load the proper lib files. If the pdftk can run from the command line and properly process files that is always the first step. Good luck!
Thanks for the quick reply and for the accurate, detailed tutorial. The upload instructions here work for GoDaddy, too, but you have to go through several steps to get a java-enabled shared Web server from them. When and if that goes through, I’ll post those details.
Contrary to my initial post, the pdftk file (the shebang file) I nano’d with the LD_LIBARY_PATH directives spelled out here was in place. The error was in describing the path to pdftk in my passthru() function.
When I downloaded and unpacked pdftk, it populated a directory called usr/bin. When I wrote the hard path to pdftk I included usr/bin in the path. That’s wrong. The correct path was the same path to which the command prompt was pointed.
This works:
echo passthru(“/home/x/xx**xxx/htdocs/pdftk –help”);
This does not work:
echo passthru(“/home/x/xx**xxx/htdocs/usr/bin/pdftk –help”);
(my site is:
/home/x/xx**xxx/htdocs/somefolder/my-site/index.php)
Thanks for the tutorial, and it did work, but eventually, 1and1 cut off access to java mid-stream in our development work, which meant no more pdftk on a shared server.
They might support some light java manipulation of pdfs if it flies under their radar, but when we started writing a few pdfs back to the server, they pulled the plug. It wasn’t a high-volume activity, nor were we using more than a few k’s of memory in the process.
Joey,
That is interesting. pdftk still works on my shared plan. But we are using a Developer plan which has more capabilities and we do not use java for anything at the moment. Just php.
Jeremy
Is there any way to update these instructions? I tried it on my 1and1 server. I had to modify the FTP location for all 3 programs using:
pdftk_1.41+dfsg-10+squeeze1_i386.deb
http://ftp.us.debian.org/debia.....2_i386.deb
http://ftp.us.debian.org/debia.....8_i386.deb
instead of what you listed. Everything seems to work fine but after everything I ran pdftk –help and received the following error:
pdftk –help
usr/bin/pdftk: error while loading shared libraries: itext-2.1.7.jar.so: cannot open shared object file: No such file or directory
Any suggestions for me would be tremendously appreciated.
Thanks