操纵up引发无效参数错误 [英] Puppeteer Throwing Invalid Parameters Error

查看:105
本文介绍了操纵up引发无效参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将HTML内容转换为PDF,但是使用变量传递时,缩放和InvalidCSSPageSize参数无效。

I am trying to convert an HTML content to PDF, but I am getting Invalid parameters for scale and preferCSSPageSize when passed using variables.

错误消息:


错误:协议错误(Page.printToPDF):无效的参数比例:预期值为双精度; preferredCSSPageSize:布尔值期望
在Promise(/home/santhosh-4759/Downloads/node-v8.11.3-linux-x64/bin/node_modules/puppeteer/lib/Connection.js:202:56)
在新的Promise()

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 ()

使用的命令:

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


推荐答案

似乎您要传递给 page.pdf() ,因为 scale preferCSSPageSize 的值类型不正确。

It appears that the variables you are passing to page.pdf() as the values for scale and preferCSSPageSize are not of the correct type.

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

Your working example shows scale to be equal to 1 and preferCSSPageSize to be equal to false.

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

These are the default values of these parameters, so you could safely exclude them from the options passed to page.pdf().

如果这些值可以更改,并且您正在命令行中获取这些属性的值,请确保将它们从字符串转换为正确的类型,然后再将它们发送到页.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';

这篇关于操纵up引发无效参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆