Click here to Skip to main content
15,883,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need To show the Selected text from a pdf document shown in a webbrowser control in vb.net windows application.

i tried following code but selected document is coming null alwasys

WebBrowser1.Navigate("D:\Madhu\Documents\Excel-3-Formulas-and-Functions.pdf")

Dim doc As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument
Dim currentSelection As mshtml.IHTMLSelectionObject = doc.selection

If currentSelection IsNot Nothing Then
Dim range As mshtml.IHTMLTxtRange = currentSelection.createRange

If range IsNot Nothing Then
MessageBox.Show(range.text)
End If
End If
Posted

1 solution

Yeah, it's coming up null. You haven't given the user any time to select anything!

Your code is navigating to a document and then immediately trying to use a selection that doesn't exist yet!
 
Share this answer
 
Comments
Madhukumar N 6-Feb-14 4:56am    
So how can i code for it so that it will take the selected text??
Dave Kreskowiak 6-Feb-14 9:36am    
You have to display the page and do nothing. Only when the user selects text can you do anything. The WebBrowser does not expose any events that tell you when the user selected text in the control. This means the user will have to select some text then click a button or something to kick off your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900