FPDF-Merge Error: field not found in pdf template using fpdm.php to fill form data

user1911141 picture user1911141 · Dec 19, 2012 · Viewed 11.5k times · Source

I'm using this FPDF script from http://www.fpdf.org/en/script/script93.php to fill html form data to pdf fields in a template. This:

require('fpdm/fpdm.php');

$fields = array(
    'name'  => $_POST['_fid_6'],
    'address'  => $_POST['_fid_7'],
    'city'  => $_POST['_fid_8'],
);

$pdf = new FPDM('template.pdf');
$pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output('qaf.pdf', 'F'); 

works fine when I use the example template.pdf provided in the zip. But when I use my own pdf template (template3.pdf), and this:

require('fpdm/fpdm.php');

$fields = array(
    'cascade'  => $_POST['_fid_6'],
    'structuretype'  => $_POST['_fid_7'],
    'marketmanager'  => $_POST['_fid_8'],
);

$pdf = new FPDM('template3.pdf');
$pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output('qaf.pdf', 'F'); 

I get the error FPDF-Merge Error: field cascade not found

I'm using Acrobat XI Pro. I've triple checked the field names in my pdf template & html form. I've optimized the pdf to remove compression and fast web view, and made it compatible with Acrobat 5.0 and later. My template is 7 pages, but I tried it as only 1 page with the same result. I've experimented with discarding other data and objects, but still get the same error.

There must be something in my pdf template that is different than the template.pdf in the example, and is causing the error. But I have no idea what it could be. I can't include my actual template pdf here, because it is proprietary.

Any ideas on what might be causing the error?? Thanks!

Answer

Mahi picture Mahi · Dec 30, 2013

for this you must compress your pdf
then run for compressing your fdf you need to install pdfftk
then set environment and compress with pdftk with the following command line process

C:\Users\Deepak\Desktop>pdftk template_3.pdf output template3_o.pdf

then use

template3_o.pdf 

instead of

template_3.pdf