public static bool Contains(this FS_RECTF rect, float x, float y) { return(rect.left <= x && x <= rect.right && rect.bottom <= y && y <= rect.top); }
/// <summary>Checks whether rect1 and rect2 are aligned along X.</summary> /// <param name="rect1"></param> /// <param name="rect2"></param> /// <param name="tolerence">Tolerence for gauging distance</param> /// <returns></returns> public static bool IsAlongsideYWith(this FS_RECTF rect1, FS_RECTF rect2, float tolerence) { return(rect1.bottom - tolerence <= rect2.top && rect1.top + tolerence >= rect2.bottom || rect2.bottom - tolerence <= rect1.top && rect2.top + tolerence >= rect1.bottom); }
/// <summary>Checks whether rect1 and rect2 are aligned along X.</summary> /// <param name="rect1"></param> /// <param name="rect2"></param> /// <param name="tolerence">Tolerence for gauging distance</param> /// <returns></returns> public static bool IsAlongsideXWith(this FS_RECTF rect1, FS_RECTF rect2, float tolerence) { return(rect1.left - tolerence <= rect2.right && rect1.right + tolerence >= rect2.left || rect2.left - tolerence <= rect1.right && rect2.right + tolerence >= rect1.left); }
public bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect) { lock (_Lock) { return(this.FPDFLink_GetAnnotRect(linkAnnot, rect)); } }
public void PDFiumBridge_FPDFRenderPageBitmapWithMatrix_SimpleCall_NoException() { var matrix = new FS_MATRIX(); var clipping = new FS_RECTF(); _bridge.FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP.InvalidHandle, FPDF_PAGE.InvalidHandle, ref matrix, ref clipping, FPDF_RENDERING_FLAGS.FPDF_NONE); }
public static bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect) { lock (LockString) { return(Imports.FPDFLink_GetAnnotRect(linkAnnot, rect)); } }
private List <PdfTextInfo> GetBoundedTextInfo(double left, double top, double right, double bottom) { var boundedArea = new FS_RECTF((float)left, (float)top, (float)right, (float)bottom); var textInfoList = new List <PdfTextInfo>(); var allRects = GetAllRects(); GetAllCharInfo(); //Ensure char info is cached in memory foreach (var rect in allRects) { if (rect.IntersectsWith(boundedArea)) { // Find all the characters that fit in this rect AND the boundedArea var chars = _allCharInfo.FindAll(c => rect.Contains(c.BoundingRectangle) && boundedArea.ContainsPartially(c.BoundingRectangle, 50)); var charBoxes = new List <FS_RECTF>(); chars.ForEach(c => charBoxes.Add(c.BoundingRectangle)); var boundingRect = FS_RECTF.Union(charBoxes); textInfoList.Add(new PdfTextInfo(string.Join <PdfTextInfo>(string.Empty, chars.ToArray()), -1, chars.Count, boundingRect, charBoxes)); } } textInfoList.Sort((x, y) => { // Sort top to bottom, left to right. int retval = -x.BoundingRectangle.Bottom.CompareTo(y.BoundingRectangle.Bottom); return(retval == 0 ? x.BoundingRectangle.Left.CompareTo(y.BoundingRectangle.Left) : retval); }); return(textInfoList); }
/// <summary> /// Initialize the new instance of PdfToolBarSearch class /// </summary> public PdfToolBarSearch() { _searchTimer = new DispatcherTimer(); _searchTimer.Interval = TimeSpan.FromMilliseconds(1); _searchTimer.Tick += _searchTimer_Tick; HighlightColor = Color.FromArgb(50, 255, 255, 0); ActiveRecordColor = Color.FromArgb(255, 255, 255, 0); InflateHighlight = new FS_RECTF(2.0, 3.5, 2.0, 2.0); }
/// <summary> /// Initialize the new instance of PdfToolStripSearch class /// </summary> public PdfToolStripSearch() { _searchTimer = new Timer(); _searchTimer.Interval = 1; _searchTimer.Tick += _searchTimer_Tick; HighlightColor = Color.FromArgb(50, 255, 255, 0); ActiveRecordColor = Color.FromArgb(255, 255, 255, 0); InflateHighlight = new FS_RECTF(2.0, 3.5, 2.0, 2.0); }
internal PdfTextInfo(string text, int startIndex, int length, FS_RECTF boundingRect, List <FS_RECTF> charBoxes) { Text = text.RemoveControlCharacters().RemoveLigatures(); StartIndex = startIndex; Length = length; BoundingRectangle = boundingRect; charBoxList = charBoxes; }
public Rectangle RectangleFromPdf(PdfPage page, FS_RECTF rect) { var(x1, y1) = page.PageToDevice((0, 0, (int)page.Width, (int)page.Height), rect.Left, rect.Top, page.Orientation); var(x2, y2) = page.PageToDevice((0, 0, (int)page.Width, (int)page.Height), rect.Right, rect.Bottom, page.Orientation); return(new Rectangle( x1, y1, x2 - x1, y2 - y1 )); }
protected Rect PageToDeviceDoubleRect(FS_RECTF rc, int pageIndex) { var pt1 = PageToDevice(rc.left, rc.top, pageIndex); var pt2 = PageToDevice(rc.right, rc.bottom, pageIndex); int x = Helpers.UnitsToPixels(pt1.X < pt2.X ? pt1.X : pt2.X); int y = Helpers.UnitsToPixels(pt1.Y < pt2.Y ? pt1.Y : pt2.Y); int w = Helpers.UnitsToPixels(pt1.X > pt2.X ? pt1.X - pt2.X : pt2.X - pt1.X); int h = Helpers.UnitsToPixels(pt1.Y > pt2.Y ? pt1.Y - pt2.Y : pt2.Y - pt1.Y); return(new Rect(x, y, w, h)); }
public void AddLine(PdfTextInfo line) { if (Lines.Any()) { BoundingRectangle = BoundingRectangle.Union(line.BoundingRectangle); } else { BoundingRectangle = line.BoundingRectangle; } Lines.Add(line); }
/// <summary> /// Render the page to the bitmap. /// </summary> /// <param name="page">Page to render.</param> /// <param name="zoomFactor">Zoom factor to use for transformation.</param> /// <param name="startX">Left pixel position of the page area to render.</param> /// <param name="startY">Top pixel position of the page area to render.</param> /// <param name="sizeX">Width of the page area to render.</param> /// <param name="sizeY">Height of the page area to render.</param> /// <param name="flags">Rendering flags to use for rendering.</param> public void RenderWithTransformation(FPDF_PAGE page, double zoomFactor, int startX, int startY, int sizeX, int sizeY, FPDF_RENDERING_FLAGS flags) { // Translation is performed with [1 0 0 1 tx ty]. // Scaling is performed with [sx 0 0 sy 0 0]. FS_MATRIX matrix = new FS_MATRIX { A = (float)zoomFactor, B = 0, C = 0, D = (float)zoomFactor, E = startX > 0f ? 0f : startX, F = startY > 0f ? 0f : startY }; FS_RECTF rect = new FS_RECTF { Left = startX, Right = startX + sizeX, Top = startY, Bottom = startY + sizeY }; _mainComponent.PDFiumBridge.FPDF_RenderPageBitmapWithMatrix(_bitmapHandle, page, ref matrix, ref rect, flags); }
private void AddImgExtractHighlight(int pageIndex, FS_RECTF boundingBox) { var pageHighlights = ImageExtractHighlights .SafeGet(pageIndex, new List <PDFImageExtract>()); pageHighlights.Add(new PDFImageExtract { BoundingBox = boundingBox, PageIndex = pageIndex, }); ImageExtractHighlights[pageIndex] = pageHighlights; }
public void FPDFVIEW_Render_Call() { var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf"); var bridge = new PDFiumBridge(); var document = bridge.FPDF_LoadDocument(pdfFile, null); Assert.IsTrue(document.IsValid); var page = bridge.FPDF_LoadPage(document, 0); Assert.IsTrue(page.IsValid); var bitmap = bridge.FPDFBitmap_Create(100, 200, false); Assert.IsTrue(bitmap.IsValid); bridge.FPDF_RenderPageBitmap(bitmap, page, 0, 0, 100, 200, 0, 0); bridge.FPDFBitmap_Destroy(bitmap); bitmap = bridge.FPDFBitmap_Create(1000, 2000, false); Assert.IsTrue(bitmap.IsValid); var matrix = new FS_MATRIX { A = 1, B = 0, C = 0, D = 1, E = 1, F = 1, }; var rect = new FS_RECTF { Left = 0, Right = 612, Top = 792, Bottom = 0, }; bridge.FPDF_RenderPageBitmapWithMatrix(bitmap, page, ref matrix, ref rect, 0); bridge.FPDFBitmap_Destroy(bitmap); bridge.FPDF_ClosePage(page); bridge.FPDF_CloseDocument(document); bridge.Dispose(); }
public void PDFiumBridge_FPDFTextGetLooseCharBox_SimpleCall_NoException() { var rect = new FS_RECTF(); _bridge.FPDFText_GetLooseCharBox(FPDF_TEXTPAGE.InvalidHandle, 0, ref rect); }
public string GetBoundedText(FS_RECTF rect) { return(this.GetBoundedText(rect.Left, rect.Top, rect.Right, rect.Bottom)); }
public static extern bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect);
public void PDFiumBridge_FPDFPageGetAnnot_TestForExistence_Success() { var pdfFile = Path.Combine(_pdfFilesFolder, "Annotations.pdf"); var bridge = new PDFiumBridge(); var document = bridge.FPDF_LoadDocument(pdfFile, null); Assert.IsTrue(document.IsValid); var page = bridge.FPDF_LoadPage(document, 0); Assert.IsTrue(page.IsValid); var count = bridge.FPDFPage_GetAnnotCount(page); for (var index = 0; index < count; index++) { var annot = bridge.FPDFPage_GetAnnot(page, index); Assert.IsTrue(annot.IsValid); var realIndex = bridge.FPDFPage_GetAnnotIndex(page, annot); Assert.AreEqual(index, realIndex); var subtype = bridge.FPDFAnnot_GetSubtype(annot); Assert.IsTrue(subtype != FPDF_ANNOTATION_SUBTYPE.FPDF_ANNOT_UNKNOWN); var objectCount = bridge.FPDFAnnot_GetObjectCount(annot); for (var objectIndex = 0; objectIndex < objectCount; objectIndex++) { var obj = bridge.FPDFAnnot_GetObject(annot, objectIndex); Assert.IsTrue(obj.IsValid); } var pointsCount = bridge.FPDFAnnot_CountAttachmentPoints(annot); for (var pointsIndex = 0; pointsIndex < pointsCount; pointsIndex++) { var points = new FS_QUADPOINTSF(); Assert.IsTrue(bridge.FPDFAnnot_GetAttachmentPoints(annot, pointsIndex, ref points)); } var rect = new FS_RECTF(); Assert.IsTrue(bridge.FPDFAnnot_GetRect(annot, ref rect)); var verticesCount = bridge.FPDFAnnot_GetVertices(annot, IntPtr.Zero, 0); if (verticesCount != 0) { var points = new FS_POINTF[verticesCount]; var pointsIntPtr = NativeMethods.StructureArrayToIntPtr(points); Assert.AreEqual(verticesCount, bridge.FPDFAnnot_GetVertices(annot, pointsIntPtr, verticesCount)); Marshal.FreeHGlobal(pointsIntPtr); } float horizontal_radius, vertical_radius, border_width; horizontal_radius = vertical_radius = border_width = -1f; if (bridge.FPDFAnnot_GetBorder(annot, ref horizontal_radius, ref vertical_radius, ref border_width)) { Assert.IsTrue(horizontal_radius != -1f); Assert.IsTrue(vertical_radius != -1f); Assert.IsTrue(border_width != -1f); } bridge.FPDFPage_CloseAnnot(annot); } bridge.FPDF_ClosePage(page); bridge.FPDF_CloseDocument(document); bridge.Dispose(); }
public void PDFiumBridge_FPDFLinkGetAnnotRect_SimpleCall_NoException() { var rect = new FS_RECTF(); _bridge.FPDFLink_GetAnnotRect(FPDF_LINK.InvalidHandle, ref rect); }
public static extern void FPDF_RenderPageBitmapWithMatrix(IntPtr bitmap, IntPtr page, [In] ref FS_MATRIX matrix, [In] ref FS_RECTF clipping, int flags);
public static extern int FPDFLink_GetAnnotRect(IntPtr link, out FS_RECTF rect);
/// <summary> /// Checks whether rect1 and rect2 are next to each other, or intersecting along Y. /// Assumes <paramref name="rect1" /> before <paramref name="rect2" />. /// </summary> /// <param name="rect1"></param> /// <param name="rect2"></param> /// <param name="tolerence">Tolerence for gauging distance</param> /// <returns></returns> public static bool IsAdjacentAlongYWith(this FS_RECTF rect1, FS_RECTF rect2, float tolerence) { return(rect1.top + tolerence >= rect2.bottom); }
/// <summary> /// Checks whether rect1 and rect2 are next to each other, or intersecting along X. /// Assumes <paramref name="rect1" /> before <paramref name="rect2" />. /// </summary> /// <param name="rect1"></param> /// <param name="rect2"></param> /// <param name="tolerence">Tolerence for gauging distance</param> /// <returns></returns> public static bool IsAdjacentAlongXWith(this FS_RECTF rect1, FS_RECTF rect2, float tolerence) { return(rect1.right + tolerence >= rect2.left); }
public static bool FPDFLink_GetAnnotRect(IntPtr linkAnnot, FS_RECTF rect) { lock (LockString) { return Imports.FPDFLink_GetAnnotRect(linkAnnot, rect); } }
public void PDFiumBridge_FPDFAnnotGetRect_SimpleCall_NoException() { var rect = new FS_RECTF(); _bridge.FPDFAnnot_GetRect(FPDF_ANNOTATION.InvalidHandle, ref rect); }