Click here to Skip to main content
15,909,091 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a class library and in this class library I create a web browser control, add html to it and then call the print function.

This doesn't seem to print anything and I wonder if someone could help me?
Doing this as a windows application seems to work fine however as soon as I convert it to a class library it doesn't seem to like it.
I heard (as I was searching for an answer) that in a class library you cannot print from a web browser control.

If this is the case how could I accomplish (an alternative way) the same task of printing an html page?

Here is my code:
VB
Private Function StartPrint(ByVal htmlstring As String) As Integer
     Try
         Dim objbrowser As New WebBrowser
         objbrowser.DocumentText = htmlstring
         objbrowser.Print()
         objbrowser.Dispose()
         Return 0
     Catch ex As Exception
         Return -1
     End Try
 End Function


Thank-you.
Posted

1 solution

The WebBrowser control MUST be put on a form in order to work.
 
Share this answer
 
Comments
Willtwinny 22-Mar-14 19:40pm    
I actually tried placing the WebBrowser control on a form, and then in the properties of the solution changed it to a class library. Still it didn't work.

Have you got any alternative solutions? (I.E. Not using a WebBrowser control - something else and be able to keep it as a class library but be able to print out websites/webpages/html ?)
Dave Kreskowiak 22-Mar-14 20:34pm    
Was this library used in a Windows Forms app and was the form you put it on visible?? If not, it's not going to work.

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