开发者

wkhtmltopdf vs fpdf and questions regarding use and performance (HTML to PDF)

I have not been able to find answers to my questions on the several posts about the same topic, that is why I will be asking more specific questions here.

My questions are about wkhtmltopdf and fpdf. I need one of those to create 1 page invoices (really basic design) and 1 page reports (basic design as well) so very small PDF documents.

I have read that most people recommend wkhtmltopdf because of it's performance but for small 1 page documents does it really make a difference vs fpdf? Is it really less memory consuming? Faster?

I know th开发者_开发问答at is a silly question but I also need to know if wkhtmltopdf can be executed multiple times at once. I mean, if there are 1000 users on my site trying to save their invoice in PDF at the same time? Is there a limit, how does it work? I know that fpdf is a php class so I don't have to "worry" about this (I only need the proper php.ini configuration I guess).

What would you suggest? For small PDF documents but high performance to be able to handle a lot of requests at the same time.

Are there any other options?

Thank you for your help!


The short answer is yes - you can create mutiple instances of wkhtmltopdf simultaneously each converting its own html page to pdf. However, wkhtmltopdf runs as an operating system process which means that if 1000 users are viewing their invoices at the same time, 1000 wkhtmltopdf processes will be spawned in the server which is probably not what you want.

On the other hand, FPDF runs as part of the web server process inside the PHP runtime and will not have this limitation. If you are creating a small or even big a invoice, I will suggest using FPDF since it is fairly easy to create an invoice using FPDF. Not only you will have a lot of control over PDF page layout, you will also save time during maintenance/upgrade later.

One of the problem I have encountered with wkhtmltopdf is page breaking. Wkhtmltopdf will not break your pages as you might expect. For example, a line of text may be split between two pages - upper part of a line of text appearing at the end of one page and lower part appearing at the start of the next page. In order to avoid this behavior, you have to set css attributes page-break-after or page-break-before judiciously in your html pages which can be difficult sometime because you are not sure where the page will break.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜