/// <summary> /// Deal the find results when some record is found out. /// </summary> /// <param name="hlts">The hightlights information</param> /// <param name="_pdfDoc">The pdf document object</param> /// <param name="lowRange">The beginning location for finding</param> /// <param name="verifyRegex">The regex for veritying key words</param> /// <returns>If the result is defined,return a LinePos object,otherwise return null</returns> LinePos GetLinePos(string regex, Highlights hlts, LinePos lowRange) { List <Rect> lineRects = GetLineRect(hlts); int pageNum = hlts.GetCurrentPageNumber(); foreach (Rect lineRect in lineRects) { if (pageNum <= GetLowPage(lowRange) && !IsBelow(lineRect, lowRange)) { continue; } string text = ReadTextFromRect(pageNum, lineRect); string trimText = text.RemoveBlankSpace(); if (!Regex.IsMatch(trimText, regex)) { continue; } LinePos linePos = new LinePos() { PageNum = pageNum, AxisValue = GetAxisBoundValue(true, lineRect), TrimText = trimText, AxisValueWithLineHeight = GetAxisBoundValue(false, lineRect), }; return(linePos); } return(null); }
double GetBlankAreaHeight(LinePos uponPos) { int pageNum = uponPos.PageNum; double bottomAxisValue = 0; double uponValue = GetBottomTextYValue(pageNum, bottomAxisValue, uponPos.AxisValue, false); return(Math.Abs(uponValue - bottomAxisValue)); }
/// <summary> /// Judge whether the position of lineRect is below lowRange. /// </summary> /// <param name="rotateAngle">The angle current pdf page has been rotated</param> /// <param name="lineRect">A rectangle</param> /// <param name="lowRange">The position of level</param> /// <returns>Return true if the position of lineRect is below lowRange,otherwise return false</returns> bool IsBelow(Rect lineRect, LinePos lowRange) { if (lowRange == null) { return(true); } return(lineRect.y1 <= lowRange.AxisValue); }
public static bool IsBelow(this Point point, LinePos lowRange) { if (lowRange == null) { return(true); } return(point.y <= lowRange.AxisValue); }
private void ScVxDate_GDIPaint(GDIGraphics g) { Graphics graphis = g.GdiGraph; graphis.SmoothingMode = SmoothingMode.HighQuality; graphis.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; RectangleF rect = new RectangleF(0, 0, Width - 1, Height - 1); // Brush brush = new SolidBrush(bgColor); DrawUtils.FillRoundRectangle(graphis, brush, rect, 6); Pen pen = new Pen(txtColor); DrawUtils.DrawRoundRectangle(graphis, pen, rect, 6); // brush = new SolidBrush(Color.FromArgb(105, 163, 175)); rect = mainTable.GetCellContentRect(0, 0); string d = dt.ToString("yyyy-MM-dd"); DrawUtils.LimitBoxDraw(graphis, d, font, brush, rect, true, 0); // rect = mainTable.GetCellContentRect(0, 1); d = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek); DrawUtils.LimitBoxDraw(graphis, d, font, brush, rect, true, 0); // rect = mainTable.GetCellContentRect(0, 2); d = DateTime.Now.ToLongTimeString().ToString(); DrawUtils.LimitBoxDraw(graphis, d, font, Brushes.WhiteSmoke, rect, true, 0); brush.Dispose(); // LinePos linePos = mainTable.GetColLinePos(0); linePos.start = new PointF((int)linePos.start.X, (int)(linePos.start.Y + Height / 7)); linePos.end = new PointF((int)linePos.end.X, (int)(linePos.end.Y - Height / 7)); graphis.DrawLine(pen, linePos.start, linePos.end); // linePos = mainTable.GetColLinePos(1); linePos.start = new PointF((int)linePos.start.X, (int)(linePos.start.Y + Height / 7)); linePos.end = new PointF((int)linePos.end.X, (int)(linePos.end.Y - Height / 7)); graphis.DrawLine(pen, linePos.start, linePos.end); }
/// <summary> /// Get the pos of the top bound of a pdf page. /// </summary> /// <param name="pageNum">The number of the pdf page.</param> /// <returns>Return the pos of the top bound of a pdf page.</returns> public LinePos GetTopPosOfPage(int pageNum) { double[] pageSize = GetPageSize(pageNum); LinePos linePos = new LinePos() { PageNum = pageNum }; double axisValue = 0; axisValue = pageSize[1]; linePos.AxisValueWithLineHeight = linePos.AxisValue = axisValue; return(linePos); }
/// <summary> /// Search by the condition provided by parameters and return the first result. /// </summary> /// <param name="regex">The regex to match the text.</param> /// <param name="lowRange">The low range of the search scale</param> /// <param name="highRange">The high range of the search scale</param> /// <returns>If there are some search result,return the first one;Otherwise,return null.</returns> public LinePos Search(string regex, LinePos lowRange, LinePos highRange) { bool isDone = false; int startPage = GetLowPage(lowRange); while (!isDone) { List <LinePos> linePoses = Search(regex, lowRange, highRange, ref startPage); if (linePoses.Count > 0) { return(linePoses[0]); } isDone = startPage > GetHighPage(highRange); } return(null); }
Rect GetTablePosRect(int pageNum, LinePos topPos, LinePos bottomPos, bool isMatchNum) { double topAxisValue = topPos == null?pdfTronHelper.GetTopPosOfPage(pageNum).AxisValue : topPos.AxisValue; double bottomPosAxisValue = bottomPos == null?0:bottomPos.AxisValue; if (bottomPosAxisValue == 0) { bottomPosAxisValue = pdfTronHelper.GetBottomPosOfPage(pageNum, isMatchNum, bottomPosAxisValue, topAxisValue).AxisValue; } double[] leftRightTextBounds = pdfTronHelper.GetLeftRightTextBounds(pageNum); Rect rect = new Rect(leftRightTextBounds[0] - 10, bottomPosAxisValue, leftRightTextBounds[1] + 10, topAxisValue); return(rect); }
/// <summary> /// Search a result and return /// </summary> /// <param name="searcher">A TextSearch object</param> /// <param name="lowRange">The low range of the search scale</param> /// <param name="highRange">The high range of the search scale</param> /// <param name="isDone">Indicate whether the search is over</param> /// <returns>A list of LinePos object found in two pages</returns> public List <LinePos> Search(string regex, LinePos lowRange, LinePos highRange, ref int startPage, bool isSearchUp = false) { int pageNum = 0; String resultStr = "", ambientStr = ""; Highlights hlts = new Highlights(); List <LinePos> linePoses = new List <LinePos>(); TextSearch searcher = InitAndBeginSearch(regex, startPage, startPage, isSearchUp); while (true) { pdftron.PDF.TextSearch.ResultCode resultCode; resultCode = searcher.Run(ref pageNum, ref resultStr, ref ambientStr, hlts); if (resultCode == TextSearch.ResultCode.e_found) { LinePos linePos = GetLinePos(regex, hlts, lowRange); if (linePos == null) { continue; } if (linePos.IsBetween(lowRange, highRange)) { linePoses.Add(linePos); } } if (resultCode == TextSearch.ResultCode.e_done) { startPage += isSearchUp ? -1 : 1; if (linePoses.Count > 0) { break; } else { int highPage = GetHighPage(highRange); int lowPage = GetLowPage(lowRange); if ((!isSearchUp && startPage > highPage) || (isSearchUp && startPage < lowPage)) { break; } searcher = InitAndBeginSearch(regex, startPage, startPage, isSearchUp); } } } linePoses.Sort(); return(linePoses); }
/// <summary> /// Validate the distance between two position. /// </summary> /// <param name="posUpon">The high positon.</param> /// <param name="posBelow">The low position.</param> /// <param name="maxInstance">The max distance allowed between two positions.</param> /// <returns>Return true if the distance is in the max distance,otherwise return false.</returns> public bool ValidateInstance(LinePos posUpon, LinePos posBelow, double maxInstance) { int pageSpan = posBelow.PageNum - posUpon.PageNum; if (pageSpan > 1) { return(false); } if (pageSpan == 1) { double pageEndAxisValue = 0; double toPageEndDistance = Math.Abs(posUpon.AxisValue - pageEndAxisValue); toPageEndDistance -= GetBlankAreaHeight(posUpon); double fromPageStartDistance = Math.Abs(posBelow.AxisValue - GetTopPosOfPage(posBelow.PageNum).AxisValue); return(toPageEndDistance + fromPageStartDistance <= maxInstance + 40); } return(Math.Abs(posBelow.AxisValue - posUpon.AxisValue) <= maxInstance); }
/// <summary> /// Get the pos of the bottom bound of a pdf page. /// </summary> /// <param name="pageNum">The number of the pdf page.</param> /// <returns>Return the pos of the bottom bound of a pdf page.</returns> public LinePos GetBottomPosOfPage(int pageNum, bool isMatchNum, double lowPos, double highPos) { if (pageNum > _pdfDoc.GetPageCount() || pageNum < 1) { return(null); } LinePos linePos = new LinePos() { PageNum = pageNum }; linePos.AxisValue = linePos.AxisValueWithLineHeight = GetBottomTextYValue(pageNum, lowPos == -1?0:lowPos, highPos == -1?GetTopPosOfPage(pageNum).AxisValue:highPos, isMatchNum); return(linePos); }
private void ScVxDate_GDIPaint(GDIGraphics g) { Graphics graphis = g.GdiGraph; graphis.SmoothingMode = SmoothingMode.HighQuality; graphis.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; RectangleF rect = new RectangleF(0, 0, Width - 1, Height - 1); // Pen pen = new Pen(txtColor); DrawUtils.DrawRoundRectangle(graphis, pen, rect, 6); // LinePos linePos = mainTable.GetColLinePos(0); linePos.start = new PointF((int)linePos.start.X, (int)(linePos.start.Y + Height / 7)); linePos.end = new PointF((int)linePos.end.X, (int)(linePos.end.Y - Height / 7)); graphis.DrawLine(pen, linePos.start, linePos.end); }
public SortedDictionary <double, FormLineList>[] GetFormLines(int pageNum, LinePos startPos, LinePos endPos , bool isSubsequentPage, SortedDictionary <double, FormLineList> lastPageVerticalLines) { //Get the information of lines and extreme points by travelsaling the page horizontalLines = new SortedDictionary <double, FormLineList>(); verticalLines = new SortedDictionary <double, FormLineList>(); _pageNum = pageNum; _startPos = startPos; _endPos = endPos; Page page = _pdfDoc.GetPage(pageNum); pageSize = PdfTronHelper.GetPageSize(page); topBound.AxisValue = startPos == null ? pageSize[1] : startPos.AxisValue; bottomBound.AxisValue = endPos == null ? 0 : endPos.AxisValue; ii = 0; using (ElementReader page_reader = new ElementReader()) { page_reader.Begin(page); ProcessElements(page_reader); } RemoveLittleLines(horizontalLines); RemoveLittleLines(verticalLines); //Remove short lines. Rect posRect = GetTablePosRect(_pageNum, _startPos, _endPos, isSubsequentPage); RemoveTooShortAndTooLongLines(page, horizontalLines, true, posRect); bool isNotNeedGenerateVerLines = isSubsequentPage && lastPageVerticalLines != null && verticalLines.Count == lastPageVerticalLines.Count; if (!isNotNeedGenerateVerLines) { RemoveTooShortAndTooLongLines(page, verticalLines, false, posRect); } //Generate drawed lines. Rect areaRect; bool existRealRect = horizontalLines.Count > 1 && verticalLines.Count > 1 && IsRect(posRect, horizontalLines, verticalLines); areaRect = existRealRect ? GenerateRectByLines() : posRect; if (existRealRect || isSubsequentPage) { RemoveLinesNotInRect(areaRect, horizontalLines, verticalLines); isNotNeedGenerateVerLines = isSubsequentPage && lastPageVerticalLines != null && verticalLines.Count == lastPageVerticalLines.Count; } else { posRect = GetTablePosRect(_pageNum, _startPos, _endPos, true); } FormLineGenerator.RemoveSpareNearLines(verticalLines, false); if (!isNotNeedGenerateVerLines) { isNotNeedGenerateVerLines = isSubsequentPage && lastPageVerticalLines != null && verticalLines.Count == lastPageVerticalLines.Count; } FormLineGenerator lineGenerator = new FormLineGenerator(page, areaRect); SortedDictionary <double, FormLineList>[] lines = lineGenerator.GetFormLines(existRealRect, horizontalLines, verticalLines, isNotNeedGenerateVerLines); return(lines); }
public int GetLowPage(LinePos lowPos) { return(lowPos == null ? 1 : lowPos.PageNum); }
public MmlDatum2(string code, int dat, enmMMLType type, LinePos linePos, params object[] args) : base(dat, type, linePos, args) { this.code = code; }
public MmlDatum2(string code, enmMMLType type, List <object> args, LinePos linePos, int dat) : base(type, args, linePos, dat) { this.code = code; }
int GetHighPage(LinePos highPos) { return(highPos == null?_pdfDoc.GetPageCount() : highPos.PageNum); }