How to read pdf content in Java

Download pdfbox jar Add pdfbox jar in your project
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;


public class Readcontentfrompdf {
    
    public static void main(String[] args) throws IOException {

        PDDocument pd;  
//       load pdf file
        pd=PDDocument.load(new File("Specification.pdf"));  
        
        PDFTextStripper pdftext = new PDFTextStripper();        
        System.out.println("Text =: " + pdftext.getText(pd));
        
    }
}

No comments:

Post a Comment