1

Is there a way to position a paragraph absolutely, in a way that also works when a list is added to the paragraph?

A google search shows that I should use ColumnText, but I can't get that to work if there is a list in the paragraph. It simply shows the list items next to each other on the same linie. Here is my test program:

        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();
MTilsted
  • 5,425
  • 9
  • 44
  • 76

3 Answers3

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.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Sorry, I can't. We currently don't have the 1.615€ needed for a server license -( – MTilsted Apr 13 '13 at 14:27
  • Will you be profitable in the future? If so, mail sales at iText and ask for Garry. Refer to this post and he can make you a start-up deal. – Bruno Lowagie Apr 13 '13 at 14:31
1

A different way to organize you content in PDF file is that you can use PdfPTable . first write list content into the table using loop instruction and then define the position of that PdfPTable in your output pdf file.

kavi temre
  • 1,321
  • 2
  • 14
  • 21
-1

You can use this function:

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

see also: itext positioning text absolutely;

Community
  • 1
  • 1