0

I have a pdf template. My task is to populate its fields and append table to the current page or to the new page if it doesn't fit.

I know how to add content at absolute positions, but it would be nice if I can get this values from iText

What I need is something like that

PdfStamper stamper = new PdfStamper(pdfReader, fileStream);
PdfContentByte content = stamper.GetOverContent(1);
ColumnText colText= new ColumnText(stamper.GetOverContent(1));

colText.SetSimpleColumn(pageSize.Left, pageSize.Bottom,
         pageSize.Right, pageSize.Top - content.PdfWriter.GetVerticalPosition(false));

colText.AddElement(table);

The problem is content.PdfWriter.GetVerticalPosition always returns 806 in my case. So is there any way to get content position or canvas height or something like that? Any help will be appreciated

  • The `GetVerticalPosition()` method doesn't make any sense in the context of `PdfStamper`. You claim you have an existing PDF that contains fields. Why don't you ask those fields for their absolute position? As for the "new page if [the table] doesn't fit": you're creating that new page, so you know its dimensions, don't you? And if you know its dimensions, how come you don't know where to add the table? And didn't I explain all of this in my answer to [this question](https://stackoverflow.com/questions/26853894)? – Bruno Lowagie Jun 06 '18 at 13:28
  • Note: the duplicate question I refer to, can also be found on the official iText web site: [How to continue field output on a second page?](https://developers.itextpdf.com/question/how-continue-field-output-second-page) However, that was an answer to an old question involving iText 5. It seems that you're still using that version. In the new version iText 7 (first released two years ago; now at version 7.1.2), it's done [like this](https://developers.itextpdf.com/content/best-itext-questions-stackoverview/interactive-forms/itext7-how-continue-field-output-second-page). – Bruno Lowagie Jun 06 '18 at 13:31
  • Note that the version you are currently using, is no longer supported (unless you're a paying customer with a support contract). – Bruno Lowagie Jun 06 '18 at 13:31
  • @Bruno Lowagie, Thank you for your answer. Yes, I saw answer to the question you refering too, and it was very helpful so far. And I know I can get positions of fields, but what if the last element is `Paragraph` or `Chunk`? I guess I can wrap everything into field "body" and then get its position. But I just thought there is a way to get content height or position of the last element in content that could be absent in `AcroFields` – First Last Jun 06 '18 at 16:12

0 Answers0