HTML到PDF与通过PHP以编程方式创建PDF [英] HTML to PDF vs. Programmatically creating PDF via PHP

查看:92
本文介绍了HTML到PDF与通过PHP以编程方式创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP应用程序,需要生成一些带有漂亮的页眉/页脚的PDF发票和PDF时间表.一些Stackoverflow用户建议使用TCPDF创建PDF文档.在研究中,我发现了两种生成PDF的方法:

I have a PHP application that needs to generate some PDF invoices and PDF timesheets with nice headers/footers. Some Stackoverflow users recommend using TCPDF to create the PDF documents. In my research, I discovered two approaches to generating PDFs:

1)像这样以编程方式设置PDF格式:

1) Programmatically formatting the PDF like so:

    $tcpdf->SetFillColor(255, 0, 0);
    $tcpdf->SetTextColor(255);
    $tcpdf->SetDrawColor(128, 0, 0);
    $tcpdf->SetLineWidth(0.3);
    $tcpdf->SetFont('', 'B');

2)将HTML转换为PDF

2) Converting HTML to PDF

如何确定应该使用哪种方法?

How do I decide which I approach I should use?

推荐答案

我可以推荐

I can recommend Zend_Pdf, which is a programmatic method according to your classification.

HTML抽象很不错,但是我不相信您具有基于完整几何图形的绘图API的全部功能和控制权.警惕fpdf之类的不支持UTF-8的库,并使用穷人解析器将HTML转换为PDF.

A HTML abstraction is nice but I don't believe you have the full power and control of a full geometry based drawing API. Be wary of libraries like fpdf which don't support UTF-8 out of the box, and use a poor man's parser to 'convert' HTML to PDF.

关于您的应用程序,我已经创建了一个生成模板化发票的系统.我的用户可以上传PDF模板,该模板由Zend_Pdf提取.然后,此模板可用于生成的发票的每一页,从而可以轻松进行自定义.

With regard to your application, I have produced a system which generates templated invoices. My users can upload a PDF template, which is extracted by Zend_Pdf. This template is then used for every page of the invoice generated, allowing easy customisation.

请注意,我的听众主要是能够生成这些模板的图形设计师,因此这里是合适的解决方案.如果您的听众只熟悉HTML,则将HTML转换为PDF可能是最好的方法.

Note that my audience are mainly graphic designers who are capable of producing these templates, so it was the appropriate solution here. If your audience are only familiar with HTML, 'converting' HTML to PDF might be the best way.

这篇关于HTML到PDF与通过PHP以编程方式创建PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆