2013-12-16 14 views
3
文字出現

是否有可能,使用iTextSharp的,獲得包含在PDF文檔的指定區域的所有文字出現?獲取包含在指定區域與iTextSharp的

enter image description here

謝謝。

+0

您的座標似乎是從左上角向右下方。請注意,大多數情況下在PDF中,座標都是從左下角開始的。 – mkl

+0

對不起......我犯了一個錯誤。我寫了76,而不是726 ...我做了更正。 – Gigi

回答

6

首先,您需要用紅色標記的矩形的實際座標。在視線上,我會說x值144(2英寸)可能是正確的,但如果y值爲76,它會讓我感到驚訝,所以你必須仔細檢查。

確定了矩形的確切座標後,就可以使用LocationTextExtractionStrategy的iText文本提取功能,如ExtractPageContentArea示例中所做的那樣。

對於本示例的iTextSharp版本,請參閱C#端口the examples of chapter 15

System.util.RectangleJ rect = new System.util.RectangleJ(70, 80, 420, 500); 
RenderFilter[] filter = {new RegionTextRenderFilter(rect)}; 
ITextExtractionStrategy strategy = new FilteredTextRenderListener(
     new LocationTextExtractionStrategy(), filter); 
text = PdfTextExtractor.GetTextFromPage(reader, 1, strategy); 
+0

謝謝,它的工作原理! – Gigi