3

User will see a pdf in webbrowser Control(or any other viewer) and select the text from it then I want to find

1)Coordinates of selected text.

2)Font Size of selected text.

3)Font Color of Selected text.

4)Page Number of selected text.

So that i can use this information to find the text from pdf with same theme .

Problem 1: Is it possible to find which text or coordinate is selected in webbrowser control? There must be a better way to do it using pdf tron viewer?

My approach will be to fix the Form ,so that user will not change the length, width

a) i will find a way to transform screen coordinates to pdf rectangle coordinates(#problem 2)

b) then i fill fetch text from those coordinates

c) then i will find color and other properties of that text

but i am sure ,there must be a easy way .I tried to find help but was unable to find such help. Kindly provide related documentation and a help to figure out starting point to start a task.

Charlie
  • 4,827
  • 2
  • 31
  • 55
  • Are you using [WebViewer](https://www.pdftron.com/webviewer/index.html) or [PDFViewCtrl](http://www.pdftron.com/pdfnet/docs/PDFNet/?topic=html/T_pdftron_PDF_PDFViewCtrl.htm)? – Ryan Jan 27 '15 at 18:54
  • @Ryan i am thinking of using webbrowser control ,because i didn't knew about WebViewer or PDFViewCtrl – Charlie Jan 27 '15 at 19:11
  • Can you post a link to the "webbrowser" control you are talking about? – Ryan Jan 27 '15 at 21:58
  • @Ryan I have not started using any technology of pdf tron , I have simply dragged the webbrowser control on Form and set its "navigated" property to the address of pdf unfortunately it is not interactive – Charlie Jan 28 '15 at 07:27
  • If you are using the [Forms.WebBrowser](https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser%28v=vs.110%29.aspx) class, and that is displaying a PDF when passed a URL, then it is using which ever PDF viewer you have associated with IE. It would not be using PDFTron's PDFViewCtrl class. Did you download the PDFNet .Net SDK, and you added a WebBrowser to one of the samples? You cannot use PDFNet PDFViewCtrl in a browser. You can use PDFTron's WebViewer. There is PDFViewCtrl.OpenURL, which allows you to view a PDF on a web server, and you can do all of your requirements there. – Ryan Jan 28 '15 at 19:28

1 Answers1

1

This is not possible using webbrowser but there is an alternative using PDFViewCtrl.

1) add control in toolbox by browsing PDFNET.dll

2) its better not to drag and drop the control ,alternatively initialize pdfviewctrl in after initializeComponent();

3) Add these lines to give user option of selection

        pdfViewCtrl1.SetDoc(doc);
        pdfViewCtrl1.SetToolMode(pdftron.PDF.PDFViewCtrl.ToolMode.e_text_rect_select);

4)Add this code behind the click event of start button so that user tell the program that he/she has selected text.

            int pagenumber = pdfViewCtrl1.GetCurrentPage();
            if (pdfViewCtrl1.HasSelectionOnPage(pagenumber))
            {
                pdftron.PDF.PDFViewCtrl.Selection selection = pdfViewCtrl1.GetSelection();
                string HTML = selection.GetAsHtml();
                HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(HTML);
                double[] coordinates = selection.GetQuads();
                Rect rect = new Rect(coordinates[6], coordinates[7], coordinates[2], coordinates[3]);
           }

you will get everything in html else you have text and coordinates so you can find more information ,

Find samples of code on http://www.pdftron.com/pdfnet/samplecode.html

Charlie
  • 4,827
  • 2
  • 31
  • 55