Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Ubuntu中使用Python将HTML页面转换为Pdf?_Python_Html_Python 3.x_Pdf - Fatal编程技术网

如何在Ubuntu中使用Python将HTML页面转换为Pdf?

如何在Ubuntu中使用Python将HTML页面转换为Pdf?,python,html,python-3.x,pdf,Python,Html,Python 3.x,Pdf,我试图弄明白如何在一个无头ubuntu服务器上用python将html页面转换并下载为pdf。我尝试过使用wkhtmltopdf/pdfkit,但我尝试过的版本都不起作用(包括使用静态版本,而不是ubuntu存储库版本,因为这降低了功能)。您可以使用WeasyPrint 安装: pip install weasyprint 代码: 导入weasyprint pdf=weasyprint.HTML('http://www.google.com)。请填写 打开('google.pdf','wb')

我试图弄明白如何在一个无头ubuntu服务器上用python将html页面转换并下载为pdf。我尝试过使用wkhtmltopdf/pdfkit,但我尝试过的版本都不起作用(包括使用静态版本,而不是ubuntu存储库版本,因为这降低了功能)。

您可以使用WeasyPrint

安装:

pip install weasyprint
代码:

导入weasyprint
pdf=weasyprint.HTML('http://www.google.com)。请填写
打开('google.pdf','wb')。写入(pdf)

发件人:

这是否回答了您的问题?非常感谢。有没有办法设置输出路径?@decoy24601我想你只要用你想要的任何东西替换“google.pdf”