Solved

printing a html file from a vb.net application

Posted on 2010-08-24
8
324 Views
Last Modified: 2012-05-10
Hi,

Say I have an html file at c:somefile.html and I want to print it.

I dont want to display it at all.

Can someone get me going on this as is an urgent requirement.

Thanks
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 33510629
http://www.dotnet4all.com/Dot-Net-Books/2004/09/printing-webpages-with-vbnet.html

1. Add Reference - Microsoft.mshtml
2. Open a form and add in an invisible com object named: Microsoft Web Browser

--
Alain
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
        Dim sPrintEm As Integer = 1
        Dim eQuery As SHDocVw.OLECMDF

        AxWebBrowser1.Navigate("http://www.google.com")

        eQuery = AxWebBrowser1.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT)
        If Err.Number = 0 Then
            If eQuery And SHDocVw.OLECMDF.OLECMDF_ENABLED Then
                Select Case sPrintEm
                    Case "1"
                       
AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, 0, 0)
                    Case "2"
                       
AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
                End Select
            Else
                MsgBox("The Print command is currently disabled.")
            End If
        End If
    End Sub

Open in new window

0
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 33510743
You are going way out of your way doing it that way in vb.net. Try this instead.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim browser As New WebBrowser
    browser.Navigate("http://google.com")
    AddHandler browser.Navigated, AddressOf com
  End Sub

  Private Sub com(ByVal sender As Object, ByVal e As EventArgs)
    With CType(sender, WebBrowser)
      RemoveHandler .Navigated, AddressOf com
      .Print()
    End With
  End Sub

Open in new window

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33511156
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:scm0sml
ID: 33511349
wellhole that looks spot on.

I haven't got a printer set up on the machine I am on at the moment but it printed to pdf etc.

Would you expect that to prompt me as I don't really want it to? If so can I stop it?
0
 
LVL 9

Expert Comment

by:wellhole
ID: 33511431
Since you're printing to pdf, your PDF printer is prompting you not your application. If your default printer is set to a normal printer, it will not prompt.
0
 
LVL 28

Expert Comment

by:Ark
ID: 33517328
OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER means webbrowser will show standard print dialog where you can choose printer, printing area, copies etc. To skip this dialog and use default printer/settings use OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER
0
 

Author Comment

by:scm0sml
ID: 33518985
ok good stuff.

my last question is the page 1 of 1 etc and the file name at the bottom of the page.

Do I have to use the ie settings to stop this or can i do it from my code?
0
 
LVL 28

Expert Comment

by:Ark
ID: 33527864
   Public Class IE_PageSettings
        Public header As String
        Public footer As String
        Public Sub New(ByVal _header As String, ByVal _footer As String)
            header = _header
            footer = _footer
        End Sub
    End Class

    Public Property IEPageSettings() As IE_PageSettings
        Get
            Dim IERegKey As RegistryKey
            IERegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", True)
            Dim ips As New IE_PageSettings(IERegKey.GetValue("header", 0).ToString, IERegKey.GetValue("footer", 0).ToString)
            IERegKey.Close()
            Return ips
        End Get
        Set(ByVal value As IE_PageSettings)
            Dim IERegKey As RegistryKey
            IERegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", True)
            IERegKey.SetValue("header", value.header)
            IERegKey.SetValue("footer", value.footer)
            IERegKey.Flush()
            IERegKey.Close()
        End Set
    End Property

'Using
Dim ips as new IE_PageSettings(""This is page header,"This is page footer") 'or use IE coimmands like &w&bPage &p of &P or leave them blank
Me.IEPageSettings=ips
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question