WebFaction
Community site: login faq

I've written a PHP app that uses the pdftk program (using a system call) to put data into an existing PDF form and then let a web user download the filled-in form.

But I could use some help figuring out how to build the pdftk program and use it locally with my account on web207.

They provide build instructions at...

http://www.pdflabs.com/docs/build-pdftk/

Any suggestions would be appreciated!

asked 03 Oct '11, 10:20

qplguy
122
accept rate: 0%


The exact step-by-step guide to building pdftk:

mkdir -p $HOME/env
mkdir -p $HOME/env/gcc
mkdir -p $HOME/src

cd $HOME/src
wget http://mirrors-us.seosue.com/gcc/releases/gcc-4.1.2/gcc-4.1.2.tar.gz
tar -xzf gcc-4.1.2.tar.gz
cd gcc-4.1.2

./configure --prefix=$HOME/env/gcc --enable-libgcj --enable-threads=posix --enable-shared --enable-languages='c++,java'
make
make install

export PATH=$HOME/env/gcc/bin:$PATH
export LD_LIBRARY_PATH=$HOME/env/gcc/lib:$LD_LIBRARY_PATH

# look at the output of these commands to ensure everything is okay:
which gcc # should be ~/env/gcc/bin/gcc
which gcj # should be ~/env/gcc/bin/gcj

mkdir -p $HOME/env/pdftk

cd $HOME/src
wget http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-1.44-src.zip
unzip pdftk-1.44-src.zip
cd pdftk-1.44-dist
cd pdftk

make -f Makefile.Redhat > make.log 2>&1  #log output to the log file otherwise it looks like a catastrophe

mkdir -p $HOME/env/pdftk/bin
cp pdftk $HOME/env/pdftk/bin

mkdir -p $HOME/bin
cd $HOME/bin
ln -s ../env/pdftk/bin/pdftk .

which pdftk # should be ~/bin/pdftk

Hope that helps!

permanent link
This answer is marked "community wiki".

answered 03 Oct '11, 20:09

neeravk
1.5k3412
accept rate: 41%

wikified 06 Aug '12, 12:25

seanf
12.2k41836

Thanks!

That worked to build the pdftk, and I can run it successfully from the command line.

I can't, however, get it to run from a PHP system() call, even when specifying the full paths to all the files. It seems to me that its not able to run the pdftk program. For example...

testpdftkcall.php

";

$s = "/home/** me **/bin/pdftk";
$last_line = system($s, $retval);

$message = "<p>";
$message .= "System call: $s";
$message .= "<br>Last line: $last_line" ;
$message .= "<br>Return val: $retval";
$message .= "</p>";
echo $message;

?>

results in...

testpdftkcall.php

System call: /home/ me /bin/pdftk Last line: Return val: 127

But running the same command from the command line results in...

[ me @web207 bin]$ /home/ me /bin/pdftk SYNOPSIS pdftk <input pdf="" files="" |="" -="" |="" prompt=""> [ input_pw <input pdf="" owner="" passwords="" |="" prompt=""> ] [ <operation> <operation arguments=""> ] [ output <output filename="" |="" -="" |="" prompt=""> ] [ encrypt_40bit | encrypt_128bit ] [ allow <permissions> ] [ owner_pw <owner password="" |="" prompt=""> ] [ user_pw <user password="" |="" prompt=""> ] [ flatten ] [ compress | uncompress ] [ keep_first_id | keep_final_id ] [ drop_xfa ] [ verbose ] [ dont_ask | do_ask ] Where: <operation> may be empty, or: [ cat | shuffle | burst | generate_fdf | fill_form | background | multibackground | stamp | multistamp | dump_data | dump_data_utf8 | dump_data_fields | dump_data_fields_utf8 | update_info | update_info_utf8 | attach_files | unpack_files ]

   For Complete Help: pdftk --help
(04 Oct '11, 08:56) qplguy

Can you try with:

echo exec('/home/yourusername/bin/pdftk');

rather than the code above?

(04 Oct '11, 22:35) neeravk

The install directions above don't work on my install of CentOS 6-64bit. I got a warning about 'makeinfo' missing from the system, then make and make install quit with errors.

(06 Aug '12, 10:22) mindsalt

An alternative way to install pdftk from RPMs locally

Download the RPMs:

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libart_lgpl-2.3.20-5.1.el6.x86_64.rpm
wget ftp://ftp.sunet.se/pub/Linux/distributions/centos/6.3/os/x86_64/Packages/libgcj-4.4.6-4.el6.x86_64.rpm
wget ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el6/en/x86_64/dag/RPMS/pdftk-1.44-1.el6.rf.x86_64.rpm


Create a local RPM database:
rpm --initdb --root /home/username/local --dbpath /home/username/local/lib/rpm

Install each rpm in the order libart, libgcj, pdftk:
rpm --dbpath /home/username/local/lib/rpm --relocate /usr=/home/username/local --badreloc --nodeps -ivh package.rpm

Each command will complain about something but it doesn't seem to matter at least for the pdftk executable..

Add the following folder to your LD_LIBRARY_PATH
/home/username/local/lib64/

And the pdftk in /home/username/local/bin/pdftk should work ok at this point.

Some related discussion can be found at http://ajaya.name/?p=6353

permanent link

answered 08 Dec '12, 14:45

Matti Varjok...
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×9
×9
×5

question asked: 03 Oct '11, 10:20

question was seen: 6,478 times

last updated: 08 Dec '12, 14:45

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM