简体   繁体   English

如何使用PHP动态生成PDF?

[英]How can I reduce time to generate PDF dynamically using PHP?

I am generating PDF dynamically using html2ps PHP library. 我使用html2ps PHP库动态生成PDF。 I want to decrease time of generating that PDF .I want to reduce that PDF generation time .Is there any way to reduce the time or optimize it? 我希望减少生成PDF的时间。我想减少PDF生成时间。有什么方法可以减少时间或优化它?

Help me please. 请帮帮我。

One method of optimizing is to try another library. 一种优化方法是尝试另一个库。 I use dompdf when I need to convert HTML to PDF, and I haven't found any need for optimizing, it's very fast, supports CSS properly and produces accurate results. 当我需要将HTML转换为PDF时,我使用dompdf ,我没有发现任何需要优化,它非常快,正确支持CSS并产生准确的结果。

  1. Reduce the complexity of the output. 降低输出的复杂性。
  2. Reduce the output quantity. 减少产量。
  3. If the PDF generation is impacting other operations, delegate it to another process or server. 如果PDF生成正在影响其他操作,请将其委派给另一个进程或服务器。

I'm sure you can avoid a lot of processing by skipping the HTML/CSS step(s) and go directly to PDF. 我确信你可以通过跳过HTML / CSS步骤避免大量处理,直接转到PDF。 Check FPDF or PDFLib 检查FPDFPDFLib

Are you running this code on recent hardware? 您是否在最近的硬件上运行此代码?

While it may sound like avoiding the solution, on the Coding Horror Blog (whom happens to be the guys who made this site) they preach that you shouldn't spend time tweaking performance if your hardware is limited. 虽然这可能听起来像是避免了解决方案,但在编码恐怖博客(恰好是制作这个网站的人)上,他们宣传如果您的硬件有限,就不应该花时间调整性能。

If you're doing this on a single core CPU (ex: Pentium 4), you are wasting your time worrying about what library to use or what code to change. 如果你是在单核CPU(例如Pentium 4)上进行此操作,那么你就会浪费时间来担心要使用的库或要更改的代码。 Even the slowest Core 2 Duos and newer AMDs start at 2x faster than the best Pentium 4. 即便是最慢的Core 2 Duos和更新的AMD也比最好的Pentium 4快2倍。

PS: I wasn't able to find the article on their site to link for you. PS:我无法在他们的网站上找到为您链接的文章。

PPS: Most Pentium 4 motherboards support the 65nm Core 2 Duos. PPS:大多数Pentium 4主板支持65nm Core 2 Duos。

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

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