嗨有没有人知道我可以通过PHP创建一个格式良好的PDF发票?PHP创建PDF发票
理想情况下,我正在寻找的东西有一个标题,然后列出一些产品与周围某种表。经过一段快速的Google之后,我会对生成PDF格式感到满意,但尝试并很好地设计它的样式完全是另一回事。
感谢
嗨有没有人知道我可以通过PHP创建一个格式良好的PDF发票?PHP创建PDF发票
理想情况下,我正在寻找的东西有一个标题,然后列出一些产品与周围某种表。经过一段快速的Google之后,我会对生成PDF格式感到满意,但尝试并很好地设计它的样式完全是另一回事。
感谢
我使用TCPDF(见http://www.tcpdf.org/)本:它很能干,不会太痛苦得到建立。我会说,根据您的数据源,您可能会遇到一些问题。在我的情况,我的数据是从SOAP接口外包给我的会计系统,并使用笨我的应用程序,我可以做到这一点:
$address = $extraclient->get_company_address();
// generate the PDF invoice
$this->load->library('pdfinvoice');
// set document information
$this->pdfinvoice->SetSubject("Invoice " . $data_invoice['code_invoice']);
// add a page
$this->pdfinvoice->AddPage();
$this->pdfinvoice->StartPageOffset();
// write the client's details out
$width = $this->pdfinvoice->GetPageWidth()/2;
$margins = $this->pdfinvoice->getMargins();
$this->pdfinvoice->SetFont('times', 'b', $this->pdfinvoice->bigFont);
$this->_row($width, array("From:", "To:"));
$this->pdfinvoice->SetFont('times', 'i', $this->pdfinvoice->smallFont);
$this->_row($width, array("MY NAME", $customer['name_contact']));
$this->_row($width, array($address['phone'], $customer['name_customer']));
$this->_row($width, array($address['street'], $customer['address1_street']));
$this->_row($width, array($address['city']. ", ".$address['state']." ".$address['zipcode'],
$customer['address1_city']. ", ".$customer['address1_state']." ".$customer['address1_zip
完整的代码是很坦率地说太长,在这里插入,但你应该得到的想法,你会得到相当精确的布局控制。
如果您已经使用phpExcel,它内置了库(因此您可以调用该类) – rosh3000 2013-04-22 14:27:33
我会建议创造你想要的PDF什么的HTML/CSS表示并用它来生成PDF。有几十个的应用程序处理的转化,有一个很好的线程有很多答案在这里:Convert HTML + CSS to PDF with PHP?
你可能想看看html2Pdf。这是一个基于FPDF的php类,它允许您从HTML创建PDF文件。所以只需使用html格式化文本,然后创建其pdf。它非常灵活,并给予控制。
PDF生成往往会非常棘手。只要发票相对简单,我会建议创建一个模板图像文件,并使用imagettftext
在其上打印字符串(或任何其他库)。
对于图像文件转换为PDF ImageMagick的工具套件都可以使用(只要它是可用的服务器上):
exec('convert -units \'PixelsPerInch\' -density 150 '.$filename.'.png '.$filename.'.pdf');
对我来说,整个方法工作顺利。
结帐作曲家的php-pdf-invoice
图书馆。该库已经设计用于生成发票,因此它很容易和快速地集成!
composer require quickshiftin/php-pdf-invoice
您可以生成这个样子
上有README的使用实例的PDF文件。基本上你实现了两个界面,一个用于订单,另一个用于订单项目。您也可以根据自己的喜好配置字体和颜色。
你遇到过FPDF吗?我以前看过它......看起来像很多工作,但很有希望 – 2011-05-06 17:05:54
是的,现在看看它 - 这里很好的教程:http://www.web-development-blog.com/archives/create-pdf- documents-online-with-tcpdf/ – Martin 2011-05-06 17:12:41
我建议看看actualreports.com,他们是一个API和基于浏览器的文档编辑器,用于创建不同的模板。对了,他们收取他们的服务。 – Tanel 2013-09-02 11:43:40