Reputation: 47
I am trying to convert an HTML content to PDF, but I am getting Invalid parameters for scale and preferCSSPageSize when passed using variables.
Error Message:
Error: Protocol error (Page.printToPDF): Invalid parameters scale: double value expected; preferCSSPageSize: boolean value expected at Promise (/home/santhosh-4759/Downloads/node-v8.11.3-linux-x64/bin/node_modules/puppeteer/lib/Connection.js:202:56) at new Promise ()
Command Used:
./node puppeteerpdf.js test.pdf 1 false '' '' false false 210mm 297mm 0 0 0 0 false 'htmlcontent'
This doesn't work:
await page.pdf({path: output, scale: vcale, displayHeaderFooter: displayHeaderFooter, headerTemplate: headerTemplate, footerTemplate: footerTemplate, printBackground: printBackground, landscape: landscape, width: width, height: height, margin: marginParams, preferCSSPageSize: preferCSSPageSize});
This is working:
await page.pdf({path: output, scale: 1, displayHeaderFooter: displayHeaderFooter, headerTemplate: headerTemplate, footerTemplate: footerTemplate, printBackground: printBackground, landscape: landscape, width: width, height: height, margin: marginParams, preferCSSPageSize: false});
Upvotes: 2
Views: 11014
Reputation: 28999
It appears that the variables you are passing to page.pdf()
as the values for scale
and preferCSSPageSize
are not of the correct type.
Your working example shows scale
to be equal to 1
and preferCSSPageSize
to be equal to false
.
These are the default values of these parameters, so you could safely exclude them from the options passed to page.pdf()
.
If these values can change, and you are obtaining the values of these attributes from the command line, make sure to convert them from a string to the correct type before sending them to page.pdf()
:
vcale = parseInt(vcale);
preferCSSPageSize = preferCSSPageSize === 'true';
Upvotes: 2