Unable to flatten PDF if widget doesn't have P reference
See original GitHub issueWhen running form.flatten() on some PDFs, like from this this example, I get this error:
Error: Failed to find page undefined for element favorite.superhero
at _loop_1 (/node_modules/pdf-lib/cjs/api/form/PDFForm.js:463:27)
at PDFForm.flatten (/node_modules/pdf-lib/cjs/api/form/PDFForm.js:492:17)
Here is an example of PDF that will produce this error and where form isn’t on 1st page. (Originally posted here)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to flatten an image in Adobe Acrobat Standard DC
Flatten means at least 3 different things in a PDF, and none of them relate to images. So please explain what you want...
Read more >What “Flatten PDF File” Means and How To Do It - Printivity
1. Create a backup of your PDF file · 2. Go to Advanced > Print Production > Flattener Preview · 3. Adjust the...
Read more >PTField Class Reference - PDFTron
Form 'flattening' refers to the operation that changes active form fields into a static area that is part of the PDF document, just...
Read more >Quick Reference Guide: How to Flatten a PDF
PDFs that are not flattened can create errors when users upload documents to a sponsor's system. The steps listed below provide instructions for...
Read more >WindowManager.LayoutParams - Android Developers
Window flag: if you have set FLAG_NOT_TOUCH_MODAL , you can set this flag to ... to have a window pan when an input...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve created a draft pull request with a possible solution. The approach was to find the widget reference and then find the page that has that widget reference. Ideally, I would have preferred to update
P()to do all this work, so that we don’t have to call another method for fallback, however, the document is required to get the pages and I’m not aware if there’s a way to access the document without passing it in. Perhaps @Hopding has other ideas or opinions about the apis?However, when testing the example document, I am getting a different error, possibly unrelated, something about
AcroField. @Hopding / @chislin do you have some time to take a look?@Hopding thanks for the detailed explanation. The pull request should be ready for review now.