LayoutResult在Itext7中多一页 [英] LayoutResult more one page in Itext7
问题描述
我问这个问题:删除Itext7文件中的第一行和最后一行属性
如果我这样做:
PdfWriter pdfWriter = new PdfWriter(dest);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
Div div = new Div();
Document doc = new Document(pdfDoc, PageSize.A5);
doc.setMargins(0,0,0,36);
for (int i = 0; i <50 ; i++) {
ListItem listItem = new ListItem();
String s= "hello "+i;
Paragraph p = new Paragraph();
for (int j = 0; j <s.length() ; j++) {
p.add("HELLO " +I);
}
LayoutResult result = div.createRendererSubTree().setParent(doc.getRenderer()).layout(new LayoutContext(new LayoutArea(0,PageSize.A5)));
List<IRenderer> childRendererParagraph = result.getSplitRenderer().getChildRenderers();
childRendererParagraph仅包含首页中的段落.而且我不知道pdf中有多少页
childRendererParagraph contain Paragraphs only from first page.And i don't know how many pages well be in pdf
推荐答案
我在上一个问题的答案中提到
As I mentioned in the answer to your previous question,
拆分渲染器代表iText可以放置在区域上的部分内容,即溢出的内容.
split renderer represent the part of the content which iText can place on the area, overflow - the content which overflows.
因此,如果要布局其余内容,可以在overflowRenderer
上执行相同的操作(layout
).
So if you want to layout the rest of the content, you can perform the same operation (layout
) on your overflowRenderer
.
代码如下:
LayoutResult firstPageResult = div.createRendererSubTree().setParent(doc.getRenderer()).layout(new LayoutContext(new LayoutArea(0, PageSize.A5)));
LayoutResult secondPageResult = firstPageResult.getOverflowRenderer().layout(new LayoutContext(new LayoutArea(1, PageSize.A5)));
内容完全放置后,overflowRenderer将为空.
Once the content has been fully placed, the overflowRenderer will be null.
这篇关于LayoutResult在Itext7中多一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!