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

Free Support Forum - aspose.com

Convert to pdf - Not able to clear header and footer

Hi there
In the aspose pdf, we did not find an option to clear the header from an existing PDF file.

The code which we have tried is.

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(filePath);
if (documentDetailDto.AddHeaderFooter)
{
RemoveHeader(doc);
RemoveFooter(doc);
SetDynamicHeaderForPdf(doc, headers, filePath);
SetDynamicFooterForPdf(doc, footers, filePath);
doc.Save(filePath);
}
Please find attached the sample application

Thanks & Regards
Jegadeesh S
For Melbourne Health

Please find the attachment of sample application

@mhorg

Thanks for contacting support.

We were unable to find any attachment with your post(s). Would you please share sample application with us, so that we can look into the scenario.

Furthermore, please note that there are no separate header/footer in a PDF document after a PDF document is saved. Header and Footer are used while PDF Generation and once PDF is saved, they become part of PDF document just like other content in it. You cannot extract header/footer from an existing PDF document.

We suggest you to please find and remove the text from particular region of a PDF document and add new content there to achieve what you require. You may please try the suggested approach and in case you face any issue, please share your feedback with us.

PDFCreator.zip (163.3 KB)

@mhorg

We have checked the shared sample project and found the input PDF document missing. Also, there was an image being used in the code snippet which is not present in the solution directory. Would you please share the source files with us, so that we can test the scenario in our environment and address it accordingly.

Hi there
Please find attached updated application for your reference
https://drive.google.com/uc?id=1lqR32S2GzLHYhncouzQs2Q50a2cbBdFn&export=download
Regards
Jegadeesh S

@mhorg

Thanks for sharing the sample project again.

We were able to test the sample project and noticed that you were using redaction feature of the API, in order to remove header and footer from existing PDF. Would you please share what sort of issues you are facing while implementing this functionality and what type of output PDF do you expect?

When we are using a PDF file which already have a header and footer, we need to remove the content from the header and footer. We are using the following code snippet for this, which is not removing either header or footer.

Code to remove header/footer:

Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(0, page.Rect.Height * 0.95, page.Rect.Width, page.Rect.Height);
RedactionAnnotation annot = new RedactionAnnotation(page, rect);
annot.FillColor = Aspose.Pdf.Color.White;
annot.BorderColor = Aspose.Pdf.Color.Yellow;
annot.Color = Aspose.Pdf.Color.Blue;
annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
page.Annotations.Add(annot);
annot.Redact();
TextAbsorber textAbsorber = new TextAbsorber();
pdfDoc.Pages[i].Accept(textAbsorber);

@mhorg

We have tested the scenario using your following code snippet with Aspose.PDF for .NET 18.8 and noticed that header/footer were removed from our sample PDF document.

Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(0, page.Rect.Height * 0.95, page.Rect.Width, page.Rect.Height);
RedactionAnnotation annot = new RedactionAnnotation(page, rect);
annot.FillColor = Aspose.Pdf.Color.White;
annot.BorderColor = Aspose.Pdf.Color.Yellow;
annot.Color = Aspose.Pdf.Color.Blue;
annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
page.Annotations.Add(annot);
annot.Redact(); 

Would you please try latest version of the API on your side and in case you still face any issue, please feel free to let us know.

Hi there
Thank you for the response.
We have valid license only until 17.6.
Can check and keep you updated about the outcome
Regards
Jegadeesh S

@mhorg

Please take your time while checking with latest version. In case of any issue, please let us know.