如何处理dompdf两栏设计?
我想使用 dompdf 将 html 创建为 pdf。 我有一个有两列的设计。每列都可能高于普通的 dina4 页面。所以我有一个分页符。
我不想使用浮动,因为 dompdf 浮动有时有问题,我不想浮动某些东西,我想要两个修复容器(左,右)。
如果我使用位置:绝对;该容器无法进行分页。配位:固定;这个容器位于每个 dina4 站点上(对于页脚和页眉来说很好,对于我的解决方案来说很糟糕)。
如果我使用包含两列的表来设计它,dompdf 无法处理表中的表,并且我收到错误消息。但我必须使用表格来存储我的内容。
对于这个问题还有其他解决方案吗? postion:absolute 带有正确的分页符还是其他什么?
编辑:
我的页面: div 标题(位置:固定;) div 页脚(位置:固定;) div 内容(2 栏设计 - 左右分页符)
最好的祝福
i want to use dompdf to create html to pdf.
I have an design with two columns. Every column could be higher than a normal dina4 page. So i have a page-break.
I dont want to use float, because dompdf float is buggy sometimes and i dont want to float something, i want two fix containers (left, right).
If i use position:absolute; this container cant make a page-break. With position:fixed; this container is on every dina4 site (nice for footer and header, bad for my solution).
If i use a table with two columns to design it, dompdf can not handle table in table and i get an error message. But i have to use a table for my content.
Are there any other Solutions for this Problem?
postion:absolute with a correct page break or something else?
EDIT:
My Page:
div header (position: fixed;)
div footer (position: fixed;)
div content (2 column design - left & right with page breaks)
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用相对位置 &绝对位置并留有左边距。这适用于单个页面,因此应该适用于多个页面。
You could use position relative & position absolute with left margins. This works on a single page so should work over more than one page.
我以前遇到过这个问题(列布局拆分为多个页面),使用 DomPdf 获取列布局的最简单方法是使用表格来设置页面,并在何时进行某种计算创建新的行和列。这确实对我有用,但它不是一个理想的解决方案,因为您最终必须为 pdf 创建一个全新的布局和复杂的逻辑。
如果我必须再次这样做,我会查看 http://code.google.com/p /wkhtmltopdf/ 强烈推荐。有一个 PHP 扩展... https://github.com/mreiferson/php-wkhtmltox
这是一篇评论...
http://ciaranmcnulty.com/blog/2009/04 /converting-html-to-pdf-using-wkhtmltopdf
请告诉我你的进展如何。
祝你好运 :)
I've ran in to this problem before, (column layout split over more than one page), and with DomPdf the easiest way to get column layouts is to use tables to set out the page, and to do some kind of calc on when to create new rows and columns. This did work for me, but it's not an ideal solution, as you end up having to create a whole new layout plus complicated logic for the pdf.
If I had to do this again, I'd look at http://code.google.com/p/wkhtmltopdf/ which is highly recommended. There's a PHP extension for it... https://github.com/mreiferson/php-wkhtmltox
Here's a review...
http://ciaranmcnulty.com/blog/2009/04/converting-html-to-pdf-using-wkhtmltopdf
Please let me know how you get on with this.
Good luck :)
您可以使用:
You can use:
如上所述,最简单的方法是拆分文本并将其放入表结构中。但要这样做并像普通 HTML 中的 css“column-count”属性一样填充它,一些事情可能会有所帮助,因为我发现做了同样的事情。这就是我最终的结果。
首先尝试找到仍然适合结构(即列数)的最长文本。计算字符数(即使用简单的文本编辑器 - 除了获取分割过程的数字外,它不会执行任何操作)。
这样你就可以编写你的代码了。
在分割文本之前,可以替换任何不需要的 html 标签(即双
等)。然后统计所有
并使用该数字,使用 strlen 进行计数,并为每个
减去 3 个字符。 (这对于只有一个可见字符但计数为 4 的
很有用)。
所有这些都用空格填充字符串,只要它不超过最大字符串长度即可。
最后一步:仅对文本进行自动换行并将其放入表列中。以下 3 列示例:
As mentioned above the easiest way is to split the text and put it into a tablestructure. But to do so and fill it up like the css "column-count" attribute would do in normal HTML, a few things might be helpful, as I found out doing the same thing. This is what I ended up.
First try to find the most longest text that still fits in the structure (i.e. column-count). Count the chars (i.e. with a simple texteditor - it won't do anything but to get a figure for the splitting procedure).
With that you can write your code.
Before splitting the text maybe replace any html tags not needed (i.e. double
or so). Then count all <br> and with that number, count with strlen and substract 3 chars for each <br> (this is useful for a <br> will be only one character visible but counting 4).
With all this fill up your string with white spaces as long as it does not exceed you max string length.
Last step: only wordwrapping your text and put it into your table cols.Example for 3 cols below: