如何使用java获取pdf中任何给定单词的(x,y width height)

时间:2019-04-10 18:47:32

标签: java pdfbox

我需要获取pdf中给定单词的x,y,宽度和高度。这样,稍后在解析相同类型的文件时,我就可以从坐标本身获取值。我应该如何使用Java从PDF中获取单词的位置。

Rectangle rect = new Rectangle(451, 125,100,1); // i need to get this co-ordate for any particular word
stripper.addRegion("class1", rect);
stripper.extractRegions(pdDocument.getPage(0));
System.out.println("stripper "+stripper.getTextForRegion("class1").trim());

1 个答案:

答案 0 :(得分:0)

我认为您可以使用Apache's PDFBox API并遵循this similar question中的建议,该建议专门针对该API来编写您所需的代码。