码迷,mamicode.com
首页 > 其他好文 > 详细

ITextSharp 关键字定位

时间:2015-05-27 15:15:56      阅读:1085      评论:0      收藏:0      [点我收藏+]

标签:

 1         #region IText 模块
 2         private class MyRenderListener : IRenderListener
 3         {
 4             public void BeginTextBlock() { }
 5             public void EndTextBlock() { }
 6             public void RenderImage(ImageRenderInfo renderInfo) { }
 7 
 8             public void RenderText(TextRenderInfo textRenderInfo)
 9             {
10                 string text = textRenderInfo.GetText();
11                 if (text.Contains(KEY_WORD))
12                 {
13                     RectangleJ boundRectange = textRenderInfo.GetBaseline().GetBoundingRectange();
14                     page = cycler-1;
15                     x = (int)boundRectange.X;
16                     y = (int)boundRectange.Y;
17                 }
18             }
19         }
20 
21         private ErrorCode GetPositionByIText(string path)
22         {
23             ErrorCode err = ErrorCode.E_OK;
24             try
25             {
26                 PdfReader reader = new PdfReader(path);
27                 PdfReaderContentParser parser = new PdfReaderContentParser(reader);
28                 MyRenderListener listener = new MyRenderListener();
29                 int numPages = reader.NumberOfPages;
30                 for (cycler = 1; cycler <= numPages; cycler++)
31                     parser.ProcessContent(cycler, listener);
32                 reader.Close();
33             }
34             catch (System.Exception ex)
35             {
36                 err = ErrorCode.E_EXCEPTION;
37                 LogCrash("itext.GetPosition()--" + ex.Message);
38             }
39             return err;
40         }
41         #endregion IText 模块

 

ITextSharp 关键字定位

标签:

原文地址:http://www.cnblogs.com/aoun/p/4533266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!