PDFLayoutTextStripper
v2.2.5
원본 PDF의 레이아웃을 유지하면서 PDF 파일을 텍스트 파일로 변환합니다. PDF 파일의 테이블이나 양식에서 내용을 추출하는 데 유용합니다. PDFLayoutTextStripper는 PDFTextStripper 클래스(Apache PDFBox 라이브러리에 있음)의 하위 클래스입니다.
PDF 파일의 양식에서 데이터 추출
<dependency>
<groupId>io.github.jonathanlink</groupId>
<artifactId>PDFLayoutTextStripper</artifactId>
<version>2.2.3</version>
</dependency>
경고 : 버전 2.0.0 이상의 pdfbox 버전만 이 버전의 PDFLayoutTextStripper.java와 호환됩니다.
cd PDFLayoutTextStripper
javac -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar *.java
java -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar test
Linux(위 참조)와 동일하지만 : 를 ;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.pdfbox.io.RandomAccessFile;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class test {
public static void main(String[] args) {
String string = null;
try {
PDFParser pdfParser = new PDFParser(new RandomAccessFile(new File("./samples/bus.pdf"), "r"));
pdfParser.parse();
PDDocument pdDocument = new PDDocument(pdfParser.getDocument());
PDFTextStripper pdfTextStripper = new PDFLayoutTextStripper();
string = pdfTextStripper.getText(pdDocument);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
};
System.out.println(string);
}
}
덕분에