gpt4 book ai didi

java - 使用java读取pdf中的表格

转载 作者:太空宇宙 更新时间:2023-11-04 10:08:03 24 4
gpt4 key购买 nike

我想使用 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 对象直接处理文本 block 。对于 PDF 文件中的每个文本 block ,它返回具有以下属性的文本元素:

x:距页面左侧的水平距离///y:距页面上边框的垂直距离///maxX:等于x + 文本 block 的宽度///maxY:等于 y+ 文本 block 的高度例如看这张图片 https://github.com/thoqbk/traprange/blob/master/_Docs/textposition-rectangle.png

关于java - 使用java读取pdf中的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com