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

Fields get a new parent in merged documents #778

Open
fancycode opened this issue Jan 16, 2024 · 5 comments
Open

Fields get a new parent in merged documents #778

fancycode opened this issue Jan 16, 2024 · 5 comments
Assignees

Comments

@fancycode
Copy link
Contributor

When documents containing fields are merged, a new parent for the fields of the source document is created and the source fields are added there:

pdfcpu/pkg/pdfcpu/merge.go

Lines 350 to 354 in b89d7b1

parentDict :=
types.Dict(map[string]types.Object{
"Kids": arrFieldsSrc,
"T": types.StringLiteral(fmt.Sprintf("%d", len(arrFieldsDest))),
})

This will cause problems if the (unmodified) field names are expected, e.g. for filling out later.

Example:

  • Source document contains fields named path1.field1 and path2.field2.
  • Destination document contains field named path1.field2.

Expected result:
The fields in the merged document are named path1.field1, path1.field2 and path2.field2.

Instead:
The fields in the merged document are named path1.field2, 1.path1.field1 and 1.path2.field2.

@hhrutter
Copy link
Collaborator

Please describe usecase.
Merging forms is a complex operation.
I generally recommend exporting your fields once you are ready to fill your form.

@fancycode
Copy link
Contributor Author

Here is one use case:

  • The application has multiple small PDF documents containing fields.
  • Depending on user input, some of them are merged together as output document.
  • This output document is filled out automatically with values generated from the user input.

Now as the field names in the resulting document are different depending on which documents have been combined (and in which order), filling out the fields in the resulting document automatically is not possible.

@hhrutter
Copy link
Collaborator

tricky.. let me think about this.

@hhrutter
Copy link
Collaborator

hhrutter commented Feb 6, 2024

I suggest you merge your files first, then do a form export and use the resulting json as your input for filling.

@fancycode
Copy link
Contributor Author

As written above, this unfortunately is not possible: The fillout data is generated by scripts for the different small PDF documents, i.e. not directly by the user.

However depending on the ordering and depending on which PDF documents are merged, the field names in the resulting document differ and don't match the generated data from the scripts.

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

No branches or pull requests

2 participants