LayoutResult more one page in Itext7

て烟熏妆下的殇ゞ 提交于 2019-12-13 03:01:14

问题


i ask this: Remove the first and last lines properties in the paper Itext7

and if i do it:

 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 contain Paragraphs only from first page.And i don't know how many pages well be in pdf


回答1:


As I mentioned in the answer to your previous question,

split renderer represent the part of the content which iText can place on the area, overflow - the content which overflows.

So if you want to layout the rest of the content, you can perform the same operation (layout) on your overflowRenderer.

The code is as follows:

    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)));

Once the content has been fully placed, the overflowRenderer will be null.



来源:https://stackoverflow.com/questions/56365855/layoutresult-more-one-page-in-itext7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!