Reputation: 137
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!
Upvotes: 1
Views: 13656
Reputation: 1760
I got this error when I had multiple fields with the same name in pdf. Although they're shown in Adobe Reader as BuyerEmail, on the right in the Fields list they were referenced as BuyerEmail#0, BuyerEmail#1, etc. but I couldn't reference them in FPDF even by adding #0, #1, etc. The solution was to rename the field(s) in the document, and then again to run it through pdftk. Then it did work.
Upvotes: 2
Reputation: 431
In order to make your pdf to work for this code your pdf must have the fields you have specified in $fields array. So to do that I have a simple solution.
Upvotes: -1
Reputation: 31
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
Upvotes: 3
Reputation: 91
You should convert your template using PDFtk (http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) into a compatible version with the script!
Upvotes: 1