Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.74k stars 645 forks source link

Unable to print the document which is filled with same text field twice. #1553

Open muhammadhamzajamshed opened 9 months ago

muhammadhamzajamshed commented 9 months ago

What were you trying to do?

Hello Pdf-lib Sample-pdf-for testing.pdf sample file with fields.pdf Team,

I am filling out the pdf document and the document contains 2 sections one for the user and one for the customer. Both the section needs to be filled with the same text field data.

I am having trouble printing the pdf using Adobe Acrobat. When you try to fill out the same field twice on the same page, it doesn't allow me to print a PDF. However, if you only fill out the field once, it prints without any problems. The print option not only works using Adobe but we are able to print using other PDF libraries.

Below is the ticket with the Adobe team for this issue. They asked me to consult the library team that I am using.

Adobe discussion Link :https://community.adobe.com/t5/acrobat-discussions/unable-to-print-the-document-which-is-filled-with-same-text-field-twice/m-p/14253189#M440044

How did you attempt to do it?

I am filling the pdf with the code using the information received. Look below

let readFile = fs.readFileSync( path.resolve( __dirname ) ); const pdfDoc = await pdf.PDFDocument.load(readFile); const form = pdfDoc.getForm(); const unit_number = form.getTextField("suite"); const building_name = form.getTextField("address"); const time = form.getTextField(""); unit_number.setText(UnitNumber); date_of_notice.setText( dateFormat(moment().toISOString(), "mmmm dd, yyyy") );

              time.setText(
                dateFormat(
                  oderWorkDate + "" + userCurrentTimeZone,
                  "mmmm dd, yyyy"
                )
              );
              form.flatten();

Might help you understand what I mean to say and how I am filling the PDF. Thanks Muhamamd hamza jamshed

What actually happened?

Why does a PDF file get corrupted when you fill out the same input field twice, but it prints fine when you fill each field only once?

My Use Case:

  1. Use the input text fields 1 time for each (unit, building, etc) it works perfectly.
  2. Use the input text fields twice the file generated will corrupted.

Scenario The scenario that creates a file that will get corrupt:

  1. Take a pdf document
  2. Add the input text field with the name "text field name"
  3. Use 2-time text fields of the same name
  4. Fill the text field with the data(populate fields)
  5. Then open the pdf file which is filled and try to print
  6. The issue will occur which I am talking about

Question:

Why can other PDF libraries and applications print this corrupted file, while the original software struggles to handle it?

What did you expect to happen?

It should allow me to print the file using Adobe Acrobat Reader but it does not allow me cause the file gets corrupted after filling in the data. Adobe Acrobat Reader

How can we reproduce the issue?

https://community.adobe.com/t5/acrobat-discussions/unable-to-print-the-document-which-is-filled-with-same-text-field-twice/m-p/14253189#M440044

Version

"pdf-lib": "^1.17.1",

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

I am reaching out to seek your guidance and support in navigating the above specific scenario. Your expertise and assistance in this matter would be greatly appreciated.

Thank you in advance for your time and support.

Thanks Best regards

Muhammad Hamza Jamshed

Jeff-Hamby commented 7 months ago

I was able to recreate this issue myself. I was able to get around it by committing out the form.flatten(), but unfortunately, this leaves the form open to editing which I don't want.