How can we open an existing PDF and add a footer to it

Question is in the title but how can we open an EXISTING document and add a footer (or other content to it).

We have bot Aspose.Pdf as well as Pdf.Kit if it matters.

How can we open an EXISTING pdf and add a footer to EACH and EVERY page.

Hi,

You can use Aspose.Pdf.Kit to open an existing PDF file and then add text or footer in a single or all pages. You can use AddText method of the PdfFileMend class to add text at a particular location in a PDF file. In order to add header or footer in a PDF file you can use AddHeader or AddFooter methods of the PdfFileStamp class respectively.

I hope this helps. If you have any further questions, please do let us know.
Regards,



Thank you for your help! That is what I was looking for.

Two other questions:
1) Will the PdfFileStamp (addFooter and addPageNumber) shrink the document to add the footer automatically or is it just putting the footer on top of the PDF content?

2) How can we include page numbers like “Page 1 of 7” into a footer. addPageNumber allows us to add page numbers but not into a footer and it does not give us the total number of pages.

Thank you!

Hi,

Please find the answers below:

eeehee:

1) Will the PdfFileStamp (addFooter and addPageNumber) shrink the document to add the footer automatically or is it just putting the footer on top of the PDF content?


PdfFileStamp doesn’t shrink the document, rather adds the footer on top of the contents. However, you can specify the margins while adding the footer.

eeehee:

2) How can we include page numbers like “Page 1 of 7” into a footer. addPageNumber allows us to add page numbers but not into a footer and it does not give us the total number of pages.


Please see the following code snippet to add footer as per your requirement:


//get total number of pages

Aspose.Pdf.Kit.PdfFileInfo pdfFileInfo = new Aspose.Pdf.Kit.PdfFileInfo(“test.pdf”, “”);

int totalPages = pdfFileInfo.NumberofPages;


//add page number to the PDF file

Aspose.Pdf.Kit.PdfFileStamp pdfFileStamp = new Aspose.Pdf.Kit.PdfFileStamp(“test.pdf”, “output2.pdf”);

pdfFileStamp.AddPageNumber("Page # of " + totalPages.ToString());

pdfFileStamp.Close();


I hope this helps. If you have any further questions, please do let us know.
Regards,





Thanks for sticking with me, you’ve been very helpful.

I do see the overloaded method that allows me to set the margins but what am I actually setting? If I set the margins will it shrink the document to within those margins before adding the footer?

In other words, how can I ensure that I don’t place footer text on top of content?

Hi,

I would like to share with you that the margins in the AddFooter method only allows you to add left, bottom or right margins for the text being added in the footer i.e. placing the footer 10 points above the bottom. These margins do not shrink the existing contents of the PDF file.

I’m afraid, there is no way to find out if there is already some content on the location where you’re going to add the footer.

We’re sorry for the inconvenience. If you have any further questions, please do let us know.
Regards,