Java PDFBox,从表的列中提取数据

时间:2013-04-25 14:50:03

标签: java pdfbox

我想了解如何从这个pdf中提取(例如图片)http://postimg.org/image/ypebht5dx/

例如,我想只提取“TENSIONE [V]”列中的值,如果遇到空白单元格,我在输出中输入字母“X”。 我该怎么办?

我使用的代码是:

 PDDocument p=PDDocument.load(new File("a.pdf"));
 PDFTextStripper t=new PDFTextStripper();
 System.out.println(t.getText(p));

我得到了这个输出:

http://s23.postimg.org/wbhcrw03v/Immagine.png

1 个答案:

答案 0 :(得分:1)

这些只是指导原则。使用时使用它们。这也没有经过测试,但可以帮助您解决问题。如果您有任何疑问,请告诉我。

String text = t.getText(p);
String lines[] = text.split("\\r?\\n"); // give you all the lines separated by new line

String cols[] = lines[0].split("\\s+") // gives array separated by whitespaces
// cols[0] contains pins
// clos[1] contains TENSIONE[V]
// cols[2] contains TOLLRENZA if not present then its empty
相关问题