-
I need to add Headers and footers on a output PDF file. If the input PDF file containing existing headers and footers i need to remove them first and add the new headers and footers on the output pdf file in aspose pdf using .net (c#).
-
How i can identiy if the PDF is having existing headers and footers ?
could you let me know if there is any solution related to this in Aspose PDF.
@Sandhya_Rani
Please note that there is no separate definition for Header/Footer in an existing PDF. Header/Footer can only be defined at the time PDF generation. Once a PDF is generated, Header/Footer would become part of its rest of the content.
Furthermore, if Header/Footer are added using Stamp, then you can find stamps and remove it and then add new Header/Footer.
You can use the PdfFileStamp class from Aspose.PDF for .NET library. This class allows you to add, remove or modify headers and footers in a PDF file. You can use the GetHeader and GetFooter methods of this class to get the existing header and footer objects from a PDF page. You can then check if they are null or not. Here is an example of how to do that:
// Create PdfFileStamp object
PdfFileStamp fileStamp = new PdfFileStamp();
// Open Document
fileStamp.BindPdf(_dataDir + "sample.pdf");
// Get the first page
Page page = fileStamp.Document.Pages[1];
// Get the header and footer objects
Stamp header = fileStamp.GetHeader(page);
Stamp footer = fileStamp.GetFooter(page);
// Check if they are null or not
if (header == null)
{
Console.WriteLine("No header found on page 1");
}
else
{
Console.WriteLine("Header found on page 1");
}
if (footer == null)
{
Console.WriteLine("No footer found on page 1");
}
else
{
Console.WriteLine("Footer found on page 1");
}
// Close fileStamp
fileStamp.Close();
@asad.ali
Thanks for the response. If the header and footer are not been added by stamps ? what is the other recommended approach to apply header and footer on the output PDF file ?
@Sandhya_Rani
We are afraid that there may not be other solution except search text and replace it. You may not be able to search and replace the header/footer dynamically.
@asad.ali
Thanks for the quick response.