pvginkel / PdfiumViewer

PDF viewer based on Google's PDFium.
Apache License 2.0
967 stars 418 forks source link

It seems the PdfMatch's Location is not the rigth location on the page #85

Closed BobCFD closed 7 years ago

BobCFD commented 8 years ago

Hi, I want to add the search text and highlight the PdfMatches, I add some code to the PdfDocument.Render to draw rectangle on the PdfMatch.Location. But the result is the rectangle is not in the search txt's Location. could you please help me with this? Thanks for the code and good luck!

here is the example:

var point = new NativeMethods.POINT(); NativeMethods.SetViewportOrgEx(dc, bounds.X, bounds.Y, out point);

            bool success = _file.RenderPDFPageToDC(
                page,
                dc,
                (int)dpiX, (int)dpiY,
                0, 0, bounds.Width, bounds.Height,
                FlagsToFPDFFlags(flags)
            );

            ****//here write the method : draw the Rectangle**** 

if (_highlights.ContainsKey(pageIndex))//_highlights is the sorted search result PdfMatches {

            IntPtr vBrush = NativeMethods.CreateSolidBrush(ColorTranslator.ToWin32(Color.Red));
            var matches = _highlights[pageIndex];
            foreach (var e in matches)
            {
                Rectangle rect = new Rectangle((int)e.Location.X, (int)e.Location.Y, (int)e.Size.Width, (int)e.Size.Height);
                NativeMethods.RECT r = new NativeMethods.RECT(rect);
                NativeMethods.SelectObject(vDC, vBrush);
                NativeMethods.FillRect(vDC, ref r, vBrush);
            }
            NativeMethods.DeleteObject(vBrush);
        }

            NativeMethods.SetViewportOrgEx(dc, point.X, point.Y, out point);
thakurarun commented 7 years ago

Hi @BobCFD ,

Could you provide me the the code for the Search Text and Highlight it, If you have implemented it? I am also facing problem in this.

Thanks

pvginkel commented 7 years ago

I've implemented markers (i.e. highlights) and a PdfSearchManager that uses these to simplify searching through the PDF document. I've also implemented a search dialog in the demo application which uses this class.