1

有没有办法绝对定位段落,当列表添加到段落时也可以工作?

谷歌搜索显示我应该使用 ColumnText,但如果段落中有列表,我将无法使用它。它只是在同一条线上显示彼此相邻的列表项。这是我的测试程序:

        PdfWriter writer=PdfWriter.getInstance(document,new FileOutputStream("/tmp/output.pdf"));
        document.open();
        ColumnText ct = new ColumnText(writer.getDirectContent());
        ct.setSimpleColumn(0,0,300,300);
        Paragraph p=new Paragraph();
        List list=new List();
        list.add(new ListItem("First item"));
        list.add(new ListItem("second item"));
        list.add(new ListItem("third item"));
        p.add(list);
        ct.addElement(p);
        ct.go();
        document.close();
        writer.close();
4

3 回答 3

1

I looked in the changelogs of iText and I discovered that this was fixed in iText 5.2.1, released on March 31st, 2012. That's over a year ago. Please upgrade to the latest version and the problem will disappear.

Note that all 5.2.x versions were removed from SourceForge because they contained a bug that occasionally produced PDFs that weren't compliant with ISO-32000-1. Based on the description of your problem, I know that you're using a version of iText that is even older than the 5.2.x series, so you definitely need to upgrade.

于 2013-04-13T14:17:20.737 回答
1

在 PDF 文件中组织您的内容的另一种方法是您可以使用 PdfPTable 。首先使用循环指令将列表内容写入表中,然后在输出 pdf 文件中定义该 PdfPTable 的位置。

于 2014-09-27T18:19:12.830 回答
-1

您可以使用此功能:

private void PlaceChunck(String text, int x, int y) {
    PdfContentByte cb = writer.DirectContent;
    BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb.SaveState();
    cb.BeginText();
    cb.MoveText(x, y);
    cb.SetFontAndSize(bf, 12);
    cb.ShowText(text);
    cb.EndText();
    cb.RestoreState();
}

另见:itext 绝对定位文本

于 2016-03-31T11:25:25.763 回答