【发布时间】:2014-03-01 05:46:53
【问题描述】:
我正在使用 iTextSharp 从特定矩形内的 pdf 中获取数据
在高度的情况下获取的数据工作正常,但在宽度的情况下,它返回整行而不是矩形中的单词。
我使用的代码如下:
PdfReader reader = new PdfReader(Home.currentInstance.Get_PDF_URL());
iTextSharp.text.Rectangle pageRectangle = reader.GetPageSize(currentPage);
float selection_x = ((float)(selectionRectangle.RenderTransform.Value.OffsetX) / (float)canvas.Width) * pageRectangle.Width;
float selection_y = pageRectangle.Height - (((float)(selectionRectangle.RenderTransform.Value.OffsetY) / (float)canvas.Height) * pageRectangle.Height);
float selection_height = ((float)(selectionRectangle.Height) / (float)canvas.Height) * pageRectangle.Height;
float selection_width = ((float)(selectionRectangle.Width) / (float)canvas.Width) * pageRectangle.Width;
selection_y -= selection_height;
RectangleJ rect = new RectangleJ(selection_x,selection_y,selection_width,selection_height);
RenderFilter[] filter = { new RegionTextRenderFilter(rect) };
ITextExtractionStrategy strategy;
strategy = new FilteredTextRenderListener(
new LocationTextExtractionStrategy(), filter
);
String pageText = PdfTextExtractor.GetTextFromPage(reader, currentPage, strategy);
我们将不胜感激。
提前致谢
【问题讨论】:
标签: c# .net itextsharp