【问题标题】:Prawn pdf and page breaks虾pdf和分页符
【发布时间】:2012-06-25 17:32:53
【问题描述】:

我正在尝试使用 Prawn 0.12.0 生成 pdf。

我正在呈现的内容非常动态,并且通常跨越多个页面。

我遇到的问题是,当它自动启动新页面时,当前边界框“中断”。 在新页面上呈现的文本没有正确的边界框。 如果我使用stroke_bounds,我可以看到页面最底部的底部笔划。 我已经在各种论坛上阅读过这个问题,但似乎无法弄清楚实际发生了什么。

下面是循环出内容的具体代码:

items.each do |item|
  group do
    title_text = [{ text: item.title, styles: [@heading_style], size: 11}]
    formatted_text title_text
    text(item.description, size: 9)
    stroke { line(bounds.bottom_left, bounds.bottom_right); }
  end
end

如您所见,我想在每个项目的下方画一条线,这就是为什么我需要正确的当前边界框。

【问题讨论】:

  • 遇到同样的问题。你能找到什么吗?
  • 致任何发现此内容并注意到代码中 group 方法的人:NotImplementedError: Document#group has been disabled because its implementation lead to corrupted documents whenever a page boundary was crossed. We will try to work on reimplementing it in a future release

标签: ruby pdf-generation prawn


【解决方案1】:

根据大虾文档: http://prawnpdf.org/manual.pdf

边界框绑定到页边距:

A bounding box is a structure which provides boundaries for inserting content. A bounding box
also has the property of relocating the origin to its relative bottom-left corner. However, be aware
that the location specified when creating a bounding box is its top-left corner, not bottom-left
(hence the [100, 300] coordinates below).

span 对于可以优雅地跨页流动的边界类型是更好的选择:

Span is a different kind of bounding box as it lets the text flow
gracefully onto the next page. It doesn't matter if the text started
on the middle of the previous page, when it flows to the next page
it will start at the beginning. 

跨度应该能够包含所需的线条笔划。 希望这可以帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    相关资源
    最近更新 更多