gpt4 book ai didi

ruby - Prawn pdf和分页

转载 作者:数据小太阳 更新时间:2023-10-29 08:05:18 26 4
gpt4 key购买 nike

我正在尝试使用 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

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

最佳答案

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

边界框绑定(bind)到页边距:

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 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.

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

关于ruby - Prawn pdf和分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11194314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com