Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

c#, pdf, api tool for generate PDF

hi i try to use https://pdfium.patagames.com/c-pdf-library/

I found above api/pdf tool that using for (Search for a Text in a PDF File). and return x and y coordiate value.
and I bulit my own codes which is almost the same.

The return is always 0,0 which look like the search keywords feature does not work well.
And anyone try and tell me how your test about?

 public static Tuple<float,float> ExtractTextInfo(string keyword)
           {
            //Initialize the SDK library
            //You have to call this function before you can call any PDF processing functions.
            PdfCommon.Initialize();
            //Open and load a PDF document from a file.
            float x = 0;
            float y = 0;
            using (var doc = Patagames.Pdf.Net.PdfDocument.Load(@"C:\Users\ry24234u.23423\Documents\Workspaces\RNsadfasd\AppStore\ApsdfpMot324orHomeS3423hares\document\rentalcontract.pdf"))
            {
                //Enumerate pages
                foreach (var page in doc.Pages)
                {
                   var found = page.Text.Find("This", FindFlags.MatchWholeWord, 0);
                   if (found == null)
                   {                        
                       return new Tuple<float, float>(0,0);
                   }
                    do
                    {
                        var textInfo = found.FoundText;
                        foreach (var rect in textInfo.Rects)
                        {
                            x = rect.left;
                            y = rect.top;
                        }
                    } while (found.FindNext());

                    page.Dispose();                    
                }
            }
            return new Tuple<float, float>(x, y);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial