Skip to content

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

Closed

Description

@neoygdrassyl

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.

Activity

  1. Hopding commented on Sep 22, 2021

    @Hopding
    Owner

    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.

  2. sscotti commented on Jun 25, 2022

    @sscotti

    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/pdf-lib@1.16.0/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.

  3. makarov-roman commented on Jul 20, 2022

    @makarov-roman
  4. added a commit that references this issue on Feb 26, 2023
    c978b4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions