wkhtmltopdf 与 fpdf 以及有关使用和性能的问题(HTML 到 PDF)
我无法在有关同一主题的几篇帖子中找到我的问题的答案,这就是为什么我将在这里提出更具体的问题。
我的问题是关于 wkhtmltopdf 和 fpdf 的。我需要其中之一来创建 1 页发票(非常基本的设计)和 1 页报告(也是基本设计)以及非常小的 PDF 文档。
我读到大多数人推荐 wkhtmltopdf 因为它的性能,但对于小型 1 页文档,它与 fpdf 真的有区别吗?真的能减少内存消耗吗?快点?
我知道这是一个愚蠢的问题,但我还需要知道 wkhtmltopdf 是否可以一次执行多次。我的意思是,如果我的网站上有 1000 个用户同时尝试将发票保存为 PDF 格式怎么办?有限制吗,如何运作?我知道 fpdf 是一个 php 类,所以我不必“担心”这一点(我猜我只需要正确的 php.ini 配置)。
你有什么建议?对于小型 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 that 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的答案是肯定的 - 您可以同时创建 wkhtmltopdf 的多个实例,每个实例将其自己的 html 页面转换为 pdf。然而,wkhtmltopdf 作为操作系统进程运行,这意味着如果 1000 个用户同时查看他们的发票,服务器中将生成 1000 个 wkhtmltopdf 进程,这可能不是您想要的。
另一方面,FPDF 作为 PHP 运行时内 Web 服务器进程的一部分运行,并且不会有此限制。如果您要创建小型甚至大型发票,我建议使用 FPDF,因为使用 FPDF 创建发票相当容易。您不仅可以对 PDF 页面布局进行大量控制,还可以节省以后维护/升级的时间。
我在使用 wkhtmltopdf 时遇到的问题之一是分页。 Wkhtmltopdf 不会像您预期的那样破坏您的页面。例如,一行文本可以分为两页——一行文本的上半部分出现在一页的末尾,下半部分出现在下一页的开头。为了避免这种行为,您必须在 html 页面中明智地设置 css 属性 page-break-after 或 page-break-before ,这有时会很困难,因为您不确定页面将在哪里中断。
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.