import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class PdfToTextMain1 {
public static void main(String[] args) {
// https://pdfbox.apache.org/download.cgi
// pdfbox-2.0.8
// fontbox-2.0.8.jar
String filepath = "file/pdf_ja.pdf";
try {
PDDocument pdDoc = PDDocument.load(new File(filepath)); // throws
// IOException
PDFTextStripper pdfStripper = new PDFTextStripper();// throws
// IOException
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(5);
String parsedText = pdfStripper.getText(pdDoc); // throws
// IOException
System.out.println(parsedText);
} catch (IOException e) {
e.printStackTrace();
}
}
}
--> This is a test.
Recommended Posts