Why delete header/footer fail?

Hi,Support:

I use the follow code to delete header/footer,but fail.

        Dim Pdf As New Aspose.Pdf.Document(PdfFile)
        DimTA As New TextFragmentAbsorber()
        Dim Pages As integer=Pdf.pages.count
     Dim Rect As   Aspose.Pdf.Rectangle
     For p as integer=1 to Pages
        Rect= New Aspose.Pdf.Rectangle(0, 0, Pdf.Pages(p).PageInfo.Width, Pdf.Pages(p).PageInfo.Height * 0.15)
        TA.TextSearchOptions = New TextSearchOptions(Rect)
        TA.Visit(Pdf.Pages(p))
         For Each TF As TextFragment In Ta.TextFragments
             If Not (TF.Text.Trim = "" Or IsNumeric(TF.Text.Trim)) Then
                Dim Text As String = TF.Text.Trim
                If (Text.StartsWith("-") Or Text.StartsWith("—")) Then Text = Mid(Text, 2)
                If (Text.EndsWith("-") Or Text.EndsWith("—")) Then Text= Text.Substring(0, Text.Length - 1)
                If Not IsNumeric(Text) Then TfText = ""    'Here is to delete the footers and except for the page number
            End If
         Next
        Rect =New Aspose.Pdf.Rectangle(0,Pdf.Pages(p).PageInfo.Height * 0.85, Pdf.Pages(p).PageInfo.Width, Pdf.Pages(p).PageInfo.Height * 0.15)
        TA.TextSearchOptions = New TextSearchOptions(Rect)
        TA.Visit(Pdf.Pages(p))
         For Each TF As TextFragment In Ta.TextFragments
             If Not (TF.Text.Trim = "" Or IsNumeric(TF.Text.Trim)) Then
                Dim Text As String = TF.Text.Trim
                If (Text.StartsWith("-") Or Text.StartsWith("—")) Then Text = Mid(Text, 2)
                If (Text.EndsWith("-") Or Text.EndsWith("—")) Then Text= Text.Substring(0, Text.Length - 1)
                If Not IsNumeric(Text) Then TfText = ""    'Here is to delete the headers and except for the page number
            End If
         Next

next
Pdf.Save(PdfFile)


This method can only delete footers at Left-Bottom,Mid-Bottom, whereas the footer at Right-Bottom and all headers fail to be deleted.
How delete header/footer sucessfully?

Thanks for your help!

Input.pdf (63.9 KB)

OutInput.pdf (62.8 KB)

@ducaisoft

You are trying to remove the header/footer on the basis of found text fragments. It may not work with all PDF documents. Please try to use another approach i.e. remove header/footer by adjust crop box and media box because they usually are present in them.

Dim PdfFile As String = "your_input.pdf" ' Replace with your PDF file path
Dim pdfDocument As New Aspose.Pdf.Document(PdfFile)

For Each page As Page In pdfDocument.Pages
    Dim mediaBox As Aspose.Pdf.Rectangle = page.PageInfo.MediaBox
    Dim cropBox As Aspose.Pdf.Rectangle = page.PageInfo.CropBox.Clone()
    cropBox.LLY = 0 ' Adjust the bottom of the CropBox to remove the footer
    cropBox.URX = page.PageInfo.Width ' Adjust the right side of the CropBox
    page.PageInfo.CropBox = cropBox
    page.PageInfo.MediaBox = mediaBox ' Reset the MediaBox to the original size
Next

pdfDocument.Save("output.pdf")

Yes, It is a good idea for this .
However, there is still a problem that the cropped pagesize can not be resset to its orignal size by using Pdf.Pages(1).MediaBox = mediaBox or Pdf.Pages(1).SetPageSize(mediaBox.Width, mediaBox.Height), Please investigate and fix it.
And if this problem could not be fixed, an anternative method is to draw a white rectangle to overlay the header or footer area for this purpose. How to draw this white rectangle?

I use the following code to draw two rectangle to overlay the header and footer,but it throws an exception saying “illegal character in file path”,what’s wrong? there is actually no illegal character in path. (VB.net ,Pdf.dll v23.5)

        Dim Pdf As New Aspose.Pdf.Document("C:\Users\Administrator\Desktop\Input.pdf")
        Dim canvas = New Drawing.Graph(Pdf.Pages(1).PageInfo.Width, 80)
        Pdf.Pages(1).Paragraphs.Add(canvas)
        Dim rect As Aspose.Pdf.Drawing.Rectangle = New Aspose.Pdf.Drawing.Rectangle(0, 0, Pdf.Pages(1).PageInfo.Width, 80)
        Dim c = ColorTranslator.FromHtml("#FFFFFF")
        rect.GraphInfo.Color = Aspose.Pdf.Color.White
        canvas.Shapes.Add(rect)
        rect = New Aspose.Pdf.Drawing.Rectangle(0, Pdf.Pages(1).PageInfo.Height - 80, Pdf.Pages(1).PageInfo.Width, Pdf.Pages(1).PageInfo.Height)
        rect.GraphInfo.Color = Aspose.Pdf.Color.White
        canvas.Shapes.Add(rect)
        Pdf.Save("C:\Users\Administrator\Desktop\Out.pdf")  'this code throws an exception saying "illegal path"

@ducaisoft

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-55798

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.