Adding content at bottom of page

Hello,

is there a way to add content from the bottom of a page?
We generate a document with dynamic length and need to add a text on the last page at the bottom. (directly above the footer) We can not use Endnote, because the text is than written under the footer which is not what we want.
Is there a way we can achieve that, especially how can we add at bottom of page when we do not know how the last page looks like?
Thank you

@schiepe

Thank you for contacting support.

We would like to update you that Aspose.PDF API considers bottom left corner as the origin (0,0) so in case of adding text at the bottom you do not need page dimensions although they can be retrieved, if needed. So you may add text at specific location using below code snippet or Add Text Stamp in a PDF file as per your requirements.

Document document = new Document();
Page page = document.getPages().add();

TextFragment textFragment = new TextFragment();
textFragment.setText("Aspose");

textFragment.getPosition().setXIndent(300);
textFragment.getPosition().setYIndent(700);

//create TextParagraph object
TextParagraph par = new TextParagraph();


//set paragraph position
par.setPosition(new Position(textFragment.getPosition().getXIndent(), textFragment.getPosition().getYIndent()));

//add new TextFragment to paragraph
par.appendLine(textFragment);

//add the TextParagraph using TextBuilder
TextBuilder textBuilder = new TextBuilder(page);
textBuilder.appendParagraph(par);
document.save(dataDir + "Test_19.2.pdf");

We hope this will be helpful. please feel free to contact us if you need any further assistance.

Hello and thanks.
I am not sure if that is what we need.
Because if the page is full, the text we want to have at the bottom would now overlap with the existing content.

The correct behaviour would be that a page break is generated and the content would be written at the bottom of the new page.

Or is there a way to check how much space is left at the bottom of the page and when there is not enough space, a page break is generated manually?

@schiepe

Thank you for elaborating it further.

We are afraid page break may not be controlled based on some conditions. However, you may resize page contents from bottom so that empty space be ensured and then text can be added as per your requirements.

Below code snippet resizes page contents from the bottom by twenty pixels, to avoid overlapping of contents:

Document document = new Document(dataDir + "Sample.pdf");
PdfFileEditor fileEditor = new PdfFileEditor();
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(PdfFileEditor.ContentsResizeValue.units(0), null, PdfFileEditor.ContentsResizeValue.units(0), PdfFileEditor.ContentsResizeValue.units(0), null, PdfFileEditor.ContentsResizeValue.units(20));
fileEditor.resizeContents(document, parameters);
document.save(dataDir + "Resized_19.3.pdf");

Moreover, you may also visit Resize Page Contents for your kind reference.

Hello,

resizing content is not an option for our customer.

  1. Is there a way to calculate remaining space of current page? or
  2. Is there a way to extend the last row of a table to the page end like here:
    extendLastRow.jpg (35.1 KB)
    The content could than be written at the bottom of this last row.?

Thank you

@schiepe

We are afraid that either of the approaches may not be devised because a page may contain different contents including text, images, annotations etc. Consequently, it will be difficult to specify how much the last row should be extended so that table may not overflow and added to next page while changing the structure of whole document. Therefore, it may not be possible to achieve these requirements unless resized.

For someone facing the same problem here was my solution:
I solved the problem by enhancing the size of the footer and on the last page, i add the text in the extra footer space with your code above so it is ensured the text does not overlap. Unfortunately the extra space is reserved on every page, not only the last.

@schiepe

Thank you for sharing your findings, these will definitely be helpful for others. Moreover, if you do not want to resize whole document then you may pass an array of specific page numbers which you want to resize. Shared documentation article also elaborates such a scenario. Overloads.PNG