fpdm icon indicating copy to clipboard operation
fpdm copied to clipboard

Field Name not found

Open prairieit opened this issue 5 years ago • 7 comments

Can't seem to get this working with my PDF. PDF form created in Adobe Acrobat DC, then ran through pdftk, but FPDF still says the field names are not found.

Exact error is: FPDF-Merge Error: field PremiseName not found

I can get the example working no problem, so I know this is an issue with my PDF. If I run pdftk data_dump_fields the field name shows up correctly and I have copied and pasted that into my array.

I'm completely stuck where to turn for advice on what I'm missing here...

prairieit avatar Jun 20 '19 17:06 prairieit

I have faced same issue but using this online tool i was able to know what exactly field name was

https://www.sejda.com/pdf-editor

keshav1990 avatar Sep 23 '19 12:09 keshav1990

You can also do: pdftk doc.pdf dump_data_fields

dansleboby avatar May 13 '20 13:05 dansleboby

FieldType: Text FieldName: Official title FieldNameAlt: Official title FieldFlags: 0 FieldJustification: Left

The above is an example of one field I got from running pdftk doc.pdf dump_data_fields

My code looks like this:

$fields = array(
    'Official title' => 'Test Title'
);

$pdf = new \FPDM(storage_path('app/' . $request->filename));
$pdf->Load($fields, true);
$pdf->Merge();
$pdf->Output();

And I get this error:

<b>FPDF-Merge Error:</b> field Official title not found

What am I doing wrong?

wolfpack4417 avatar Jul 29 '20 18:07 wolfpack4417

Can you share the PDF?

Thanks

dansleboby avatar Jul 29 '20 18:07 dansleboby

PDF_Test.pdf I can't because it has some customer info on it, but I'm seeing the same issue on this one which I created from scratch to try to narrow down the issue.

FieldType: Text
FieldName: name
FieldFlags: 0
FieldJustification: Left

That's the result from the console command. The code is the same except I changed "Official title" to "name"

wolfpack4417 avatar Jul 29 '20 18:07 wolfpack4417

Running into the same issue. data_dump_fields reports what I'd expect.

mkomarsr avatar Aug 16 '20 02:08 mkomarsr

I found part of the issue.

The example PDF seems to have one element per line whereas the PDFs I'm creating are more compressed.

An example line from each as follows.

Template: /T (address)

My PDF: <</Type/Annot/Subtype/Widget/DA(/Helv 0 Tf 0 0 0 rg)/Ff 0/Q 1/BS<</W 1/S/S>>/Rect[0 299.242 612 383.595]/T(myname)/F 4/V()/M(D:20200815215310-05'00')/FT/Tx/MK<<>>/AP<</N 4 0 R>>/NM(85209dde-79a6-4f5d-8328-bc23e9912174)>>

So, the preg_match() call wasn't working. It was expecting ^/T.

I'm working on a fix. We shall see what I come up with. Maybe this will be enough for somebody else to help?

I've changed the offending preg_match line to: if(($name=="")&&preg_match("//T\s*((\w+))/",$this->_protectContentValues($CurLine),$match)) {

That's resulting in other errors, I think due to the elements falling behind the "()" in my PDF. Hoping for a resolution!

mkomarsr avatar Aug 16 '20 14:08 mkomarsr