[英]Reading table in pdf using java
我想使用Java阅读现有pdf文件中的表格。 我可以使用以下代码(apache pdfBox)从pdf读取文本:
File file=new File("ReadTest.pdf");
PDDocument pdfDocument = PDDocument.load(file);
System.out.println("PDF loaded");
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
PDFTextStripper pdfStripper=new PDFTextStripper();
pdfStripper.setSortByPosition(true);
String text=pdfStripper.getText(pdfDocument);
首先,我想检测给定pdf中表数据的起始位置,然后读取表数据(而表行和列未知)。
我在此网站https://dzone.com/articles/traprange-method-extract-table中找到了您的答案...
在我的工作中,我直接使用TextPosition对象处理文本块。 对于PDF文件中的每个文本块,它将返回具有以下属性的文本元素:
x:距页面左侧的水平距离/// y:距页面顶部边框的垂直距离/// maxX:等于x +文本块的宽度/// maxY:等于y +文本块的高度示例看这张图片https://github.com/thoqbk/traprange/blob/master/_Docs/textposition-rectangle.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.