Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with nested fields with numeric field names #260

Closed
maxguru opened this issue Oct 19, 2021 · 16 comments
Closed

Problem with nested fields with numeric field names #260

maxguru opened this issue Oct 19, 2021 · 16 comments

Comments

@maxguru
Copy link

maxguru commented Oct 19, 2021

I seem to have found a big issue with the newer version (0.10.3). I narrowed it down to issues with XFDF generator.

See files generated by the two versions:
xfdf.zip

Version 0.10.3 generate files that don't work fully with pdftk-java (some fields are not filled).

@mikehaertl
Copy link
Owner

I'm hesitant to download arbitrary ZIP files from unknown sources. Could you maybe better add the relevant information here? A code example would also help.

@maxguru
Copy link
Author

maxguru commented Oct 19, 2021

GitHub didn't allow me to upload XFDF files but allowed ZIP. Go figure.

XFDF output from v0.9.2:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields><field name="Phone">
<value>+1 (168) 258-9206</value>
</field>
<field name="Relationship to You">
<value>Eius eligendi eius a</value>
</field>
<field name="Hospital">
<value>Veniam ex neque et</value>
</field>
<field name="Phone_2">
<value>+1 (452) 938-4562</value>
</field>
<field name="City">
<value>Do ut soluta distinc</value>
</field>
<field name="County">
<value>Unde est ut expedita</value>
</field>
<field name="Date">
<value>14-Feb-2007</value>
</field>
<field name="Client DOB">
<value>Rem eos aliqua Qui</value>
</field>
<field name="Date_2">
<value>16-Sep-2000</value>
</field>
<field name="Date_3">
<value>06-Sep-2003</value>
</field>
<field name="Please Initial that you have read this page">
<field name="0">
<value>Totam quia aut culpa</value>
</field>
<field name="1">
<field name="0">
<value>Aut sequi corrupti</value>
</field>
<field name="1">
<value>Dolorem duis aliquid</value>
</field>
<field name="2">
<field name="0">
<value>Quibusdam illo labor</value>
</field>
<field name="1">
<value>Reiciendis irure rec</value>
</field>
<field name="2">
<value>Quis duis sint rati</value>
</field>
</field>
</field>
</field>
<field name="Parents or Legal Guardians Name Please Print">
<field name="0">
<value>Irene Juarez</value>
</field>
<field name="1">
<value>Berk Rivers</value>
</field>
<field name="2">
<value>Jaime Carver</value>
</field>
</field>
<field name="Client Name Please Print">
<field name="0">
<value>Amal Harrington</value>
</field>
<field name="1">
<value>Sophia Decker</value>
</field>
</field>
<field name="Check Box2">
<field name="0">
<field name="0">
<value>Yes</value>
</field>
<field name="1">
<value>Yes</value>
</field>
</field>
<field name="1">
<field name="0">
<value>Yes</value>
</field>
<field name="1">
<value>Yes</value>
</field>
</field>
</field>
<field name="Name">
<value>Noelani Martin</value>
</field>
</fields>
</xfdf>

XFDF output from v0.10.3:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>
<field name="Phone">
<value>+1 (168) 258-9206</value>
</field>
<field name="Relationship to You">
<value>Eius eligendi eius a</value>
</field>
<field name="Hospital">
<value>Veniam ex neque et</value>
</field>
<field name="Phone_2">
<value>+1 (452) 938-4562</value>
</field>
<field name="City">
<value>Do ut soluta distinc</value>
</field>
<field name="County">
<value>Unde est ut expedita</value>
</field>
<field name="Date">
<value>14-Feb-2007</value>
</field>
<field name="Client DOB">
<value>Rem eos aliqua Qui</value>
</field>
<field name="Date_2">
<value>16-Sep-2000</value>
</field>
<field name="Date_3">
<value>06-Sep-2003</value>
</field>
<field name="Please Initial that you have read this page">
<value>Totam quia aut culpa</value>
<value></value>
</field>
<field name="Parents or Legal Guardians Name Please Print">
<value>Irene Juarez</value>
<value>Berk Rivers</value>
<value>Jaime Carver</value>
</field>
<field name="Client Name Please Print">
<value>Amal Harrington</value>
<value>Sophia Decker</value>
</field>
<field name="Check Box2">
<value></value>
<value></value>
</field>
<field name="Name">
<value>Noelani Martin</value>
</field>
</fields>
</xfdf>

@mikehaertl
Copy link
Owner

Can you please also provide a simple code example that I can use to reproduce the issue? Especially including the format of the data array.

@maxguru
Copy link
Author

maxguru commented Oct 19, 2021

$data = array(
  'Phone' => '+1 (168) 258-9206',
  'Relationship to You' => 'Eius eligendi eius a',
  'Hospital' => 'Veniam ex neque et',
  'Phone_2' => '+1 (452) 938-4562',
  'City' => 'Do ut soluta distinc',
  'County' => 'Unde est ut expedita',
  'Date' => '14-Feb-2007',
  'Client DOB' => 'Rem eos aliqua Qui',
  'Date_2' => '16-Sep-2000',
  'Date_3' => '06-Sep-2003',
  'Please Initial that you have read this page.0' => 'Totam quia aut culpa',
  'Please Initial that you have read this page.1.0' => 'Aut sequi corrupti',
  'Please Initial that you have read this page.1.1' => 'Dolorem duis aliquid',
  'Please Initial that you have read this page.1.2.0' => 'Quibusdam illo labor',
  'Please Initial that you have read this page.1.2.1' => 'Reiciendis irure rec',
  'Please Initial that you have read this page.1.2.2' => 'Quis duis sint rati',
  'Parents or Legal Guardians Name Please Print.0' => 'Irene Juarez',
  'Parents or Legal Guardians Name Please Print.1' => 'Berk Rivers',
  'Parents or Legal Guardians Name Please Print.2' => 'Jaime Carver',
  'Client Name Please Print.0' => 'Amal Harrington',
  'Client Name Please Print.1' => 'Sophia Decker',
  'Check Box2.0.0' => 'Yes',
  'Check Box2.0.1' => 'Yes',
  'Check Box2.1.0' => 'Yes',
  'Check Box2.1.1' => 'Yes',
  'Name' => 'Noelani Martin',
);
$xfdf = new \mikehaertl\pdftk\XfdfFile($data);
$xfdf->saveAs('data.xfdf');

By the way, even v0.9.2 output looks strange (nested field tags), although, I am not an expert on XFDF.

@mikehaertl
Copy link
Owner

Your field names contain dots . which are interpreted as nested fields. I don't remember if this is a XFDF thing or only in our library. I will look into this later but maybe it also helps you to further investigate.

@maxguru
Copy link
Author

maxguru commented Oct 19, 2021

Version 0.9.2 output works with pdftk, so, I am not going to complain, but whatever version 0.10.3 outputs doesn't work (some fields are not filled).

@mikehaertl
Copy link
Owner

mikehaertl commented Oct 19, 2021

[DELETED]

@mikehaertl
Copy link
Owner

Sorry, forget what I wrote above. This will not work. The real problem is that you use numeric field names.

@mikehaertl
Copy link
Owner

Unfortunately I see no way to fix this without breaking things. The main problem is really that your field names are numbers. If you can somehow at least avoid a field with name 0 things should work again for you.

Background: If you have field names like this:

[
    'abc.0' => 'value1',
    'abc.1' => 'value2',
]

this gets converted internally into this:

[
    'abc' => [
        0 => 'value1',
        1 => 'value2',
    ],
]

But this is the same as the syntax that we use for fields with multiple values:

[
    'abc' => ['value1', 'value2'],
]

They must be handled differently. So we check if a key with value 0 exists and assume that its a multivalue field. That's why your fields are treated like multivalue fields and not like nested fields anymore.

There is no fix for this.

@maxguru
Copy link
Author

maxguru commented Oct 19, 2021

I don't understand. The old version (0.9.2) is working fine...

@maxguru
Copy link
Author

maxguru commented Oct 19, 2021

I can't control what my users use as a field names. Regardless, this sounds like a design issue in the php-pdftk library. I use another library which has no problems whatsoever with the same PDF file.

IMHO, dismissing this issue as a user problem is unreasonable. Would you consider a pull request if I was to fix it?

@mikehaertl
Copy link
Owner

The problem started with implemenation of #148 in 0.10.2 where we added support for multi-value fields.

But let me have another look, maybe we can still find a workaround somehow.

@mikehaertl mikehaertl reopened this Oct 19, 2021
@mikehaertl mikehaertl changed the title Problem with new version Problem with nested fields with numeric field names Oct 19, 2021
@mikehaertl
Copy link
Owner

@maxguru I've prepared a fix. Can you help testing this? See MR above for branch issue-260-nested-numeric-field-names.

@maxguru
Copy link
Author

maxguru commented Oct 20, 2021

Thanks for the quick fix! It does produce the desired output for the case I described above. However, give me some time to test it with a large number of different PDF files.

mikehaertl added a commit that referenced this issue Oct 25, 2021
…d-names

Issue #260 Fix nested fields with numeric field names
@mikehaertl
Copy link
Owner

I've now created release 0.10.4 containing this fix. Let me know if there's still an issue.

@maxguru
Copy link
Author

maxguru commented Nov 5, 2021

It seems to be working fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants