跳至主要內容

文本分析器

xsx小于 1 分钟高级功能分析器

说明

可解析文本相关信息,包含内容如下:

  1. pageIndex(页面索引)
  2. pageWidth(页面宽度)
  3. pageHeight(页面高度)
  4. fontName(字体名称)
  5. fontSize(字体大小)
  6. textContent(文本内容)
  7. textBeginPosition(文本起始位置坐标)
  8. textEndPosition(文本结束位置坐标)
  9. textTotalWidth(文本总宽度)

示例(文档)

try (
    // 加载文档
    Document document = PdfHandler.getDocumentHandler().load("E:\\PDF\\pdfbox\\analyzer\\hello-world.pdf");
    // 创建文档分析器
    DocumentAnalyzer analyzer = new DocumentAnalyzer(document);
) {
    // 解析文本信息(文档)
    Set<TextInfo> infoSet = analyzer.analyzeText();
    // 输出文本信息
    infoSet.forEach(System.out::println);
}
源文档
源文档
解析效果
解析效果

示例(页面)

try (
    // 加载文档
    Document document = PdfHandler.getDocumentHandler().load("E:\\PDF\\pdfbox\\analyzer\\hello-world.pdf");
    // 创建文档分析器
    DocumentAnalyzer analyzer = new DocumentAnalyzer(document);
) {
    // 解析文本信息(指定页面)
    Set<TextInfo> infoSet = analyzer.analyzeText(0);
    // 输出文本信息
    infoSet.forEach(System.out::println);
}
源文档
源文档
解析效果
解析效果