question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to flatten PDF if widget doesn't have P reference

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
btecucommented, Dec 28, 2020

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?

0reactions
btecucommented, Jan 3, 2021

@Hopding thanks for the detailed explanation. The pull request should be ready for review now.

Read more comments on GitHub >

github_iconTop 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 >

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