标签:
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 模块
标签:
原文地址:http://www.cnblogs.com/aoun/p/4533266.html