Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using flatten, Could not find page for PDFRef #967

Closed
neoygdrassyl opened this issue Aug 18, 2021 · 3 comments · May be fixed by #1407
Closed

Error when using flatten, Could not find page for PDFRef #967

neoygdrassyl opened this issue Aug 18, 2021 · 3 comments · May be fixed by #1407

Comments

@neoygdrassyl
Copy link

I'm currently trying to figure out what is going on.

I fill a form from my PDF and then I need to use flatten in order to "save" the values and then download said PDF.

At the moment of using flatten there is an Unhandled Rejection, as follows

Unhandled Rejection (Error): Could not find page for PDFRef 439 0 R

which I understand means that once the field is flatten, the library will delete the field and uses the ref value of the field in order to do this, in this case, it looks for a field with a ref value of "439 0 R" but it does not exist, so I looked around to see what was said problem, using the following code

const fields = form.getFields()
fields.forEach(field => {
    const type = field.constructor.name
    const name = field.getName()
    const ref = field.ref
    const acroField = field.acroField
    console.log(`${type}: ${name} - ${ref}`)
  })

and found out that the ref values only go around 200-ish, about the same number of fields from the PDF.

PDFCheckBox: cb_1_1_a - 11 0 R 
PDFCheckBox: cb_1_1_b - 12 0 R
PDFCheckBox: cb_1_1_c - 13 0 R 
PDFCheckBox: cb_1_1_d - 14 0 R
PDFCheckBox: cb_1_1_e - 15 0 R 
PDFCheckBox: cb_1_1_f - 16 0 R 
PDFCheckBox: cb_1_1_g - 17 0 R 

[...]

PDFCheckBox: cb_52_4_s - 208 0 R
PDFCheckBox: cb_52_4_n - 209 0 R 
PDFTextField: tb_53_1 - 210 0 R 
PDFTextField: tb_53_2 - 211 0 R 
PDFTextField: tb_53_3 - 212 0 R
PDFTextField: tb_53_4 - 213 0 R
PDFTextField: tb_53_5 - 214 0 R 
PDFCheckBox: cb_1_8_b - 215 0 R
PDFCheckBox: cb_1_8_c - 216 0 R

the field "cb_1_8_c " is the last field of the form and has a ref value of "216 0 R"

So, I have no idea what is happening, what is causing the function flatten to use a ref value of "439 0 R" when none of the current fields have such.

The PDF I'm using was a flat document that I later add field forms using online tools.

@Hopding
Copy link
Owner

Hopding commented Sep 22, 2021

Hello @neoygdrassyl! I'll need more information to be of any assistance on this. Please fill out the new bug report form and we can continue from there.

@sscotti
Copy link

sscotti commented Jun 25, 2022

I encounter a similar issue recently. We created a PDF from a Word document and then added fields using Wondershare's PDF Element software. When I try to flatten the form (which is multipage) I get:

Uncaught (in promise) Error: Could not find page for PDFRef 1188 0 R
    findWidgetPage PDFForm.js:592
    flatten PDFForm.js:456
    Flatten regform:181
    async* regform:186
    jQuery 8
    <anonymous> regform:156
[PDFForm.js:592:22](https://unpkg.com/[email protected]/es/api/form/PDFForm.js)

I haven't had trouble with the same code for other pages that we created, although those are all single page forms.

@makarov-roman
Copy link

#1281

emilsedgh added a commit to emilsedgh/pdf-lib that referenced this issue Feb 26, 2023
that couldn't be found on any pages. Up until now we've been throwing
an exception when dealing with such fields. But it appears that other
PDF software are more resilient to this and gracefully ignore them.

This commit ensures we'll do the same.

Fixes Hopding#967,Hopding#1281,Hopding#1349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants