Apache Tikaを使用したテキスト抽出
v2023.05
JPedalはApache TikaのParserインターフェース に対応しており、既存のTikaアプリケーションでそのまま置き換えて使用することができます。
現在、構造化テキストと非構造化テキストの両方をサポートしています。
try (final TikaInputStream tik = TikaInputStream.get(Paths.get("inputFile.pdf"))) {
final PDFParser parser = new PDFParser(UNSTRUCTURED_TEXT);
// Set the writeLimit to -1 otherwise only the first 100000 characters are parsed
final BodyContentHandler handler = new BodyContentHandler(-1);
// Ability to set a password if necessary
final Metadata metadata = new Metadata();
// metadata.set(PDFParser.PASSWORD, "password");
// parseContext is not required so can be null
parser.parse(tik, handler, metadata, null);
// Print the result
System.out.println(handler);
} catch (final IOException | SAXException | TikaException e) {
e.printStackTrace();
}
PDFParser の詳細情報。
