During flatten, expected instance of PDFDict or PDFStream, but got instance of undefined

See original GitHub issue

Hello!

I’m encountering the following crash when trying to flatten a W4 from the IRS’ website.

/home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/errors.js:38
this = _super.call(this, msg) || this;
^
Error: Expected instance of PDFDict or PDFStream, but got instance of undefined
at new UnexpectedObjectTypeError (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/errors.js:38:24)
at PDFContext.lookup (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/PDFContext.js:93:15)
at PDFDict.lookup (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/objects/PDFDict.js:64:48)
at PDFWidgetAnnotation.PDFAnnotation.getAppearances (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/annotation/PDFAnnotation.js:89:20)
at PDFTextField.needsAppearancesUpdate (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/api/form/PDFTextField.js:670:48)
at PDFForm.updateFieldAppearances (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/api/form/PDFForm.js:534:23)
at PDFForm.flatten (/home/ubuntu/src/x/node_modules/pdf-lib/cjs/api/form/PDFForm.js:450:18)
at file:///home/ubuntu/src/x/fillOut.js:293:6

Using v1.16.0, any suggestions to workaround this issue?

My code adds a bunch of text (it doesn’t use the Form API, just writes at given coordinates), and then flatten the PDF using PDFForm.flatten().

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
NoNameProvidedcommented, Sep 2, 2021

It also worked for me to “touch” all field via setting an empty text as value inside:

const pdfDoc = await PDFDocument.load(pdfDocBytes);
const form = pdfDoc.getForm();
const fields = form.getFields();

fields.forEach(field => form.getTextField(field.getName()).setText(''));

// Form flatten works now as expected.
form.flatten();
0reactions
Hopdingcommented, Sep 23, 2021

Please fill out the new bug report form if you’re still having trouble with this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

During flatten, expected instance of PDFDict or PDFStream ...
I'm encountering the following crash when trying to flatten a W4 from the IRS' website. /home/ubuntu/src/x/node_modules/pdf-lib/cjs/core/ ...
Read more >
Trying to use pdf-lib to fill pdf form fields. Trouble Flattening ...
The issue I am having is that I want to be able to Flatten and Save the form after any online editing after...
Read more >
iTextSharp.xml - eSport
Begins handling of current pdf stream decompression. this instance. ... null iText expects Arabic Diactrics (tashkeel) to have zero advance but some fonts, ......
Read more >
iText Knowledge Base
I use ((PdfStream)obj).getBytes(), iText will look at the filter. For instance: page content streams consists of PDF syntax ...
Read more >
iTextSharp.xml
itextsharp An Anchor can be a reference or a destination of a reference. ... A Phrase has a main Font, but some chunks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found