PejmanNik/puppeteer-report

Return Buffer instead of bytes

Closed this issue · 7 comments

since -report is using pdf-lib the return value from the .page and .pdf is Promise<Uint8Array> which in turn is giving us a lot of issues when combing with node-signpdf that we are using to sign the PDF.

We're using puppeteer-report due to the limitations of puppeteer regarding running scripts on the footer/header templates (thank you for this lib btw) but now having trouble combining the two.

Any pointers on how we could use them or are you able to open a method/option to return the Buffer?

Current implementation

// --------------------------------- The page variable Is the puppeteer page with the HTML
const pdfBytes = await report.pdfPage(page, { format: this.config.format(), margin: this.config.margin() });
const placeholderPdfBuffer = plainAddPlaceholder({
        pdfBuffer: Buffer.from(pdfBytes),
        reason: reason,
        name: name,
        contactInfo: contactInfo,
});
return signer.sign(placeholderPdfBuffer, certBuffer);

And running plainAddPlaceholder throws an exception:

TypeError: Cannot read property 'split' of undefined
    at getXref (.../node_modules/node-signpdf/dist/helpers/plainAddPlaceholder/readRefTable.js:55:34)

Original: https://github.com/vbuch/node-signpdf/blob/develop/src/helpers/plainAddPlaceholder/readRefTable.js#L48

Any pointers would be greatly appreciated and thank you in advance for your time.

Does it work with the puppeteer pdf function?
if yes, please create a simple repo that replicates this issue, so I can debug the output.

It does, it simply uses the bytes returning the .page and running the same method from node-sign-pdf. It outputs that error (that's literally that) since the -report returns a Uint8Array and not the Buffer.

@PejmanNik sorry for the delay wasn't able to get online this week. Was finally able to create a small example:

Run with

node app.js

@PejmanNik any updates?

I was on vacation and couldn't find the time to debug. Did the mentioned PR will resolve your issue?

ok, I will close this issue, the PR needs one minor change and I can release the new version as soon as @miguelangelomendes fix it.