user2246930
user2246930

Reputation: 59

FPDF and PHP: Help merging PDF forms with text fields without losing text data?

I have PDF form files that I fill out dynamically with PHP using FPDM (the FPDF script). I can save them on my server no problem, and the text all looks fine in the PDF when I download and view in Acrobat.

My problem is: I'm trying to merge multiple PDF files together on the server so the user can download a single PDF document with several pages. I downloaded PDF Merger (http://pdfmerger.codeplex.com/) and got it merging the files together, but this causes the PDF form text to disappear.

Anyone know of a form-friendly PHP-based PDF merger that doesn't require installing anything (other than uploading libraries) to my server?

Code that works for merging but kills text in form boxes:

$pdfCombined= new PDFMerger;

$pdfCombined->addPDF('../forms/generated/16.pdf', 'all')
        ->addPDF('../forms/generated/19.pdf', 'all')
        ->merge('browser', 'mergedDoc.pdf');

Upvotes: 2

Views: 2515

Answers (1)

Jan Slabon
Jan Slabon

Reputation: 5058

The linked "PDF Merger" simply uses FPDI in the back. FPDI is not able to handle dynamic content as described here.

A pure PHP solution for merging PDF forms is the SetaPDF-Merger component (not free). An evaluation requires the installation of a Loader (Ioncube or Zend Guard). License owners will get access to the source code, so that no external library is needed. The usage is also that easy:

require_once("library/SetaPDF/Autoload.php");

// create a file writer
$writer = new SetaPDF_Core_Writer_Http("mergedDoc.pdf");
// create a new merger instance
$merger = new SetaPDF_Merger();
// add the files    
$merger->addFile('../forms/generated/16.pdf');
$merger->addFile('../forms/generated/19.pdf');

// merge all files
$merger->merge();

// get the resulting document and set the writer instance
$document = $merger->getDocument();
$document->setWriter($writer);

// save the file and finish the writer
$document->save()->finish();

Upvotes: 2

Related Questions