【问题标题】:DomPDF: Footer extends beyond the pdf when using a long textDomPDF:使用长文本时,页脚超出 pdf
【发布时间】:2014-09-16 11:37:40
【问题描述】:

使用以下代码时,我的页脚超出了页面(并且不可见):

  $footer = $pdf->open_object();

  $w = $pdf->get_width();
  $h = $pdf->get_height();
  $size = 10;

  $color = array(.24,.65,.04);
  $font = Font_Metrics::get_font("verdana", "bold");
  $text_height = Font_Metrics::get_font_height($font, $size);


  $text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";

  $width = Font_Metrics::get_text_width($text, $font, $size);
  $pdf->page_text (16 , $y-15, $text, $font, $size, $color);

这样,肯定会添加页脚,但只有部分文本可见。有什么想法吗?

【问题讨论】:

  • 如果您使用的是 v0.6(并且应该是),并且您不需要让页面总数尝试使用 CSS。当您直接使用渲染库编写页脚脚本时,您必须自己处理布局。
  • 本题讨论了两种创建页眉/页脚的方法:stackoverflow.com/q/7484318/264628
  • @BrianS 嗨,Brian,感谢您的信息,并为我迟到的回复道歉。我也用过0.6。我之前的消息中已经提到了内联脚本的问题。现在,"position:fixed" CSS 的问题在于,如果页面内容变得足够长到底部,页脚会与它重叠,并隐藏内容。再次不是解决方案。因此,我不得不求助于使用页脚作为所有其他 div。
  • 现在,页脚不会出现在页面底部,正如我所希望的那样。相反,它出现在内容结束的下方。有时在页面底部,有时在页面中间,有时在新页面的顶部。不是很优雅,但仍然比重叠文本好。
  • 使用固定位置的内容时,您可以通过设置页边距然后使用负值将页眉/页脚定位在页边距之外来避免内容重叠。再次查看 CSS 示例。如果您决定使用 CSS 并且仍然遇到问题,请使用代码示例开始一个新问题。

标签: footer dompdf


【解决方案1】:

dompdf 执行布局,然后使用渲染库生成 PDF。渲染库不了解 dompdf,因此无法使用其布局引擎。也就是说,当您直接使用 PDF 渲染库编写页眉/页脚时,您必须自己处理布局。

如果您希望 dompdf 执行布局,请使用 CSS 作为页眉/页脚。这个问题的答案概述了创建页眉/页脚的两种方法:stackoverflow.com/q/7484318/264628。

【讨论】:

    猜你喜欢
    • 2015-06-24
    • 2023-03-10
    • 2011-01-13
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多