简体   繁体   English

画布错误地在表itext7中绘制了高度单元

[英]canvas incorrectly draws heights cell in table itext7

i draw table as it: Draw custom borders for table with more flexibility in itext7 照原样绘制表格: 在itext7中为表格绘制自定义边框,具有更大的灵活性

But i But with big data the table is badly drawn height cell in table. 但是我但是有了大数据,表格就很难在表格中绘制高度单元。

 PdfDocument pdfDoc = new PdfDocument(new PdfWriter("_testPd/dashed_underline.pdf"));
        Document doc = new Document(pdfDoc, PageSize.A5);

        Table table = new Table(3).useAllAvailableWidth().setFixedLayout();
        table.addCell("Highway System that runs east from the Indiana state line near Lake Michigan through the southern Lower Peninsula to Detroit, then n");
        table.addCell("Highway System that runs east from the Indiana state line near Lake Michigan through the southern Lower Peninsula to Detroit, then n");
        table.addCell("Highway System that runs east from the Indiana state line near Lake Michigan through the southern Lower Peninsula to Detroit, then n");

        table.addCell("Pell morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus");



        table.setNextRenderer(new CustomTableRenderer(table));


        doc.add(table);

        doc.close();

在此处输入图片说明

also one example: 还有一个例子:

  Table table = new Table(3);
    table.addCell("hello1 ");
    table.addCell("hello2 ");
    table.addCell("hello3 ");
    table.addCell("hello4\nWord ");
    table.addCell("hello5 ");

在此处输入图片说明

There is a minor mistake in your custom renderer: the items of heights list represent rows from the highest to the lowest, but you're drawing the borders from the lowest to the highest. 自定义渲染器中存在一个小错误: 高度列表项代表从最高到最低的行,但是您正在绘制从最低到最高的边框。

The following code should be used to draw horizontal lines: 以下代码应用于绘制水平线:

        // Draw horizontal lines
        float curY = getOccupiedAreaBBox().getTop();
        for (int i = 0; i <= heights.size(); i++) {
            canvas.moveTo(getOccupiedAreaBBox().getLeft() - 3, curY);
            canvas.lineTo(getOccupiedAreaBBox().getRight() + 3, curY + r.nextInt(4));
            if (i < heights.size()) {
                float curHeight = heights.get(i);
                curY -= curHeight;
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM