作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道pdf页面添加内容后还剩下多少个空格。有什么方法可以让我跟踪那里有一些空间,以便我可以在一页中容纳 3 到 4 行,或者我可以创建一个新的文档页面来放置内容。
我想按以下方式进行 -
if( getRemainingSpace() < pageSize)
//Create new page
else
put contents in the same page
最佳答案
当您使用itext时标签(不是 itext7 ),我假设您使用的是 iText 5.5.x。
PdfWriter
类提供了一个返回当前垂直位置的方法:
/**
* Use this method to get the current vertical page position.
* @param ensureNewLine Tells whether a new line shall be enforced. This may cause side effects
* for elements that do not terminate the lines they've started because those lines will get
* terminated.
* @return The current vertical page position.
*/
public float getVerticalPosition(final boolean ensureNewLine)
因此,要检索当前页面上剩余主要内容空间的垂直范围,您只需检索此垂直位置值并减去底部页边距的 y 位置(您可以使用 文档
方法bottom()
)。
您获得的值采用默认用户空间单位(默认为 1/72 英寸)。
适合此空间的行数显然取决于您要在这些行上使用的字体和其他参数(字体大小、行距等)。
关于java - 如何在iText pdf中知道pdf的剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42173874/
我是一名优秀的程序员,十分优秀!