单页PDF含有一张表
com.aistrong.analysis.pdf.service
Class ReaderTextService
Method Detail:
public ArrayList<List<WordWithTextPositions>> readWordWithTextPositions(String path)
Arguments:
path - pdf文件存储路径
Returns:
ArrayList<List<WordWithTextPositions>>
每个WordWithTextPositions对象中存储了1行(参看注意)中所有字符,其中每个字符对应一个TextPosition对象,每个TextPosition存储了该字符所有相关信息,包含字符、坐标等,详细介绍参看pdfBox API文档Class TextPosition
Instance:
package com;
import java.io.IOException;
import java.util.List;
import org.apache.pdfbox.text.PDFLocalStripper.WordWithTextPositions;
import org.apache.pdfbox.text.TextPosition;
import com.aistrong.analysis.pdf.service.ReaderTextService;
public class TestReadWordWithTextPositions {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ReaderTextService rts = new ReaderTextService();
for(List<WordWithTextPositions> l : rts.readWordWithTextPositions("/Users/hhhtide/Desktop/PDF_Extract/Data/table1.pdf")) {
for(WordWithTextPositions wwtp : l) {
for(TextPosition tp : wwtp.getTextPositions()) {
System.out.println("word:" + tp.getUnicode().toString() + " X:" + tp.getX());
}
}
}
}
}
输出:
word:表 X:48.0
word:1 X:64.5
word:2 X:75.5
word:0 X:81.0
word:0 X:86.5
word:9 X:92.0
word:~ X:97.5
word:2 X:108.5
word:0 X:114.0
word:1 X:119.5
word:1 X:125.0
word:年 X:136.0
word:安 X:147.0
word:庆 X:158.0
word:市 X:169.0
.
.
.
网友评论