How to add multiline footer when creating a PDF document using Aspose.PDF for .net api

Hi,

I am creating PDF from html. I need to add multi line footer to the document. I am using TextStamp to add footer. I can add single line footer to every page. However, I am not sure how add multi-line footer. I also need to add page number in the lower right bottom. Something like the following:

Line 1
Line 2 bold text some more text Page 1 of 5

@sohelm

You can add multiline text stamps using FormattedText as below:

Aspose.Pdf.Facades.FormattedText formattedText = new Aspose.Pdf.Facades.FormattedText("One line");
formattedText.AddNewLineText("Second Line");
Aspose.Pdf.TextStamp stamp = new Aspose.Pdf.TextStamp(formattedText);

Furthermore, the page numbers can be added at the bottom using TextStamp as well. You can specify the horizontal and vertical alignment as per your needs to position the stamp.

Thank you Asad!
One more question. How do I have part of the text bolded? for example: “Second Line myboldText” , where myboldText is rendered bold.

Thanks for your help!

@sohelm

We need to investigate this requirement. Can you please share a sample source and expected output PDF document with us so that we can further proceed to assist you accordingly.

Please see the uploaded pdf and the footer for a sample

sample.pdf (135.0 KB)

@sohelm

As per our understandings, there are more than one stamp added in the footer of the document that you have shared. You can please try adding multiple stamps in the footer of the document by specifying their VerticalAlignment and XIndent to position them as per your desire. The TextState property of the TextStamp Class can be used to set font style e.g. bold, italic. Please feel free to let us know in case you need more information.

Thanks Asad. I guess if I understand it correctly, you want me to use TextStamp as opposed to FormattedText to create footer which may include multiple lines and some formatted text,correct?

Would it be possible to provide some sample code? I tried to create multiple TextStamp and add to the bottom of each page before and I was having issues where they would overlap. I am sure I was not setting the vertical and horizontal alignments correctly and I am sure I was not using the XIndent at the time. A sample code to create a footer similar to the attached pdf would be really helpful. Thank you so much for your support.

@sohelm

In your shared PDF document, there are three stamps. The middle one stamp is in bold font. We tried to create a similar footer using the below code snippet in which we specified XIndent for two stamps. Please check it and let us know in case you have more requirements:

Document doc = new Document();
Page page = doc.Pages.Add();
            
Facades.FormattedText stamptext = new Facades.FormattedText("Aspose");
stamptext.AddNewLineText("Pty");
stamptext.AddNewLineText("Ltd");
            
TextStamp topleftstamp = new TextStamp(stamptext);

TextStamp bottomleft = new TextStamp(stamptext);
bottomleft.XIndent = 72;
bottomleft.VerticalAlignment = VerticalAlignment.Bottom;

TextStamp bottomcenter = new TextStamp(stamptext);
bottomcenter.TextState.FontStyle = FontStyles.Bold;
bottomcenter.XIndent = 150;
bottomcenter.VerticalAlignment = VerticalAlignment.Bottom;

TextStamp bottomright = new TextStamp(stamptext);
bottomright.HorizontalAlignment = HorizontalAlignment.Right;
bottomright.VerticalAlignment = VerticalAlignment.Bottom;

page.AddStamp(bottomcenter);
page.AddStamp(bottomleft);
page.AddStamp(bottomright);

doc.Save(dataDir + "stamps.pdf");

stamps.pdf (4.1 KB)