How to get Content height on the page?

Hello Aspose!

Could you please help me with finding out height of content on the page?
My task is add TextStamp on each stamp. In the same time stamp should not overlap content.

  1. First option to do it is calculate stamp size and shrink initial contents size via PdfFileEditor.resizeContents().
    User of my system can set text any length, any font and any font size. As consequence height of stamp could be any. So I have to calculate stamp height before rendering new PDF. How to do it I don’t know.

textStamp.getHeight() / textStamp.getTextState().getTextHeight() will return font size of one line, independent of stamp's width, independent of text legth.

  1. Second option is to restrict user to use only one line. But font size anyway can be any.
    So I have to get Content height to understand which top / bottom margins already exist on page and how many margin point I have to add.
    page.getPageInfo().getMargin().getTop() - doesn’t help because it says margin is 70 while in real life it is 0.
    Example of PDF in attachment.

Thank you in advance!

Best wishes,
Artem Fokin

SamplePDF.pdf (556.7 KB)

@artemrfokin

We tried to achieve the required values while using the below code snippet but did not get much success:

Document doc = new Document(dataDir + "SamplePDF.pdf");
Rectangle mediabox = doc.getPages().get_Item(1).getMediaBox();
Rectangle artbox = doc.getPages().get_Item(1).getArtBox();

System.out.println("Page 1 MediaBox, width/heigt=" + mediabox.getWidth() + "/" + mediabox.getHeight());
System.out.println("Page 1 ArtBox, width/heigt=" + artbox.getWidth() + "/" + artbox.getHeight());

mediabox = doc.getPages().get_Item(2).getMediaBox();
artbox = doc.getPages().get_Item(2).getArtBox();

System.out.println("Page 2 MediaBox, width/heigt=" + mediabox.getWidth() + "/" + mediabox.getHeight());
System.out.println("Page 2 ArtBox, width/heigt=" + artbox.getWidth() + "/" + artbox.getHeight());

We have logged an investigation ticket as PDFJAVA-40364 in our issue tracking system. We will further look into details of its and let you know once the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you for quick response.