We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add Text in Header Footer of the PDF Page in C#

Hello,

i have a problem creating a PDF page using tables (or another solution).

I need a Title (dynamic text length) at the Top, a thin line afterwards and a gray box with 3 text lines at the bottom of the page. Therefor i try HeaderFooter, but the height is limited, so i can not use this. Now i us a table with 2 rows. The first row has a border at the bottom. This works nice for me.

My problem is, that i am not able to place the gray box at the bottom of the page.
I cannot set a fixed height of the second row, because the content of the first row is not fixed.

How can i solve it?

Kind regards,
Andy

@AStelzner

Can you please share your sample PDF documents (input/output) along with the sample code snippet that you are using to add header footer? We will test the scenario in our environment and address it accordingly.

See Example (not the HeaderFooter solution, but the best solution for me).
Consider comments in lines 22, 42, 49 and 53.

My approach is, 3 Rows. The middle one is a placeholder row, whose height is calculated from the first (variable height) and the last (fixed size) to make sure that the box at the bottom is always at the bottom.

PdfCreateExample.zip (4.2 KB)

Kind Regards,
Andy

@AStelzner

We tested the scenario in our environment and produced a PDF. We could not understand what did you actually mean by the gray box at the bottom. There was already a table row filled with gray color at the bottom. Do you want to add another gray box inside it? Can you please share an expected output PDF for our reference so that we can better understand the requirements?

Also, please try to use the method Table.GetHeight(); in order to get height of complete table after adding rows. This may help you to calculate the area as per your requirements.

Yes, there is a box at the bottom but if the text in the first row contains 200 characters the box is at the second page. The calculation of the placeholder row fails becaus the height of the title row cannot be obtained to calculate the placeholder height! Currently i use the height of the Text Fragement, but their height is ALWAYS 22 (font size).

@AStelzner

Please check the below code snippet where we tried another approach by using FloatingBox in order to tackle the dynamic length of title text. The calculations for the bottom table can also be performed easily. For your kind reference, an output PDF is also attached:

using (var doc = new Document())
{
 var page = doc.Pages.Add();
 page.SetPageSize(597.6, 842.4);

 var table = CreateAndGetTable();
 var titleRow = CreateAndGetTitleRow(table);
 FloatingBox header = new FloatingBox();
 header.Top = 0;
 header.Left = 0;
 //header.Border = new BorderInfo(BorderSide.All, 2f);
 header.Margin = new MarginInfo(0, 0, 0, 0);

 header.Paragraphs.Add(table);

 var footerTable = CreateAndGetTable();
 var creationInfoRow = CreateAndGetCreationInfoRow(footerTable);

 FloatingBox footer = new FloatingBox();
 footer.Top = page.GetPageRect(true).Height - footerTable.GetHeight() - page.PageInfo.Margin.Top - page.PageInfo.Margin.Bottom;
 footer.Left = 0;
 //footer.Border = new BorderInfo(BorderSide.All, 2f);
 footer.Margin = new MarginInfo(0, 0, 0, 0);

 footer.Paragraphs.Add(footerTable);

 page.Paragraphs.Add(header);
 page.Paragraphs.Add(footer);
 //CreateCoverSheetPage(doc, page);

 doc.Save(".\\PdfOut.pdf");
}

PdfOut.pdf (37.0 KB)