Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

printing a html file from a vb.net application

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
scm0sml
Asked:
scm0sml
  • 2
  • 2
  • 2
  • +2
1 Solution
 
alainbrydenCommented:
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
 
wellholeCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
scm0smlAuthor Commented:
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
 
wellholeCommented:
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
 
ArkCommented:
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
 
scm0smlAuthor Commented:
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
 
ArkCommented:
   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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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