• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 865
  • Last Modified:

Print web page in VB.NET Console Application

Hello, I am struggling to print a web page from a VB.NET terminal application. Basically, when our system sees a command in the database, it prints off a web page based on the value of that command. The problem I am having, is calling a web browser control gives me an ActiveX error about the application not having multiple threads.

Any code snippets for this would be really appreciated.
0
Benji_
Asked:
Benji_
  • 3
  • 3
1 Solution
 
rogerardCommented:
I just did a test in my vb.net 2005.  I added a WebBrowser control to the form, set it the url to both a url and to a html file, then executed
Me.WebBrowser1.Print()
for both types of pages and it printed find.  Are you trying to print it from a background worker?
0
 
rogerardCommented:
If trying to print from a thread, implement something similar to this:
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.WebBrowser1.Print()
    If Me.WebBrowser1.InvokeRequired Then
      Me.WebBrowser1.Invoke(New MethodInvoker(AddressOf printbrowser))
    Else
      WebBrowser1.Print()
    End If
  End Sub

  Private Sub printbrowser()
    Me.WebBrowser1.Print()
  End Sub

Open in new window

0
 
rogerardCommented:
delete the first me.webbrowser1.print from the code above at line 2.  I forgot to remove it.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Benji_Author Commented:
Sorry, both of you seem to have missed (though this is my fault) that this application is a Terminal application, or a Console application in VB.NET terms. Sorry, but thank you for trying.
0
 
CodeCruiserCommented:
Does it have to be console app?

One option is to develop another winforms based app which you can launch from your console app. That app can use the webbrowser and print the web page.
0
 
Benji_Author Commented:
I am thinking of just moving from a console app to a winforms app. As nice as it is having a nice simple system, I think it is time to move to winforms as the solution.

Thanks for all your help.
0
 
Benji_Author Commented:
Shame there was never a full solution, but still made me see what had to be done.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now