项目地址:
Pdfium.Net:https://github.com/1000374/Pdfium.Net
PdfiumViewer:https://github.com/1000374/PdfiumViewer
框选PDF坐标及区域内文字:
关键代码:
//选中区域的坐标转成相对于pdf的坐标
var point1 = this.PointToPdf(new Point(_currRect.X, _currRect.Y)); var point2 = this.PointToPdf(e.Location); int x = (int)point1.Location.X; int y = (int)point2.Location.Y; int x1 = (int)point2.Location.X; int y1 = (int)point1.Location.Y; var txt = this.Document.Pages[Page].GetBoundedText(x, y, x1, y1); _currRect = Rectangle.Empty; if (Math.Abs(x1 - x) * Math.Abs(y1 - y) == 0)//相当与未框选有效区域 return; BoundedTextHandler?.Invoke(Page, x, y, x1, y1, txt, true);
截取pdf指定区域的图片:
关键代码:
//选中区域的坐标转成相对于pdf的坐标
var point1 = this.PointToPdf(new Point(_currRect.X, _currRect.Y)); var point2 = this.PointToPdf(e.Location); var bound = Document.Pages[Page].PageSize; var rect = new Rectangle(); var x = (int)point1.Location.X; var y = (int)Math.Abs(bound.Height - point1.Location.Y); var x1 = (int)point2.Location.X; var y1 = (int)Math.Abs(bound.Height - point2.Location.Y); rect.X = Math.Min(x, x1); rect.Y = Math.Min(y, y1); rect.Width = Math.Abs(x1 - x); rect.Height = Math.Abs(y1 - y); _currRect = Rectangle.Empty; if (Math.Abs(x1 - x) * Math.Abs(y1 - y) == 0)//相当与未框选有效区域 return; var image = Document.Render( Page, (int)Document.Pages[Page].Width, (int)Document.Pages[Page].Height, rect.X, // x of the top/left of clipping rectangle rect.Y, // y of the top/left point of clipping rectangle rect.Width, // width of clipping reactangle rect.Height, // height of clipping reactangle _cutDpiX, _cutDpiY, FpdfRotation.Rotate0, // no rotation RenderFlags.None // no render flags ); BoundedCutHandler?.Invoke(Page, rect, image);
转换出来的效果:
标签:rect,int,Pdfium,Free,y1,Location,var,PDF,Math From: https://www.cnblogs.com/xiaohemiao/p/17987167