-
-
Notifications
You must be signed in to change notification settings - Fork 822
Open
Labels
Description
What were you trying to do?
flatten document.
How did you attempt to do it?
example to reproduce below
What actually happened?
crash on flatten call
Error: Could not find page for PDFRef 220 0 R
at PDFForm.findWidgetPage (/home/roman/Projects/monorepo/packages/lambdas/pdfService/node_modules/pdf-lib/cjs/api/form/PDFForm.js:603:23)
at PDFForm.flatten (/home/roman/Projects/monorepo/packages/lambdas/pdfService/node_modules/pdf-lib/cjs/api/form/PDFForm.js:458:33)
What did you expect to happen?
not having a crash
How can we reproduce the issue?
const { PDFCheckBox, PDFDocument, PDFTextField } = require('pdf-lib');
const fs = require('fs');
const fill = async () => {
try {
const Body = fs.readFileSync(
'internshipApplicationForFurtherEducation.pdf',
);
const pdfDoc = await PDFDocument.load(Body);
const form = pdfDoc.getForm();
form.flatten();
const result = await pdfDoc.save({ useObjectStreams: true });
fs.writeFileSync('result.pdf', result);
} catch (e) {
console.error(e);
throw e;
}
};
fill();Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- My report includes a Short, Self Contained, Correct (Compilable) Example.
- I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
In our project I have around 30 different pdfs and only 2 has such issue. Not sure if it's corrupted metadata or something else. Before it was working with pdftk.