Hopding / pdf-lib

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

PDF417 barcode tied to fields are not rendering #1415

Open brandensiegle opened 1 year ago

brandensiegle commented 1 year ago

What were you trying to do?

I am trying to use pdf-lib to fill out a pdf that has a PDF417 barcode added in Acrobat that has it's output tied to some fields.

How did you attempt to do it?

The form was generated in Adobe Acrobat and works when filled in manually in Acrobat/Reader. I then used pdf-lib to set the text of the fields I needed changed, then saved the result to disk following the sample in the README.

What actually happened?

When changing a field that the barcode is tied to, the barcode goes grey. When opening in Acrobat and editing the form after the barcode goes grey, the field states "Barcode Render Error" image

What did you expect to happen?

I expected the barcode in the output PDF to still update as fields were modified in Reader/Acrobat as seen on the left in below video

Recording of expected vs actual

How can we reproduce the issue?

async function fillPdfFields(
  pdfBuffer: Buffer,
  fieldValues: { [fieldKey: string]: string | undefined } = {"borrowerFirstName": "Jovan","borrowerLastName": "Jovan"}
): Promise<Buffer> {
  const pdfDoc = await PDFDocument.load(pdfBuffer);

  const form = pdfDoc.getForm();

  for (const field of form.getFields()) {
    const fieldName = field.getName();
    if (Object.keys(fieldValues).includes(fieldName) && fieldValues[fieldName]) {
      form.getTextField(fieldName).setText(fieldValues[fieldName]);
    }
  }

  return Buffer.from(await pdfDoc.save());
}

Input File Broken Output

Recording of expected vs actual

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response

cm4h commented 11 months ago

I would like to know if there is a solution or workaround to this issue, as I have the same problem.