Free Support Forum -

Extract text from the header- footer and body


We are using aspose-pdf-9.5.2.jar with the below code to extract the text of a pdf file:

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(this.path); com.aspose.pdf.TextAbsorber textAbsorber = new com.aspose.pdf.TextAbsorber();
String extractedText = textAbsorber.getText();

But i am not finding how i can extract the text from the header of the first page, the footer in the last page and the body of the file.
Can you advise please,

Hi Karine,

Thanks for using our API’s.

In order to get text from Footer/Header area of PDF file, please try using following code snippet.


pce = new


com.aspose.pdf.facades.StampInfo[] infos = pce.getStamps(1);

for(int counter =1; counter<=infos.length;counter++)

{ System.out.println(infos[counter].getText()); }

However if you you need to get text of header/footer added with Adobe Acrobat (not stamps added by Aspose software), you may consider using page.getArtifacts(); method to read header and footer artifacts on the page.


// bind source PDF file

com.aspose.pdf.Document doc = new com.aspose.pdf.Document("input.pdf");

// get artifacts collection of frist page

com.aspose.pdf.ArtifactCollection artifact = doc.getPages().get_Item(1).getArtifacts();

Iterator fi = artifact.iterator();



if (((com.aspose.pdf.Artifact) == Artifact.ArtifactSubtype.Header || ((com.aspose.pdf.Artifact) == Artifact.ArtifactSubtype.Footer)

// print text of artifact



Hi Karine,

In case you need to extract contents of PDF file without extracting contents of Header/Footer, please try using following code snippet.


//open document<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");

//create TextAbsorber object to extract text

com.aspose.pdf.TextAbsorber textAbsorber = new com.aspose.pdf.TextAbsorber();

textAbsorber.getTextSearchOptions().setRectangle(new com.aspose.pdf.Rectangle(


pdfDocument.getPages().get_Item(1).getRect().getLLY() + 20,


pdfDocument.getPages().get_Item(1).getRect().getURY() - 20));

//accept the absorber for all the pages


//get the extracted text

String extractedText = textAbsorber.getText();

//create a writer and open the file

BufferedWriter writer = new BufferedWriter(new FileWriter(new"c:/pdftest/ExtractedText.txt")));

//write extracted contents

writer.write (extractedText);

//Close writer


Hi Nayyer,
Thank you for your response,
Your code to extract contents of pdf file without extracting the contents of header/footer works well.
But i am still having problems for header/footer,
The issue is that the headers and footers of my file aren’t added with Adobe Acrobat neither by aspose software.
I need to extract for example in the attached pdf file
the header as: "Guide [TAG] Category management Administration Initialization"
the footer as :“© EVER TEAM 2013 – EverSuite 5.1 – Ref: ES510 TAG.V1 3”,
i tried to use also the method of rectangle and textabsorber, but i couldn’t find the correct X and Y to use.

I appreciate if you can help me,
Thank you,

Hi Karine,

Thanks for sharing the details.

have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34642. We will
investigate this issue in details and will keep you updated on the status of a
correction. <o:p></o:p>

We apologize for your inconvenience.

HI Nayyer,

Can you please let me know how to extract header and footer from pdf using c# ?
I am waiting for quick response.


HI All,

Do you anybody know , how to extract header and footer from pdf .



Thanks for contacting support.

Please note that header/footer contents cannot be extracted separately from a PDF document. Because, once you add header/footer during PDF generation and save the document, they become merged with other content of PDF document - and there are no separate header and footer. However, in reference to above logged ticket i.e. PDFJAVA-34642, further investigation is pending to be made. As soon as we have some news on investigation progress, we will let you know. Please spare us little time.

We are sorry for the inconvenience.

Thanks Asad for your information!!

Can we ignore header and footer while extract content from pdf?
At least deleted header and footer.

Here is the code I am using to extract data .

TextAbsorber textAbsorber = new TextAbsorber();

this is the code to extract data from pdf.


Thanks for your inquiry.

As shared earlier, once the text is extracted from PDF document, there is no differentiation between header/footer and main(body) content. However, as soon as we have some information in this regard, after investigation of earlier logged ticket, we will surely let you know. Please be patient and spare us little time.

We are sorry for the inconvenience.