5

My web sites are hosted on Total Choice Hosting using some kind of Linux (I don't know what precise variety) and Apache. I don't have command line access - I can run command line programs only via exec() in PHP, or via CRON jobs.

Can I install and use PDFTK on a system like this?

If so, what exactly do I have to do? Which files do I have to copy where? Do I have to rebuild PDFTK from source, or is there an executable version somewhere?

Since (as I understand it) PDFTK is based on iText, which is written in Java. Maybe I'd be better off using the original iText package?

Or is there a better way of doing what I want to do (which is basically to merge and flatten a PDF file (blank form) with a FDF file (field values) into a new PDF file (the completed form) and download it to the user)? Is there some native PHP or Python or Perl code to do this?

Thanks - Rowan

rowan.bradley
  • 147
  • 3
  • 9

2 Answers2

6

A quick glance reveals that the PDFTK source is C++ and it looks like they use GCJ to compile some 3rd party Java code to native code. If you find a pre-built version of PDFTK that matches your OS and architecture you should be able to just upload the binary to your system and run it from PHP using exec. There are some builds available on the install page.

There are some native PHP libraries available for creating and manipulating PDFs. Check out TCPDF, Zend_Pdf, and FPDF to see if any of those are usable. Each one should support what you want to do, its just a matter of choosing the right solution.

Using PDFTK may be the fastest option since it is compiled code, but it is the least portable option since it would require the server have that software installed on it, where the PHP solutions could be distributed with your code.

drew010
  • 68,777
  • 11
  • 134
  • 162
  • Do you by any chance know of any PHP libraries that will merge FDF to PDF? Based on here this isn't possible: https://stackoverflow.com/questions/4653351/merge-fdf-and-pdf-without-pdftk – albertski May 02 '19 at 16:34
  • @albertski It's not PHP but you could call it from PHP. This worked for me to merge a filled out PDF with a regular document: `pdftk testform.pdf testdoc.pdf cat output merged.pdf` The filled in form data was preserved in the merge. – drew010 May 02 '19 at 17:18
  • I'm thinking that would require us to have the PDFTK library which in my case is not allowed. Were you able to run it without the pdftk library installed? – albertski May 02 '19 at 19:57
  • That would require the PDF toolkit software be installed on the server. I didn't try with any pure PHP solutions. PDFTK is the most promising candidate at this point. – drew010 May 02 '19 at 20:36
  • Thanks. Yeah, I had a feeling that was the case. I did search around and I don't believe there is a way to do this with pure PHP. – albertski May 02 '19 at 20:43
  • Ah sorry, in my last reply I meant TCPDF (for PHP only) was the most promising candidate. There's probably a way to open both PDF's and then open a new blank PDF and dump both inputs, but less trivially than pdftk. I don't think there's anything particularly special about the form fields or the data, they should be embedded and copied across by TCPDF, but I couldn't say for sure. – drew010 May 02 '19 at 21:09
0

If you are on a shared host you cant install PDFtk because you don't have access to root to install anything. You need to have a host that has it preinstalled. I use bluehost.com but there up-time is not the best. It works for now but I am going to move to another host once my site is complete. I have had several outages that have lasted for over a day.

JoBaxter
  • 710
  • 2
  • 12
  • 23