Download PFD Box from here: https://pdfbox.apache.org/download
package MyPackage;
import java.io.File;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class ReadPDF
{
public void readP() throws Exception
{
File filepath=new File("PDF file path");
PDDocument document = PDDocument.load(filepath);
int pages=document.getNumberOfPages();
System.out.println("Total Number of Pages in Document :"+pages);
//Instantiate PDFTextStripper class
PDFTextStripper pdfStripper = new PDFTextStripper();
//Retrieving text from PDF document
String text = pdfStripper.getText(document);
System.out.println(text);
//Closing the document
document.close();
}
public static void main(String[] args) throws Exception {
ReadPDF p=new ReadPDF();
p.readP();
}
}
No comments:
Post a Comment