使用 PDFLib 通过 PHP 创建表

发布于 2024-11-06 03:46:01 字数 193 浏览 5 评论 0原文

我想知道是否有关于如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

口干舌燥 2024-11-13 03:46:01

我过去曾多次使用过 PDF 生成,并且通常发现它是一个巨大的难题。

PDFLib 的文档 http://www.pdflib.com /fileadmin/pdflib/pdf/manuals/PDFlib-8.0.2-tutorial.pdf 开始解释您在第 193 页第 8.2 节中查找的内容。您将创建多线流。那里的代码看起来很吓人,但是需要一些时间来完成它,它非常接近您最终将使用的代码。

我稍后可能可以找到一些代码,但我忘记了我使用的是什么库。现在有一些提示:

  • 在纸上进行计算,就像他们标记的示例一样。你希望事情开始、结束等的地方。
  • 使用清晰的变量名称来存储这些偏移量。不是常数!
  • 寻找好的极端例子来在开发时进行测试。使用“测试”之类的文本进行开发,以便稍后发现您需要支持“我是现代少将的典范”,可能会打乱您的整个流程,并要求您从头开始。
  • 一些库“支持”HTML 嵌入,包括 HTML 表格。这首海妖之歌很甜美,但会带你进入锋利的岩石。我使用过的每个库都对它们有一点支持,但随后您就会遇到困难,如果不删除表并恢复到本机函数,就无法进行下一个小调整。总而言之,和他们一起玩实在是浪费了很多时间。

更新
我找到了最近的代码迭代,我们使用了 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:

  • Work it out on paper, just like their marked up examples. Where you want things to start, end, and such.
  • Use clear variable names to store those offsets. Not constants!
  • Find good extreme examples to test with while developing. Developing with text like "test" to find out later you need to support "I am the very model of the modern major general" may throw off your entire flow, and require you to start from scratch.
  • Some libraries "support" HTML embeds, including HTML tables. This siren song is sweet, but will lead you into the razor sharp rocks. Every library I've used supports them a little bit, but then you run into a wall where you can't get the next little tweak without dropping tables and reverting to native functions. They've been a huge waste of time to play with, one and all.

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.

傾旎 2024-11-13 03:46:01

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文