Search code examples
phppdfpdftk

PDFtk not writing to some multiline fields


I'm using PDFtk to fill out interactive PDFs from form entries, but some of the fields in the PDF remain blank after using the fill_form command to merge the FDF file. It seems to be affecting some of the multiline fields (FieldFlags: 4096), but not all multiline fields.

This is a sample of the field data of the interactive PDF from pdftk /pdf-forms/raw/idaho.pdf dump_data_fields:

---
FieldType: Text
FieldName: Employer Name Address incl zip
FieldNameAlt: Employer (Name & Address incl. zip)
FieldFlags: 4096
FieldValue: 
FieldJustification: Left
---
FieldType: Text
FieldName: CarrierAdministrator Claim Number
FieldNameAlt: Carrier/Administrator Claim Number
FieldFlags: 0
FieldValue: 
FieldJustification: Left
---
FieldType: Text
FieldName: Jurisdiction
FieldNameAlt: Jurisdiction
FieldFlags: 0
FieldValue: 
FieldJustification: Left
---
FieldType: Text
FieldName: Jurisdiction Claim No
FieldNameAlt: Jurisdiction Claim No.
FieldFlags: 0
FieldValue: 
FieldJustification: Left
---
FieldType: Text
FieldName: Employers Location Address if different
FieldNameAlt: Employer’s Location Address (if different)
FieldFlags: 4096
FieldValue: 
FieldJustification: Left
---
FieldType: Text
FieldName: Claims Admin Name Address Phone Number
FieldNameAlt: Claims Admin (Name, Address & Phone Number)
FieldFlags: 4096
FieldValue: 
FieldJustification: Left
---

Here's what the temp FDF file looks like:

%FDF-1.2 1 0 obj<</FDF<< 
/Fields[
    <</T(Employer Name Address incl zip)/V(Name Test Submit)>>
    <</T(CarrierAdministrator Claim Number)/V(Carrier/Administrator Claim Number)>>
    <</T(Jurisdiction)/V(Jurisdiction)>>
    <</T(Jurisdiction Claim No)/V(Jurisdiction Claim No.)>>
    <</T(Employers Location Address if different)/V(Employer’s Location Address (if different))>>
    <</T(Claims Admin Name Address Phone Number)/V(Claims Admin Name)>>
] >> >>
endobj
trailer
<</Root 1 0 R>>
%%EOF

And here's a sample of the code I'm using if it helps:

$data = [
    'Employer Name Address incl zip' => $entry[15],               // multiline blank
    'CarrierAdministrator Claim Number' => $entry[93],            // multiline filled
    'Jurisdiction' => $entry[95],                                 // single line filled
    'Jurisdiction Claim No' => $entry[96],                        // single line filled
    'Employers Location Address if different' => $entry["98.1"],  // multiline filled
    'Claims Admin Name Address Phone Number' => $entry[155],      // multiline blank
];

$pdf = new PdfForm('/pdf-forms/raw/idaho.pdf', $data);
$pdf->save('/pdf-forms/flat/idaho.pdf');
$pdf->download();

Looking for some kind of solution to get all the fields filling, or at least for some way to test why it's not working.


Solution

  • There's actually a double space in some of the field names.

    • Employer Name Address incl zip rather than Employer Name Address incl zip
    • Claims Admin Name Address Phone Number rather than Claims Admin Name Address Phone Number

    Corrected FDF:

    %FDF-1.2
    1 0 obj <<
      /FDF <<
        /Fields [ <<
            /T (Employer Name  Address incl zip)
            /V (Name Test Submit)
          >> <<
            /T (CarrierAdministrator Claim Number)
            /V (Carrier/Administrator Claim Number)
          >> <<
            /T (Jurisdiction)
            /V (Jurisdiction)
          >> <<
            /T (Jurisdiction Claim No)
            /V (Jurisdiction Claim No.)
          >> <<
            /T (Employers Location Address if different)
            /V (Employer’s Location Address \(if different\))
          >> <<
            /T (Claims Admin Name Address  Phone Number)
            /V (Claims Admin Name)
          >> ]
      >>
    >>
    endobj
    
    trailer
    <<
      /Root 1 0 R
    >>
    %%EOF