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});
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});
Share
Improve this question
edited Aug 18, 2018 at 23:02
Grant Miller
29.1k16 gold badges156 silver badges170 bronze badges
asked Aug 18, 2018 at 15:52
Santhosh ManikandanSanthosh Manikandan
471 gold badge1 silver badge12 bronze badges
1 Answer
Reset to default 2It 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 mand 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';