How to generate editable PDF using puppeteer
Asked Answered
E

3

5

I am trying to generate PDF using puppeteer, everything works fine but input & checkboxes are not editable. In documentation i can't find how to make it editable, or elsewhere.

is it possible ? if so how ?

// ... 
const _conf = _.merge(conf, {
    format: 'A4',
    margin: {
       left: '15px',
       top: '15px',
        right: '15px',
        bottom: '15px'
                    }
   });
   const browser = await puppeteer.launch({ headless: true })
   const page = await browser.newPage()
   await page.setContent(html)
   const buffer = await page.pdf()

   await browser.close()


   return buffer;

Episternum answered 3/1, 2020 at 20:49 Comment(0)
A
10

Puppeteer is a Node library which provides a high-level API to control Chromium over the DevTools Protocol. The API allows you to call Chromium functionality to generate PDF. The API doesn't do anything special, just providing the layer to the functionality of Chromium. As of the above, this is not the question for Puppeteer team indeed. They already answered this @ Pdf form inputs not editable.

Now to the Chromium ... "Save as PDF" option is designed to generate PDF for printing and does not support HTML form controls mapping to PDF AcroForms elements. They are not going to implement it any time soon per answer from the project member @ Issue 1024713: save-as-pdf doesn't generate editable form inputs.

Bottom line: It is not possible with Puppeteer.

Amadoamador answered 8/1, 2020 at 14:53 Comment(0)
E
1

To those who got stuck like I did last time - as the answer above it can not be done with puppeteer, but I wrote lib on top of pdftk supporting also UTF8 chars and reusing the same prop for multiple fields in pdf - https://www.npmjs.com/package/pdftk-fill-pdf

Episternum answered 21/5, 2023 at 15:30 Comment(0)
D
0

I know this is a Python lib but WeasyPrint now supports a falg called --pdf-forms wich converts html input elements to fillable PDF form: https://doc.courtbouillon.org/weasyprint/stable/api_reference.html#cmdoption-pdf-forms

Dyne answered 23/7, 2024 at 12:41 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.