/// <summary> /// Scrolls the image to make sure that the box is visible /// </summary> /// <param name="v">Annotate viewer</param> /// <param name="imageBox">The box to make sure is visible</param> private void EnsureAreaIsVisible(AnnotateViewer v, RectangleF imageBox) { Point sp = v.ScrollPosition; int x = GetAdjustedScrollPos(sp.X, imageBox.Left, imageBox.Right, v.ClientSize.Width, v.Zoom); int y = GetAdjustedScrollPos(sp.Y, imageBox.Top, imageBox.Bottom, v.ClientSize.Height, v.Zoom); v.ScrollPosition = new Point(x, y); }
/// <summary> /// Puts a highlight rectangle over the box which is expressed in PDF coordinate space /// </summary> /// <param name="p">A PDF Text page</param> /// <param name="v">The viewer to put the annotation on</param> /// <param name="layer">The layer to put the annotation on</param> /// <param name="pdfBox">The box to highlight in PDF coordinate space</param> /// <param name="hiColor">The color to highlight with</param> /// <param name="padding">Extra padding around the box in pixels</param> private void HighlightPdfBox(PdfTextPage p, AnnotateViewer v, LayerAnnotation layer, RectangleF pdfBox, Color hiColor, int padding) { RectangleF imageBox = p.ConvertPdfUnitsToPixels(new QuadrilateralF(pdfBox), v.Image.Resolution).Bounds; imageBox.X = imageBox.X - padding; imageBox.Y = imageBox.Y - padding; imageBox.Width = imageBox.Width + 2 * padding; imageBox.Height = imageBox.Height + 2 * padding; HighlightImageBox(v, layer, imageBox, hiColor); }
/// <summary> /// Puts an annotation over the characters in a PDF page /// </summary> /// <param name="v">Annotate viewer</param> /// <param name="p">A PDF Text page</param> /// <param name="hiColor">The highlight color</param> /// <param name="index">The index of the first character within the page</param> /// <param name="len">The number of characters to highlight</param> private void HighlightChars(AnnotateViewer v, PdfTextPage p, Color hiColor, int index, int len) { // take off all existing hilights LayerAnnotation layer = v.Annotations.CurrentLayer; layer.Items.Clear(); // a single phrase can span a line and need more than one box to // highlight it QuadrilateralF[] pdfBoxes = p.GetBoxes(index, len); foreach (QuadrilateralF b in pdfBoxes) { HighlightPdfBox(p, v, layer, b.Bounds, hiColor, 2); } }
/// <summary> /// A class to highlight pdf documents that are in an annotation viewer and have a thumbnail viewer /// </summary> /// <param name="viewer">An annotation viewer with one layer for putting highlights on</param> /// <param name="thumbnailViewer">An optional thumbnail viewer (can be null)</param> public PdfFindHighlighter(AnnotateViewer viewer, ThumbnailView thumbnailViewer) { _viewer = viewer; _thumbnailViewer = thumbnailViewer; }
/// <summary> /// Puts a highlight rectangle over the box which is expressed in the image's coordinate space /// </summary> /// <param name="layer">The layer to put the annotation on</param> /// <param name="imageBox">The box to highlight in Image coordinate space</param> /// <param name="hiColor">The color to highlight with</param> private void HighlightImageBox(AnnotateViewer v, LayerAnnotation layer, RectangleF imageBox, Color hiColor) { CreateHighlightAnnotation(layer, imageBox, hiColor); EnsureAreaIsVisible(v, imageBox); }