Javascript 木偶演员投掷无效参数错误

Javascript 木偶演员投掷无效参数错误,javascript,node.js,npm,chromium,puppeteer,Javascript,Node.js,Npm,Chromium,Puppeteer,我正在尝试将HTML内容转换为PDF,但当使用变量传递时,我得到的scale和preferCSSPageSize参数无效 错误消息: 错误:协议错误(Page.printToPDF):无效参数比例:应为双值;PreferCsPagesize:应为布尔值 在承诺中(/home/santhosh-4759/Downloads/node-v8.11.3-linux-x64/bin/node_modules/puppeter/lib/Connection.js:202:56) 在新的承诺() 使用的命令

我正在尝试将HTML内容转换为PDF,但当使用变量传递时,我得到的scale和preferCSSPageSize参数无效

错误消息:

错误:协议错误(Page.printToPDF):无效参数比例:应为双值;PreferCsPagesize:应为布尔值 在承诺中(/home/santhosh-4759/Downloads/node-v8.11.3-linux-x64/bin/node_modules/puppeter/lib/Connection.js:202:56) 在新的承诺()

使用的命令:

./node puppeteerpdf.js test.pdf 1 false '' '' false false 210mm 297mm 0 0 0 0 false 'htmlcontent'
这不起作用:

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});
这是有效的:

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});

您作为
scale
preferCSSPageSize
的值传递到的变量类型似乎不正确

您的工作示例显示
scale
等于
1
preferCSSPageSize
等于
false

这些是这些参数的默认值,因此您可以安全地将它们从传递到
page.pdf()
的选项中排除

如果这些值可以更改,并且您正在从命令行获取这些属性的值,请确保在将它们发送到
page.pdf()
之前将它们从字符串转换为正确的类型:


谢谢,米勒,这很有效。正如您所说的,这些值可能会更改,因此只能将其暴露给args。
vcale = parseInt(vcale);
preferCSSPageSize = preferCSSPageSize === 'true';