itext positioning text absolutely

Jack picture Jack · Oct 26, 2009 · Viewed 35.9k times · Source

In itext I have a chunk/phrase/paragraph (I dont mind which) and I want to position some where else on the page e.g. at 300 x 200. How would I do this?

Answer

Jack picture Jack · Oct 27, 2009

In the end I wrote my own method to do it.

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