I am using iText's LocationTextExtractionStrategy class to find a special character in a PDF, which seems to be working. I get an iText vector such as 94.5,698.9,1.0 (from getStartLocation()) and 100.5,698.9,1.0 (from getEndLocation). I want to know what the location is, expressed as a percent in relation to the page. The objective is to export the PDF page as an image and use it in a div on a web page, and use another div as an overlay (semi translucent) to highlight the area. For example, I can locate a person's name followed by the special character. I want to put a div right over that one spot where the special character is. Since I have the iText vector, if I can somehow convert that to the percent in relation to the PDF page then I can translate that info for use on a div. For example top 25.125%, left 30.55% - It's OK if the location is a few pixels off mark since I just want to highlight the general area (give or take about 5 pixels vertically or horizontally).
1 に答える
1
leftPercent = (location.getEndLocation().get(0) / pageWidth) *100,
topPercent = ((pageHeight - location.getEndLocation().get(1)) / pageHeight) *100
8.5 インチ (幅) x 11 インチ (高さ) のドキュメントがある場合、特殊文字がベクトル 152,594,1.0 にある場合、方程式は次のように計算されます。
leftPercent = (152 / 612) *100 = 25%
と
topPercent = ((792 - 594) / 792) *100 = 25%
私のテスト ケースでは、特殊文字を意図的に上から 25%、左から 25% の位置に配置しました。
于 2013-08-06T00:22:12.147 に答える