LayoutResult在Itext7中多一页 [英] LayoutResult more one page in Itext7

查看:182
本文介绍了LayoutResult在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆