php html_topdf,Converting HTML to PDF (not PDF to HTML) using PHP - Stack Overflow

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 2 years ago.

I am a PHP developer and in one of my projects, I need to convert some HTML documents (about 30 to 50 pages) into PDF documents.

My search has turned up the following possible solutions. Among them are some PHP libraries and some command line applications. Each has its own advantages and disadvantages.

PHP libraries:

fpdf (need more effort to convert)

tcpdf (need more effort to convert)

dompdf http://code.google.com/p/dompdf/ (compared to other, works well)

For each library, I have problems like:

Takes a long time (more than five minutes to convert 30 HTML pages)

Requires too many resources (memory and time)

(I set the following parameters in php.ini:

max_execution_time = 600

memory_limit = 250M

but things still don't work.)

Needs HTML pages to be well-formatted (e.g. no missing close tags)

All of these work when I try to convert simple HTML docs (five or fewer pages with little CSS)

Command line applications

All command line apps work perfectly and very quickly compared to the above libraries, but only when I run them directly on console. When I try to use them in PHP with exec() or system(), they give me errors.

The following are the command line applications and their errors when I run them in PHP:

html2pdf:11380): Gtk-WARNING **: cannot open display: :0.0

No protocol specified

wkhtmltopdf

Loading page: 10%

Loading page: 33%

Loading page: 100%

Waiting for redirect

Outputting pages

QPainter::begin(): Returned false

QPainter::begin(): Returned false

QPainter::save: Painter not active

QPainter::scale: Painter not active

QPainter::setRenderHint: Painter must be active to set rendering hints

QPainter::setBrush: Painter not active

QPainter::pen: Painter not active

QPainter::setPen: Painter not active

So now I am looking for help. Can anyone answer:

Which PHP library would work well in my case?

Why do these errors occur in command line applications?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值