холст неправильно рисует высоту ячейки в таблице itext7 - PullRequest
0 голосов
/ 14 мая 2019

я рисую таблицу так: Рисую пользовательские границы для таблицы с большей гибкостью в 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();

enter image description here

также один пример:

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

enter image description here

1 Ответ

1 голос
/ 14 мая 2019

В пользовательском рендерере есть небольшая ошибка: элементы списка heights представляют строки от самого высокого до самого низкого, но вы рисуете границы от самого низкого до самого высокого.

Следующий код должен использоваться для рисования горизонтальных линий:

        // 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;
            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...