简体   繁体   English

HTML到PDF的node-wkhtmltopdf在Digital Ocean Droplet服务器上崩溃

[英]HTML to PDF with node-wkhtmltopdf crashing on a Digital Ocean Droplet server

I'm trying to generate a pdf file from html and would like to know the best way. 我正在尝试从html生成pdf文件,并想知道最好的方法。 I've tried html-pdf, pdf-puppeteer, node-wkhtmltopdf. 我试过了html-pdf,pdf-puppeteer,node-wkhtmltopdf。

The first 2 crash the server when used giving 0 errors on a Digital Ocean Droplet using an Ubuntu image. 当使用Ubuntu映像在Digital Ocean Droplet上给0错误时,前2个会使服务器崩溃。 They work fine on my computer (MAC OS), but fail to where on the server. 它们可以在我的计算机(MAC OS)上正常工作,但是无法到达服务器上的任何位置。 When I tried node-wkhtmltopdf, which looked promising: 当我尝试node-wkhtmltopdf时,它看起来很有希望:

var wkhtmltopdf = require('wkhtmltopdf');

wkhtmltopdf(html).pipe(res);

It crashed giving an error message: > 它崩溃并显示错误消息:>

Error: qt.qpa.screen: QXcbConnection: Could not connect to display 错误:qt.qpa.screen:QXcbConnection:无法连接到显示器

Could not connect to any X display 无法连接到任何X显示器

I would like to know the best way I can create pdfs using a Digital Ocean Droplet. 我想知道使用Digital Ocean Droplet创建pdf的最佳方法。

Found the solution, the qt is broken for the version which is installed using 'apt-get install' on ubuntu. 找到解决方案后,使用ubuntu上的“ apt-get install”安装的版本的qt损坏了。

So, I installed wkhtmltopdf from the git repository and it worked fine. 因此,我从git仓库安装了wkhtmltopdf,并且运行良好。

https://github.com/wkhtmltopdf/wkhtmltopdf/releases/ https://github.com/wkhtmltopdf/wkhtmltopdf/releases/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM