Hello,
during PDF signing with Documenso I noticed an issue related to handling PDF forms.
First of all, a short disclaimer: I am not very familiar with the internals of PDFs, but I did a brief investigation to better understand the problem.
I observed that a multi-page PDF form is rendered incorrectly during flattening. In my case, a text field was rendered as a checkbox. Interestingly, the issue depends on the order in which the fields were added: changing the field order results in a different text field being rendered incorrectly.
Looking into it, it seems that the function flattenWidgetsOnPage is called for each page, while the variable xObjectIndex is initialized with 0 every time. This leads to multiple xObjects being created with the same name across pages, which appears to cause the described behavior.
As a quick workaround, I changed the name generation to:
const xObjectName = FlatField${widget.ref.objectNumber};
This ensures unique names and resolves the issue in my case. I assume this is not the ideal solution, but it might help to build a proper fix.
I have attached a PDF where this behavior can be observed.
Test_libpdf.pdf
Here is the code I used for testing:
form.fill({
"text": "test",
"check": true,
});
form.flatten();
Hello,
during PDF signing with Documenso I noticed an issue related to handling PDF forms.
First of all, a short disclaimer: I am not very familiar with the internals of PDFs, but I did a brief investigation to better understand the problem.
I observed that a multi-page PDF form is rendered incorrectly during flattening. In my case, a text field was rendered as a checkbox. Interestingly, the issue depends on the order in which the fields were added: changing the field order results in a different text field being rendered incorrectly.
Looking into it, it seems that the function flattenWidgetsOnPage is called for each page, while the variable xObjectIndex is initialized with 0 every time. This leads to multiple xObjects being created with the same name across pages, which appears to cause the described behavior.
As a quick workaround, I changed the name generation to:
const xObjectName =
FlatField${widget.ref.objectNumber};This ensures unique names and resolves the issue in my case. I assume this is not the ideal solution, but it might help to build a proper fix.
I have attached a PDF where this behavior can be observed.
Test_libpdf.pdf
Here is the code I used for testing:
form.fill({
"text": "test",
"check": true,
});
form.flatten();