PDFLayoutTextStripper
v2.2.5
元の PDF のレイアウトを維持したまま、PDF ファイルをテキスト ファイルに変換します。 PDF ファイル内の表またはフォームからコンテンツを抽出するのに便利です。 PDFLayoutTextStripper は、(Apache PDFBox ライブラリからの) PDFTextStripper クラスのサブクラスです。
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);
}
}
おかげで