Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read text from a particular page using PDFBox [duplicate]

Tags:

java

pdfbox

I know how to read text of an entire pdf file usinf PDFBox using PDFTextStripper.getText(PDDocument).

I also have a sample on how to get an object reference to a particular page using PDDocumentCatalog.getAllPages().get(i).

How do I get the text of just one page using PDFBox as I dont see any such method on PDPage class?

like image 281
Shyam Sundar Ananthaswamy Avatar asked Nov 26 '12 11:11

Shyam Sundar Ananthaswamy


1 Answers

You can set parameters on the PDFTextStripper to read particular pages:

PDDocument doc; // document
int i; // page no.

PDFTextStripper reader = new PDFTextStripper();
reader.setStartPage(i);
reader.setEndPage(i);
String pageText = reader.getText(doc);

As far as I'm aware, PDPage is more used with representing a page onscreen, rather than extracting text. As such, I wouldn't recommend using this to extract text.

like image 157
amaidment Avatar answered Nov 05 '22 20:11

amaidment