Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Printing.

Printing.

Scheduled Pinned Locked Moved Visual Basic
htmlhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Lintott
    wrote on last edited by
    #1

    Hi I am currently working on a app that prints a html invoice using Internet Explorer. as follows

    Dim internetExplorer As New SHDocVw.InternetExplorerClass()
    Dim webBrowser As SHDocVw.IWebBrowser2 = CType(internetExplorer, SHDocVw.IWebBrowser2)
    '// Make the web browser visible. //
    webBrowser.Visible = False
    '// Display empty page so we have something to manipulate.
    Dim noValue As Object = System.Reflection.Missing.Value
    webBrowser.Navigate("file://" + fileName, noValue, noValue, noValue, noValue)
    Threading.Thread.Sleep(1000)
    '// Get access to the webbrowser's document.
    Dim htmlDoc As mshtml.IHTMLDocument2 = internetExplorer.Document
    Dim o As Object = ""

        htmlDoc.execCommand("Print", False, o)
        htmlDoc.close()
    

    I read in the documentation that one can set a value for nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER for the dialog. I just can't seem to figure out where to set it. All help greatly appreaciated. Tx

    Stephen Lintott Bsc IT (RAU)

    D 1 Reply Last reply
    0
    • S Stephen Lintott

      Hi I am currently working on a app that prints a html invoice using Internet Explorer. as follows

      Dim internetExplorer As New SHDocVw.InternetExplorerClass()
      Dim webBrowser As SHDocVw.IWebBrowser2 = CType(internetExplorer, SHDocVw.IWebBrowser2)
      '// Make the web browser visible. //
      webBrowser.Visible = False
      '// Display empty page so we have something to manipulate.
      Dim noValue As Object = System.Reflection.Missing.Value
      webBrowser.Navigate("file://" + fileName, noValue, noValue, noValue, noValue)
      Threading.Thread.Sleep(1000)
      '// Get access to the webbrowser's document.
      Dim htmlDoc As mshtml.IHTMLDocument2 = internetExplorer.Document
      Dim o As Object = ""

          htmlDoc.execCommand("Print", False, o)
          htmlDoc.close()
      

      I read in the documentation that one can set a value for nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER for the dialog. I just can't seem to figure out where to set it. All help greatly appreaciated. Tx

      Stephen Lintott Bsc IT (RAU)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Stephen Lintott wrote:

      webBrowser.Navigate("file://" + fileName, noValue, noValue, noValue, noValue) Threading.Thread.Sleep(1000)

      The Thread.Sleep line is of no use. It's making the improper assumption that the page takes, at MOST, 1 second to load. It's better to check the Busy property every so often to know when the browser is ready. You can't use that trick with the .NET version of the WebBrowser control. You have to use the COM server that IE exposes directly to do that. A sample of which can be found here[^]. The code is in C#, but is easily converted to VB.NET using any online code conversion utility or, even better, done by hand.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Stephen Lintott wrote:

        webBrowser.Navigate("file://" + fileName, noValue, noValue, noValue, noValue) Threading.Thread.Sleep(1000)

        The Thread.Sleep line is of no use. It's making the improper assumption that the page takes, at MOST, 1 second to load. It's better to check the Busy property every so often to know when the browser is ready. You can't use that trick with the .NET version of the WebBrowser control. You have to use the COM server that IE exposes directly to do that. A sample of which can be found here[^]. The code is in C#, but is easily converted to VB.NET using any online code conversion utility or, even better, done by hand.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        S Offline
        S Offline
        Stephen Lintott
        wrote on last edited by
        #3

        Thats all fine and good but it doesn't answer the original question. Any help with that?

        Stephen Lintott Bsc IT (RAU)

        D 1 Reply Last reply
        0
        • S Stephen Lintott

          Thats all fine and good but it doesn't answer the original question. Any help with that?

          Stephen Lintott Bsc IT (RAU)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Thanks for down-voting me, and YES, it DOES answer the original question. You cannot use the .NET WebBrowser control to do what you want. You have to use the unwrapped COM server IE exposes, THEN you can use the technique you described. I even posted a link to a code example showing you exactly how to do it. So, how did that not answer the original post?

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          S 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Thanks for down-voting me, and YES, it DOES answer the original question. You cannot use the .NET WebBrowser control to do what you want. You have to use the unwrapped COM server IE exposes, THEN you can use the technique you described. I even posted a link to a code example showing you exactly how to do it. So, how did that not answer the original post?

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            S Offline
            S Offline
            Stephen Lintott
            wrote on last edited by
            #5

            Thanks.

            Stephen Lintott Bsc IT (RAU)

            S 1 Reply Last reply
            0
            • S Stephen Lintott

              Thanks.

              Stephen Lintott Bsc IT (RAU)

              S Offline
              S Offline
              Stephen Lintott
              wrote on last edited by
              #6

              Thanks for all the help. I tryed it and it worked. Sorry for the vote. I misread your answer and acted on that. If I could take it back I would

              Stephen Lintott Bsc IT (RAU)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups