Arquivo da categoria: PDF

PDFBox – How to read PDF file in Java

pom.xml
[code type=xml]

org.apache.pdfbox
pdfbox
2.0.6

Class
[code type=java]
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea;

import java.io.File;
import java.io.IOException;

public class ReadPdf {

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

try (PDDocument document = PDDocument.load(new File(“/path-to/abc.pdf”))) {

document.getClass();

if (!document.isEncrypted()) {

PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);

PDFTextStripper tStripper = new PDFTextStripper();

String pdfFileInText = tStripper.getText(document);
//System.out.println(“Text:” + st);

// split by whitespace
String lines[] = pdfFileInText.split(“\\r?\\n”);
for (String line : lines) {
System.out.println(line);
}

}

}

}
}

PDFBox – How to read PDF file in Java