簡體   English   中英

畫布錯誤地在表itext7中繪制了高度單元

[英]canvas incorrectly draws heights cell in table itext7

照原樣繪制表格: 在itext7中為表格繪制自定義邊框,具有更大的靈活性

但是我但是有了大數據,表格就很難在表格中繪制高度單元。

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

在此處輸入圖片說明

還有一個例子:

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

在此處輸入圖片說明

自定義渲染器中存在一個小錯誤: 高度列表項代表從最高到最低的行,但是您正在繪制從最低到最高的邊框。

以下代碼應用於繪制水平線:

        // 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