Expected instance of PDFDict or PDFStream, but got instance of undefined
What were you trying to do?
Expected instance of PDFDict or PDFStream, but got instance of undefined
How did you attempt to do it?
I flattened a PDF fillable file and want to get Buffer data from it. But an error occurred: Expected instance of PDFDict or PDFStream, but got instance of undefined my code: note: bufferData is a Buffer data which got from PDF fillable file
const pdfDoc = await PDFDocument.load(bufferData);
cosnt form = pdfDoc.getForm();
form.flatten();
const resultBytes = await pdfDoc.save();
But when i use a PDF fillable file which has one page, that works fine! My files: 0000013_ArizonaForm.pdf
What actually happened?
at new UnexpectedObjectTypeError (/app/node_modules/pdf-lib/src/core/errors.ts:31:5)
at PDFContext.lookup (/app/node_modules/pdf-lib/src/core/PDFContext.ts:166:11)
at PDFDict.lookup (/app/node_modules/pdf-lib/src/core/objects/PDFDict.ts:143:38)
at PDFWidgetAnnotation.PDFAnnotation.getAppearances (/app/node_modules/pdf-lib/src/core/annotation/PDFAnnotation.ts:112:18)
at PDFTextField.needsAppearancesUpdate (/app/node_modules/pdf-lib/src/api/form/PDFTextField.ts:764:16)
at PDFForm.updateFieldAppearances (/app/node_modules/pdf-lib/src/api/form/PDFForm.ts:646:17)
at PDFDocument.
What did you expect to happen?
I can get Buffer data from PDF fillable files.
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
- [X] I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response
Yep, having the same issue with some fillable documents. It seems almost random, since some fillable multi-page documents do not work for me, others do. I do not use .flatten(). Didn't have such a problem for a long time using this library to fill in forms in PDFs, but now issues with certain files. For me the error also occurs on .save().
Hi, I recently had this same issue and solved it by passing a parameter when saving the pdf
const resultBytes = await pdfDoc.save({ updateFieldAppearances: false });
Hope this helps y'all.
Hi, I recently had this same issue and solved it by passing a parameter when saving the pdf
const resultBytes = await pdfDoc.save({ updateFieldAppearances: false });Hope this helps y'all.
Are there any side effects you see?
@chrisrodz thanks for the suggestion.
I believe, however, that this will not help if you're filling form fields (like I am). As the config param implies, it does not show the value as changing when it saves the PDF, though the text does appear if you open the PDF in Adobe Reader and focus on the field.
I'm now trying to figure out a work around that allows me to omit that config param.
@chrisrodz as @omgreenfield , it does not show the value as changing when saving, so some readers (such as the Preview on Mac) show the field as empty even though it is filled in.