Java PDFBox,从表的一列中提取数据 [英] Java PDFBox, extract data from a column of a table
本文介绍了Java PDFBox,从表的一列中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想了解如何从这个 pdf(例如图像)中提取 http://postimg.org/image/ypebht5dx/
I would like to find out how to extract from this pdf(ex. image) http://postimg.org/image/ypebht5dx/
例如,我只想提取列TENSIONE[V]"中的值,如果遇到空白单元格,我会在输出中输入字母X".我该怎么办?
For example, I want to extract only the values in the column "TENSIONE[V]" and if it encounters a blank cell I enter the letter "X" in the output. How could I do?
我使用的代码是这样的:
The code I used is this:
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
推荐答案
这些只是指导方针.在您使用时使用它们.这也没有经过测试,但可以帮助您解决问题.如果您有任何问题,请告诉我.
These are just guidelines. Use them upon your use. This is not tested either, but help you solve your issue. If you have any question let me know.
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
这篇关于Java PDFBox,从表的一列中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文