使用 PDFLib 通过 PHP 创建表
我想知道是否有关于如何使用 PHP 的 PDFLib 构建表格的好资料。我计划用数据库表(以及一些我连接在一起创建新视图的表)填充 PDF 文档,并且我想将其制作为 Web 的 PDF 文档。我一直在搜索,发现了很多关于 PDFLib 的信息,除了如何用它创建表格之外。
我已经在 PHP.net 上查看了 PDFLib 命令,但也无法清楚地了解需要什么。
I was wondering if there was a good source on how to build tables using the PDFLib for PHP. I am planning to populate a PDF Document with a Database Table (well a few that I join together to create a new view) and I wanted to make it a PDF document for the web. I've been searching all over and I find plenty of information on PDFLib except how to create a table with it.
I've checked out the PDFLib commands on PHP.net and also can't quite get a clear grasp of what's needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我过去曾多次使用过 PDF 生成,并且通常发现它是一个巨大的难题。
PDFLib 的文档 http://www.pdflib.com /fileadmin/pdflib/pdf/manuals/PDFlib-8.0.2-tutorial.pdf 开始解释您在第 193 页第 8.2 节中查找的内容。您将创建多线流。那里的代码看起来很吓人,但是需要一些时间来完成它,它非常接近您最终将使用的代码。
我稍后可能可以找到一些代码,但我忘记了我使用的是什么库。现在有一些提示:
更新
我找到了最近的代码迭代,我们使用了 http://www.tcpdf.org 中的库。大部分情况下它有效。在将多行文本写入页面后,我处理了光标所在位置的许多不一致问题。我最终撕掉了所有使用他们的多行代码的东西并编写了我自己的。这样就完成了,使用起来非常容易。
I've worked with PDF generation a few times in the past, and generally find it to be a huge pain in the neck.
PDFLib's documentation http://www.pdflib.com/fileadmin/pdflib/pdf/manuals/PDFlib-8.0.2-tutorial.pdf starts explaining what you're looking for in section 8.2, page 193. You'll be creating multi-line flows. The code there looks intimidating, but take some time to work through it, it's pretty close to what you'll end up using.
I may be able to find some code later, but I forget what library I was using. For now a few tips:
update
I've found my most recent code iteration, we used the library from http://www.tcpdf.org. It worked, mostly. I dealt with a lot of inconsistencies in where the cursor was left after writing multiple lines of text to a page. I ended up ripping out anything that used their multi-line code and writing my own. That done it got pretty easy to work with.
PDFlib 中的表处理变得极其困难。表格可以工作,但如果您有多个表格彼此叠放,并且希望下面的表格始终与上表格的底线保持一定距离,或者想要使用嵌套表格,那么您就会遇到麻烦。这些类似的行为是可以实现的,但是代码很复杂。为什么 pdflib 团队没有采用 html 表格的使用行为,它们在两个世纪以来一直运行良好。
由于 html 表格易于使用,一种好的方法是使用 phantomJS 从 html 生成 pdf。 PhantomJS使用webkit进行页面渲染,支持html5+css3+svg+canvas。而且除了pdf之外,它还可以输出png、jpeg和gif。
以下是使用 phantomJS 生成 PDF 发票的示例:
http://we -love-php.blogspot.fi/2012/12/create-pdf-invoices-with-html5-and-phantomjs.html
Table handling in PDFlib is made extremely difficult. Tables work, but in cases where you have multiple tables in top of each other and want the below one tables to be always at a certain distance of upper table's bottom line or want to use nested tables, you are in trouble. These like behaviors can be made, but the code is complicated. WHY pdflib team didn't take usage behaviour of html tables, where they have worked well two centuries.
Because html tables are easy to use, one good method is to use phantomJS to generate pdf from html. PhantomJS uses webkit for page rendering and supports html5+css3+svg+canvas. And in addition to pdf, it can output png, jpeg and gif.
Here is an example of using phantomJS to generate PDF-invoices:
http://we-love-php.blogspot.fi/2012/12/create-pdf-invoices-with-html5-and-phantomjs.html