WebBrowser Control Printing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Clark

    #1

    WebBrowser Control Printing

    Greetings,

    (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).

    I've decided to take advantage of the layout characteristics of HTML
    documents to simplify my printing tasks, but of course it's thrown up a
    whole host of new issues...

    I'm generating a multi page printable document in HTML from my app, and
    displaying it in a WebBrowser control. I've looked into using some CSS
    commands to control pagination, but nothing seems to fit the bill so far.

    I need to include a custom header/footer (imported from another HTML file)
    on every page that's printed. I also need to draw a border around each
    page. The closest I can get to the border is putting all my print-content
    inside an HTML table, which looks ugly because it doesn't close off at the
    foot of each page - it only draws its final horizontal line at the very end
    of the document.

    I tried inheriting from WebBrowser and overriding the OnPrint event, but
    this never seems to get called? I've found an example on the MSDN site, but
    it's all in C++ and seems designed around MFC.

    How can I hang on to the snazzy built-in formatting features of HTML, but
    still have control over the printed output & pagination? Help!

    Thanks in advance,
    Alex Clark




  • Colin Neller

    #2
    Re: WebBrowser Control Printing

    Alex,

    I suggest you look into Print Templates:

    http://msdn.microsoft.com/library/de...intpreview.asp

    http://msdn.microsoft.com/library/de...asp?frame=true

    --
    Colin Neller



    "Alex Clark" <honeycomb@news groups.nospam> wrote in message
    news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..[color=blue]
    > Greetings,
    >
    > (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
    >
    > I've decided to take advantage of the layout characteristics of HTML
    > documents to simplify my printing tasks, but of course it's thrown up a
    > whole host of new issues...
    >
    > I'm generating a multi page printable document in HTML from my app, and
    > displaying it in a WebBrowser control. I've looked into using some CSS
    > commands to control pagination, but nothing seems to fit the bill so far.
    >
    > I need to include a custom header/footer (imported from another HTML file)
    > on every page that's printed. I also need to draw a border around each
    > page. The closest I can get to the border is putting all my print-content
    > inside an HTML table, which looks ugly because it doesn't close off at the
    > foot of each page - it only draws its final horizontal line at the very
    > end of the document.
    >
    > I tried inheriting from WebBrowser and overriding the OnPrint event, but
    > this never seems to get called? I've found an example on the MSDN site,
    > but it's all in C++ and seems designed around MFC.
    >
    > How can I hang on to the snazzy built-in formatting features of HTML, but
    > still have control over the printed output & pagination? Help!
    >
    > Thanks in advance,
    > Alex Clark
    >
    >
    >
    >[/color]


    Comment

    • Alex Clark

      #3
      Re: WebBrowser Control Printing

      Hi Colin,

      These look really useful but the article seems to imply that this is only
      possible when using C++. I know it was written a long time ago (before
      ..NET) but it doesn't seem as though it could be very VB.NET friendly :-(

      Thanks,
      Alex



      "Colin Neller" <cneller@gmail. com> wrote in message
      news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...[color=blue]
      > Alex,
      >
      > I suggest you look into Print Templates:
      >
      > http://msdn.microsoft.com/library/de...intpreview.asp
      >
      > http://msdn.microsoft.com/library/de...asp?frame=true
      >
      > --
      > Colin Neller
      > http://www.colinneller.com/blog
      >
      >
      > "Alex Clark" <honeycomb@news groups.nospam> wrote in message
      > news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..[color=green]
      >> Greetings,
      >>
      >> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
      >>
      >> I've decided to take advantage of the layout characteristics of HTML
      >> documents to simplify my printing tasks, but of course it's thrown up a
      >> whole host of new issues...
      >>
      >> I'm generating a multi page printable document in HTML from my app, and
      >> displaying it in a WebBrowser control. I've looked into using some CSS
      >> commands to control pagination, but nothing seems to fit the bill so far.
      >>
      >> I need to include a custom header/footer (imported from another HTML
      >> file) on every page that's printed. I also need to draw a border around
      >> each page. The closest I can get to the border is putting all my
      >> print-content inside an HTML table, which looks ugly because it doesn't
      >> close off at the foot of each page - it only draws its final horizontal
      >> line at the very end of the document.
      >>
      >> I tried inheriting from WebBrowser and overriding the OnPrint event, but
      >> this never seems to get called? I've found an example on the MSDN site,
      >> but it's all in C++ and seems designed around MFC.
      >>
      >> How can I hang on to the snazzy built-in formatting features of HTML, but
      >> still have control over the printed output & pagination? Help!
      >>
      >> Thanks in advance,
      >> Alex Clark
      >>
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Colin Neller

        #4
        Re: WebBrowser Control Printing

        Alex,

        Print Templates are certainly non-trivial, but they do not require C++. The
        key line of code from the example I gave is:

        pCmdTarg->Exec(&CGID_MSH TML,
        IDM_PRINT,
        OLECMDEXECOPT_P ROMPTUSER,
        &vTemplatePa th,
        NULL);

        Basically, what you would do in .NET is cast your IWebBrowser2 object to an
        IOleCommandTarg et and call the Exec method (as above) passing in the path to
        your print template (vTemplatePath in the above example.) The vast majority
        of the Print Template code will be written in JavaScript.

        Honestly, I think you would be better investing in a report writing tool
        (e.g. ActiveReports) The path you are headed down with the WB is not an
        easy one.

        --
        Colin Neller



        "Alex Clark" <honeycomb@news groups.nospam> wrote in message
        news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > Hi Colin,
        >
        > These look really useful but the article seems to imply that this is only
        > possible when using C++. I know it was written a long time ago (before
        > .NET) but it doesn't seem as though it could be very VB.NET friendly :-(
        >
        > Thanks,
        > Alex
        >
        >
        >
        > "Colin Neller" <cneller@gmail. com> wrote in message
        > news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...[color=green]
        >> Alex,
        >>
        >> I suggest you look into Print Templates:
        >>
        >> http://msdn.microsoft.com/library/de...intpreview.asp
        >>
        >> http://msdn.microsoft.com/library/de...asp?frame=true
        >>
        >> --
        >> Colin Neller
        >> http://www.colinneller.com/blog
        >>
        >>
        >> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
        >> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..[color=darkred]
        >>> Greetings,
        >>>
        >>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
        >>>
        >>> I've decided to take advantage of the layout characteristics of HTML
        >>> documents to simplify my printing tasks, but of course it's thrown up a
        >>> whole host of new issues...
        >>>
        >>> I'm generating a multi page printable document in HTML from my app, and
        >>> displaying it in a WebBrowser control. I've looked into using some CSS
        >>> commands to control pagination, but nothing seems to fit the bill so
        >>> far.
        >>>
        >>> I need to include a custom header/footer (imported from another HTML
        >>> file) on every page that's printed. I also need to draw a border around
        >>> each page. The closest I can get to the border is putting all my
        >>> print-content inside an HTML table, which looks ugly because it doesn't
        >>> close off at the foot of each page - it only draws its final horizontal
        >>> line at the very end of the document.
        >>>
        >>> I tried inheriting from WebBrowser and overriding the OnPrint event, but
        >>> this never seems to get called? I've found an example on the MSDN site,
        >>> but it's all in C++ and seems designed around MFC.
        >>>
        >>> How can I hang on to the snazzy built-in formatting features of HTML,
        >>> but still have control over the printed output & pagination? Help!
        >>>
        >>> Thanks in advance,
        >>> Alex Clark
        >>>
        >>>
        >>>
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Alex Clark

          #5
          Re: WebBrowser Control Printing

          Hi Colin,

          After further investigation on the web I'm still fairly convinced this is a
          C++ only option, due to the wrapping of COM Variant types - .NET interop
          will, apparently, not support this at all, unless something has changed as
          of 2.0.

          I think you're right about the report-writing avenue however. It's a shame,
          as what I'm trying to do would be ideally suited to generating a quick HTML
          file and printing it, if only I could have slightly more control over the
          printed output :-(

          Thanks for your help,
          Alex Clark




          "Colin Neller" <cneller@gmail. com> wrote in message
          news:OkLFEw4QGH A.5500@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Alex,
          >
          > Print Templates are certainly non-trivial, but they do not require C++.
          > The key line of code from the example I gave is:
          >
          > pCmdTarg->Exec(&CGID_MSH TML,
          > IDM_PRINT,
          > OLECMDEXECOPT_P ROMPTUSER,
          > &vTemplatePa th,
          > NULL);
          >
          > Basically, what you would do in .NET is cast your IWebBrowser2 object to
          > an IOleCommandTarg et and call the Exec method (as above) passing in the
          > path to your print template (vTemplatePath in the above example.) The
          > vast majority of the Print Template code will be written in JavaScript.
          >
          > Honestly, I think you would be better investing in a report writing tool
          > (e.g. ActiveReports) The path you are headed down with the WB is not an
          > easy one.
          >
          > --
          > Colin Neller
          > http://www.colinneller.com/blog
          >
          >
          > "Alex Clark" <honeycomb@news groups.nospam> wrote in message
          > news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..[color=green]
          >> Hi Colin,
          >>
          >> These look really useful but the article seems to imply that this is only
          >> possible when using C++. I know it was written a long time ago (before
          >> .NET) but it doesn't seem as though it could be very VB.NET friendly :-(
          >>
          >> Thanks,
          >> Alex
          >>
          >>
          >>
          >> "Colin Neller" <cneller@gmail. com> wrote in message
          >> news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...[color=darkred]
          >>> Alex,
          >>>
          >>> I suggest you look into Print Templates:
          >>>
          >>> http://msdn.microsoft.com/library/de...intpreview.asp
          >>>
          >>> http://msdn.microsoft.com/library/de...asp?frame=true
          >>>
          >>> --
          >>> Colin Neller
          >>> http://www.colinneller.com/blog
          >>>
          >>>
          >>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
          >>> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..
          >>>> Greetings,
          >>>>
          >>>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
          >>>>
          >>>> I've decided to take advantage of the layout characteristics of HTML
          >>>> documents to simplify my printing tasks, but of course it's thrown up a
          >>>> whole host of new issues...
          >>>>
          >>>> I'm generating a multi page printable document in HTML from my app, and
          >>>> displaying it in a WebBrowser control. I've looked into using some CSS
          >>>> commands to control pagination, but nothing seems to fit the bill so
          >>>> far.
          >>>>
          >>>> I need to include a custom header/footer (imported from another HTML
          >>>> file) on every page that's printed. I also need to draw a border
          >>>> around each page. The closest I can get to the border is putting all
          >>>> my print-content inside an HTML table, which looks ugly because it
          >>>> doesn't close off at the foot of each page - it only draws its final
          >>>> horizontal line at the very end of the document.
          >>>>
          >>>> I tried inheriting from WebBrowser and overriding the OnPrint event,
          >>>> but this never seems to get called? I've found an example on the MSDN
          >>>> site, but it's all in C++ and seems designed around MFC.
          >>>>
          >>>> How can I hang on to the snazzy built-in formatting features of HTML,
          >>>> but still have control over the printed output & pagination? Help!
          >>>>
          >>>> Thanks in advance,
          >>>> Alex Clark
          >>>>
          >>>>
          >>>>
          >>>>
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • TerryFei

            #6
            Re: WebBrowser Control Printing

            Hi Alex,
            Thanks for your response!
            [color=blue][color=green]
            >>After further investigation on the web I'm still fairly convinced this is[/color][/color]
            a[color=blue][color=green]
            >>C++ only option, due to the wrapping of COM Variant types - .NET interop
            >>will, apparently, not support this at all, unless something has changed[/color][/color]
            as[color=blue][color=green]
            >>.of 2.0.[/color][/color]
            WebBrowser control provide us IWebBrowser2 com-interface and we can use
            this interface to control WebBrowser control's operation. IWebBrowser2 is
            an IDispatch interface, in a word, this is a dual-interface, so we can use
            it in C++ and VB. If your environment is .Net, we could use it with
            Interoperabilit y mechanism. I hope the following articles will be helpful
            for you:
            Title: Using the WebBrowser control in .NET
            URL: http://www.codeproject.com/csharp/webbrowser.asp

            Title: Using MSHTML Advanced Hosting Interfaces
            URL: http://www.codeproject.com/csharp/advhost.asp

            Title: Microsoft Web Browser Automation using C#
            URL: http://www.codeproject.com/csharp/mshtml_automation.asp

            I hope the above information is helpful for you. If there is anything I
            can do for you, please feel free to let me know. Thanks and have a nice day!

            Best Regards,

            Terry Fei[MSFT]
            Microsoft Community Support
            Get Secure! www.microsoft.com/security
            (This posting is provided "AS IS", with no warranties, and confers no
            rights.)



            --------------------[color=blue]
            >Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
            >From: "Alex Clark" <honeycomb@news groups.nospam>
            >References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
            <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
            <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
            <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>[color=blue]
            >Subject: Re: WebBrowser Control Printing
            >Date: Thu, 9 Mar 2006 16:22:23 -0000
            >Lines: 116
            >X-Priority: 3
            >X-MSMail-Priority: Normal
            >X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
            >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
            >X-RFC2646: Format=Flowed; Response
            >Message-ID: <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
            >Newsgroups: microsoft.publi c.dotnet.langua ges.vb
            >NNTP-Posting-Host: host86-134-248-72.range86-134.btcentralpl us.com[/color]
            86.134.248.72[color=blue]
            >Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
            >Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321151
            >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
            >
            >Hi Colin,
            >
            >After further investigation on the web I'm still fairly convinced this is[/color]
            a[color=blue]
            >C++ only option, due to the wrapping of COM Variant types - .NET interop
            >will, apparently, not support this at all, unless something has changed as
            >of 2.0.
            >
            >I think you're right about the report-writing avenue however. It's a[/color]
            shame,[color=blue]
            >as what I'm trying to do would be ideally suited to generating a quick[/color]
            HTML[color=blue]
            >file and printing it, if only I could have slightly more control over the
            >printed output :-(
            >
            >Thanks for your help,
            >Alex Clark
            >
            >
            >
            >
            >"Colin Neller" <cneller@gmail. com> wrote in message
            >news:OkLFEw4QG HA.5500@TK2MSFT NGP12.phx.gbl.. .[color=green]
            >> Alex,
            >>
            >> Print Templates are certainly non-trivial, but they do not require C++.
            >> The key line of code from the example I gave is:
            >>
            >> pCmdTarg->Exec(&CGID_MSH TML,
            >> IDM_PRINT,
            >> OLECMDEXECOPT_P ROMPTUSER,
            >> &vTemplatePa th,
            >> NULL);
            >>
            >> Basically, what you would do in .NET is cast your IWebBrowser2 object to
            >> an IOleCommandTarg et and call the Exec method (as above) passing in the
            >> path to your print template (vTemplatePath in the above example.) The
            >> vast majority of the Print Template code will be written in JavaScript.
            >>
            >> Honestly, I think you would be better investing in a report writing tool
            >> (e.g. ActiveReports) The path you are headed down with the WB is not an
            >> easy one.
            >>
            >> --
            >> Colin Neller
            >> http://www.colinneller.com/blog
            >>
            >>
            >> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
            >> news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
            >>> Hi Colin,
            >>>
            >>> These look really useful but the article seems to imply that this is[/color][/color][/color]
            only[color=blue][color=green][color=darkred]
            >>> possible when using C++. I know it was written a long time ago (before
            >>> .NET) but it doesn't seem as though it could be very VB.NET friendly :-(
            >>>
            >>> Thanks,
            >>> Alex
            >>>
            >>>
            >>>
            >>> "Colin Neller" <cneller@gmail. com> wrote in message
            >>> news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...
            >>>> Alex,
            >>>>
            >>>> I suggest you look into Print Templates:
            >>>>
            >>>>[/color][/color][/color]
            http://msdn.microsoft.com/library/de...us/dnie55/html
            /beyondprintprev iew.asp[color=blue][color=green][color=darkred]
            >>>>
            >>>>[/color][/color][/color]
            http://msdn.microsoft.com/library/de...us/dnie55/html
            /printtemplate2. asp?frame=true[color=blue][color=green][color=darkred]
            >>>>
            >>>> --
            >>>> Colin Neller
            >>>> http://www.colinneller.com/blog
            >>>>
            >>>>
            >>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
            >>>> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..
            >>>>> Greetings,
            >>>>>
            >>>>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
            >>>>>
            >>>>> I've decided to take advantage of the layout characteristics of HTML
            >>>>> documents to simplify my printing tasks, but of course it's thrown up[/color][/color][/color]
            a[color=blue][color=green][color=darkred]
            >>>>> whole host of new issues...
            >>>>>
            >>>>> I'm generating a multi page printable document in HTML from my app,[/color][/color][/color]
            and[color=blue][color=green][color=darkred]
            >>>>> displaying it in a WebBrowser control. I've looked into using some[/color][/color][/color]
            CSS[color=blue][color=green][color=darkred]
            >>>>> commands to control pagination, but nothing seems to fit the bill so
            >>>>> far.
            >>>>>
            >>>>> I need to include a custom header/footer (imported from another HTML
            >>>>> file) on every page that's printed. I also need to draw a border
            >>>>> around each page. The closest I can get to the border is putting all
            >>>>> my print-content inside an HTML table, which looks ugly because it
            >>>>> doesn't close off at the foot of each page - it only draws its final
            >>>>> horizontal line at the very end of the document.
            >>>>>
            >>>>> I tried inheriting from WebBrowser and overriding the OnPrint event,
            >>>>> but this never seems to get called? I've found an example on the[/color][/color][/color]
            MSDN[color=blue][color=green][color=darkred]
            >>>>> site, but it's all in C++ and seems designed around MFC.
            >>>>>
            >>>>> How can I hang on to the snazzy built-in formatting features of HTML,
            >>>>> but still have control over the printed output & pagination? Help!
            >>>>>
            >>>>> Thanks in advance,
            >>>>> Alex Clark
            >>>>>
            >>>>>
            >>>>>
            >>>>>
            >>>>
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >
            >[/color]

            Comment

            • Alex Clark

              #7
              Re: WebBrowser Control Printing

              Hi Terry,

              Any chance you could give me some example code in either C# or VB.NET for
              using Print Templates with the WebBrowser control? I'm using .NET 2.0 and
              my clients will have IE6 installed as a minimum. A simple example just to
              get me started would be much appreciated.

              Many thanks,
              Alex


              ""TerryFei" " <v-terryf@online.m icrosoft.com> wrote in message
              news:npn7UC0RGH A.4824@TK2MSFTN GXA03.phx.gbl.. .[color=blue]
              > Hi Alex,
              > Thanks for your response!
              >[color=green][color=darkred]
              >>>After further investigation on the web I'm still fairly convinced this is[/color][/color]
              > a[color=green][color=darkred]
              >>>C++ only option, due to the wrapping of COM Variant types - .NET interop
              >>>will, apparently, not support this at all, unless something has changed[/color][/color]
              > as[color=green][color=darkred]
              >>>.of 2.0.[/color][/color]
              > WebBrowser control provide us IWebBrowser2 com-interface and we can use
              > this interface to control WebBrowser control's operation. IWebBrowser2 is
              > an IDispatch interface, in a word, this is a dual-interface, so we can use
              > it in C++ and VB. If your environment is .Net, we could use it with
              > Interoperabilit y mechanism. I hope the following articles will be helpful
              > for you:
              > Title: Using the WebBrowser control in .NET
              > URL: http://www.codeproject.com/csharp/webbrowser.asp
              >
              > Title: Using MSHTML Advanced Hosting Interfaces
              > URL: http://www.codeproject.com/csharp/advhost.asp
              >
              > Title: Microsoft Web Browser Automation using C#
              > URL: http://www.codeproject.com/csharp/mshtml_automation.asp
              >
              > I hope the above information is helpful for you. If there is anything I
              > can do for you, please feel free to let me know. Thanks and have a nice
              > day!
              >
              > Best Regards,
              >
              > Terry Fei[MSFT]
              > Microsoft Community Support
              > Get Secure! www.microsoft.com/security
              > (This posting is provided "AS IS", with no warranties, and confers no
              > rights.)
              >
              >
              >
              > --------------------[color=green]
              >>Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
              >>From: "Alex Clark" <honeycomb@news groups.nospam>
              >>References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
              > <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
              > <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
              > <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>[color=green]
              >>Subject: Re: WebBrowser Control Printing
              >>Date: Thu, 9 Mar 2006 16:22:23 -0000
              >>Lines: 116
              >>X-Priority: 3
              >>X-MSMail-Priority: Normal
              >>X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
              >>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
              >>X-RFC2646: Format=Flowed; Response
              >>Message-ID: <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
              >>Newsgroups: microsoft.publi c.dotnet.langua ges.vb
              >>NNTP-Posting-Host: host86-134-248-72.range86-134.btcentralpl us.com[/color]
              > 86.134.248.72[color=green]
              >>Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
              >>Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321151
              >>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
              >>
              >>Hi Colin,
              >>
              >>After further investigation on the web I'm still fairly convinced this is[/color]
              > a[color=green]
              >>C++ only option, due to the wrapping of COM Variant types - .NET interop
              >>will, apparently, not support this at all, unless something has changed as
              >>of 2.0.
              >>
              >>I think you're right about the report-writing avenue however. It's a[/color]
              > shame,[color=green]
              >>as what I'm trying to do would be ideally suited to generating a quick[/color]
              > HTML[color=green]
              >>file and printing it, if only I could have slightly more control over the
              >>printed output :-(
              >>
              >>Thanks for your help,
              >>Alex Clark
              >>
              >>
              >>
              >>
              >>"Colin Neller" <cneller@gmail. com> wrote in message
              >>news:OkLFEw4Q GHA.5500@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
              >>> Alex,
              >>>
              >>> Print Templates are certainly non-trivial, but they do not require C++.
              >>> The key line of code from the example I gave is:
              >>>
              >>> pCmdTarg->Exec(&CGID_MSH TML,
              >>> IDM_PRINT,
              >>> OLECMDEXECOPT_P ROMPTUSER,
              >>> &vTemplatePa th,
              >>> NULL);
              >>>
              >>> Basically, what you would do in .NET is cast your IWebBrowser2 object to
              >>> an IOleCommandTarg et and call the Exec method (as above) passing in the
              >>> path to your print template (vTemplatePath in the above example.) The
              >>> vast majority of the Print Template code will be written in JavaScript.
              >>>
              >>> Honestly, I think you would be better investing in a report writing tool
              >>> (e.g. ActiveReports) The path you are headed down with the WB is not an
              >>> easy one.
              >>>
              >>> --
              >>> Colin Neller
              >>> http://www.colinneller.com/blog
              >>>
              >>>
              >>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
              >>> news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..
              >>>> Hi Colin,
              >>>>
              >>>> These look really useful but the article seems to imply that this is[/color][/color]
              > only[color=green][color=darkred]
              >>>> possible when using C++. I know it was written a long time ago (before
              >>>> .NET) but it doesn't seem as though it could be very VB.NET friendly
              >>>> :-(
              >>>>
              >>>> Thanks,
              >>>> Alex
              >>>>
              >>>>
              >>>>
              >>>> "Colin Neller" <cneller@gmail. com> wrote in message
              >>>> news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...
              >>>>> Alex,
              >>>>>
              >>>>> I suggest you look into Print Templates:
              >>>>>
              >>>>>[/color][/color]
              > http://msdn.microsoft.com/library/de...us/dnie55/html
              > /beyondprintprev iew.asp[color=green][color=darkred]
              >>>>>
              >>>>>[/color][/color]
              > http://msdn.microsoft.com/library/de...us/dnie55/html
              > /printtemplate2. asp?frame=true[color=green][color=darkred]
              >>>>>
              >>>>> --
              >>>>> Colin Neller
              >>>>> http://www.colinneller.com/blog
              >>>>>
              >>>>>
              >>>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
              >>>>> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..
              >>>>>> Greetings,
              >>>>>>
              >>>>>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
              >>>>>>
              >>>>>> I've decided to take advantage of the layout characteristics of HTML
              >>>>>> documents to simplify my printing tasks, but of course it's thrown up[/color][/color]
              > a[color=green][color=darkred]
              >>>>>> whole host of new issues...
              >>>>>>
              >>>>>> I'm generating a multi page printable document in HTML from my app,[/color][/color]
              > and[color=green][color=darkred]
              >>>>>> displaying it in a WebBrowser control. I've looked into using some[/color][/color]
              > CSS[color=green][color=darkred]
              >>>>>> commands to control pagination, but nothing seems to fit the bill so
              >>>>>> far.
              >>>>>>
              >>>>>> I need to include a custom header/footer (imported from another HTML
              >>>>>> file) on every page that's printed. I also need to draw a border
              >>>>>> around each page. The closest I can get to the border is putting all
              >>>>>> my print-content inside an HTML table, which looks ugly because it
              >>>>>> doesn't close off at the foot of each page - it only draws its final
              >>>>>> horizontal line at the very end of the document.
              >>>>>>
              >>>>>> I tried inheriting from WebBrowser and overriding the OnPrint event,
              >>>>>> but this never seems to get called? I've found an example on the[/color][/color]
              > MSDN[color=green][color=darkred]
              >>>>>> site, but it's all in C++ and seems designed around MFC.
              >>>>>>
              >>>>>> How can I hang on to the snazzy built-in formatting features of HTML,
              >>>>>> but still have control over the printed output & pagination? Help!
              >>>>>>
              >>>>>> Thanks in advance,
              >>>>>> Alex Clark
              >>>>>>
              >>>>>>
              >>>>>>
              >>>>>>
              >>>>>
              >>>>>
              >>>>
              >>>>
              >>>
              >>>[/color]
              >>
              >>
              >>[/color]
              >[/color]


              Comment

              • TerryFei

                #8
                Re: WebBrowser Control Printing

                Hi Alex,
                After researching, we can use WebBrowser to print, just like the following
                code:
                m_axWebBrowser. ExecWB(SHDocVw. OLECMDID.OLECMD ID_PRINT,
                SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DODEFAULT ,
                ref o, ref o);

                I also the following article will be helpful for you:
                Title: Using the WebBrowser control in .NET
                URL: http://www.codeproject.com/csharp/webbrowser.asp

                Thanks for your understanding!

                Best Regards,

                Terry Fei[MSFT]
                Microsoft Community Support
                Get Secure! www.microsoft.com/security
                (This posting is provided "AS IS", with no warranties, and confers no
                rights.)

                --------------------[color=blue]
                >Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                >From: "Alex Clark" <honeycomb@news groups.nospam>
                >References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
                <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>
                <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                <npn7UC0RGHA.48 24@TK2MSFTNGXA0 3.phx.gbl>[color=blue]
                >Subject: Re: WebBrowser Control Printing
                >Date: Wed, 15 Mar 2006 11:44:28 -0000
                >Lines: 207
                >X-Priority: 3
                >X-MSMail-Priority: Normal
                >X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                >X-RFC2646: Format=Flowed; Original
                >Message-ID: <uYswLXCSGHA.46 00@TK2MSFTNGP11 .phx.gbl>
                >Newsgroups: microsoft.publi c.dotnet.langua ges.vb
                >NNTP-Posting-Host: host81-152-10-23.range81-152.btcentralpl us.com[/color]
                81.152.10.23[color=blue]
                >Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP11.phx. gbl
                >Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321889
                >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                >
                >Hi Terry,
                >
                >Any chance you could give me some example code in either C# or VB.NET for
                >using Print Templates with the WebBrowser control? I'm using .NET 2.0 and
                >my clients will have IE6 installed as a minimum. A simple example just to
                >get me started would be much appreciated.
                >
                >Many thanks,
                >Alex
                >
                >
                >""TerryFei" " <v-terryf@online.m icrosoft.com> wrote in message
                >news:npn7UC0RG HA.4824@TK2MSFT NGXA03.phx.gbl. ..[color=green]
                >> Hi Alex,
                >> Thanks for your response!
                >>[color=darkred]
                >>>>After further investigation on the web I'm still fairly convinced this[/color][/color][/color]
                is[color=blue][color=green]
                >> a[color=darkred]
                >>>>C++ only option, due to the wrapping of COM Variant types - .NET interop
                >>>>will, apparently, not support this at all, unless something has changed[/color]
                >> as[color=darkred]
                >>>>.of 2.0.[/color]
                >> WebBrowser control provide us IWebBrowser2 com-interface and we can use
                >> this interface to control WebBrowser control's operation. IWebBrowser2 is
                >> an IDispatch interface, in a word, this is a dual-interface, so we can[/color][/color]
                use[color=blue][color=green]
                >> it in C++ and VB. If your environment is .Net, we could use it with
                >> Interoperabilit y mechanism. I hope the following articles will be helpful
                >> for you:
                >> Title: Using the WebBrowser control in .NET
                >> URL: http://www.codeproject.com/csharp/webbrowser.asp
                >>
                >> Title: Using MSHTML Advanced Hosting Interfaces
                >> URL: http://www.codeproject.com/csharp/advhost.asp
                >>
                >> Title: Microsoft Web Browser Automation using C#
                >> URL: http://www.codeproject.com/csharp/mshtml_automation.asp
                >>
                >> I hope the above information is helpful for you. If there is anything I
                >> can do for you, please feel free to let me know. Thanks and have a nice
                >> day!
                >>
                >> Best Regards,
                >>
                >> Terry Fei[MSFT]
                >> Microsoft Community Support
                >> Get Secure! www.microsoft.com/security
                >> (This posting is provided "AS IS", with no warranties, and confers no
                >> rights.)
                >>
                >>
                >>
                >> --------------------[color=darkred]
                >>>Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                >>>From: "Alex Clark" <honeycomb@news groups.nospam>
                >>>References : <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
                >> <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                >> <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                >> <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>[color=darkred]
                >>>Subject: Re: WebBrowser Control Printing
                >>>Date: Thu, 9 Mar 2006 16:22:23 -0000
                >>>Lines: 116
                >>>X-Priority: 3
                >>>X-MSMail-Priority: Normal
                >>>X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                >>>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                >>>X-RFC2646: Format=Flowed; Response
                >>>Message-ID: <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                >>>Newsgroups : microsoft.publi c.dotnet.langua ges.vb
                >>>NNTP-Posting-Host: host86-134-248-72.range86-134.btcentralpl us.com[/color]
                >> 86.134.248.72[color=darkred]
                >>>Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
                >>>Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321151
                >>>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                >>>
                >>>Hi Colin,
                >>>
                >>>After further investigation on the web I'm still fairly convinced this is[/color]
                >> a[color=darkred]
                >>>C++ only option, due to the wrapping of COM Variant types - .NET interop
                >>>will, apparently, not support this at all, unless something has changed[/color][/color][/color]
                as[color=blue][color=green][color=darkred]
                >>>of 2.0.
                >>>
                >>>I think you're right about the report-writing avenue however. It's a[/color]
                >> shame,[color=darkred]
                >>>as what I'm trying to do would be ideally suited to generating a quick[/color]
                >> HTML[color=darkred]
                >>>file and printing it, if only I could have slightly more control over the
                >>>printed output :-(
                >>>
                >>>Thanks for your help,
                >>>Alex Clark
                >>>
                >>>
                >>>
                >>>
                >>>"Colin Neller" <cneller@gmail. com> wrote in message
                >>>news:OkLFEw4 QGHA.5500@TK2MS FTNGP12.phx.gbl ...
                >>>> Alex,
                >>>>
                >>>> Print Templates are certainly non-trivial, but they do not require C++.
                >>>> The key line of code from the example I gave is:
                >>>>
                >>>> pCmdTarg->Exec(&CGID_MSH TML,
                >>>> IDM_PRINT,
                >>>> OLECMDEXECOPT_P ROMPTUSER,
                >>>> &vTemplatePa th,
                >>>> NULL);
                >>>>
                >>>> Basically, what you would do in .NET is cast your IWebBrowser2 object[/color][/color][/color]
                to[color=blue][color=green][color=darkred]
                >>>> an IOleCommandTarg et and call the Exec method (as above) passing in the
                >>>> path to your print template (vTemplatePath in the above example.) The
                >>>> vast majority of the Print Template code will be written in JavaScript.
                >>>>
                >>>> Honestly, I think you would be better investing in a report writing[/color][/color][/color]
                tool[color=blue][color=green][color=darkred]
                >>>> (e.g. ActiveReports) The path you are headed down with the WB is not[/color][/color][/color]
                an[color=blue][color=green][color=darkred]
                >>>> easy one.
                >>>>
                >>>> --
                >>>> Colin Neller
                >>>> http://www.colinneller.com/blog
                >>>>
                >>>>
                >>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
                >>>> news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..
                >>>>> Hi Colin,
                >>>>>
                >>>>> These look really useful but the article seems to imply that this is[/color]
                >> only[color=darkred]
                >>>>> possible when using C++. I know it was written a long time ago[/color][/color][/color]
                (before[color=blue][color=green][color=darkred]
                >>>>> .NET) but it doesn't seem as though it could be very VB.NET friendly
                >>>>> :-(
                >>>>>
                >>>>> Thanks,
                >>>>> Alex
                >>>>>
                >>>>>
                >>>>>
                >>>>> "Colin Neller" <cneller@gmail. com> wrote in message
                >>>>> news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...
                >>>>>> Alex,
                >>>>>>
                >>>>>> I suggest you look into Print Templates:
                >>>>>>
                >>>>>>[/color]
                >>[/color][/color]
                http://msdn.microsoft.com/library/de...us/dnie55/html[color=blue][color=green]
                >> /beyondprintprev iew.asp[color=darkred]
                >>>>>>
                >>>>>>[/color]
                >>[/color][/color]
                http://msdn.microsoft.com/library/de...us/dnie55/html[color=blue][color=green]
                >> /printtemplate2. asp?frame=true[color=darkred]
                >>>>>>
                >>>>>> --
                >>>>>> Colin Neller
                >>>>>> http://www.colinneller.com/blog
                >>>>>>
                >>>>>>
                >>>>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
                >>>>>> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..
                >>>>>>> Greetings,
                >>>>>>>
                >>>>>>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
                >>>>>>>
                >>>>>>> I've decided to take advantage of the layout characteristics of HTML
                >>>>>>> documents to simplify my printing tasks, but of course it's thrown[/color][/color][/color]
                up[color=blue][color=green]
                >> a[color=darkred]
                >>>>>>> whole host of new issues...
                >>>>>>>
                >>>>>>> I'm generating a multi page printable document in HTML from my app,[/color]
                >> and[color=darkred]
                >>>>>>> displaying it in a WebBrowser control. I've looked into using some[/color]
                >> CSS[color=darkred]
                >>>>>>> commands to control pagination, but nothing seems to fit the bill so
                >>>>>>> far.
                >>>>>>>
                >>>>>>> I need to include a custom header/footer (imported from another HTML
                >>>>>>> file) on every page that's printed. I also need to draw a border
                >>>>>>> around each page. The closest I can get to the border is putting[/color][/color][/color]
                all[color=blue][color=green][color=darkred]
                >>>>>>> my print-content inside an HTML table, which looks ugly because it
                >>>>>>> doesn't close off at the foot of each page - it only draws its final
                >>>>>>> horizontal line at the very end of the document.
                >>>>>>>
                >>>>>>> I tried inheriting from WebBrowser and overriding the OnPrint event,
                >>>>>>> but this never seems to get called? I've found an example on the[/color]
                >> MSDN[color=darkred]
                >>>>>>> site, but it's all in C++ and seems designed around MFC.
                >>>>>>>
                >>>>>>> How can I hang on to the snazzy built-in formatting features of[/color][/color][/color]
                HTML,[color=blue][color=green][color=darkred]
                >>>>>>> but still have control over the printed output & pagination? Help!
                >>>>>>>
                >>>>>>> Thanks in advance,
                >>>>>>> Alex Clark
                >>>>>>>
                >>>>>>>
                >>>>>>>
                >>>>>>>
                >>>>>>
                >>>>>>
                >>>>>
                >>>>>
                >>>>
                >>>>
                >>>
                >>>
                >>>[/color]
                >>[/color]
                >
                >
                >[/color]

                Comment

                • Alex Clark

                  #9
                  Re: WebBrowser Control Printing

                  Hi Terry,

                  A few problems with this:

                  1) I'm using .NET 2.0 and would very much prefer to use the managed
                  WebBrowser control. Not so hard, as presumably I just need to call ExecWB
                  of the late-bound ActiveXInstance property?

                  2) Testing this example with the ActiveX version of the web-browser (i.e.
                  not using the managed control from 2.0), it does absolutely nothing at all.
                  I'm on XP Pro SP2 with IE6 and all latest service packs.

                  3) Printing in itself wasn't the problem to start with - getting the
                  web-browser control to print with a Print-Template from within a VB.NET
                  application is the problem I'm facing.

                  Please see:
                  http://msdn.microsoft.com/library/de...intpreview.asp
                  ....for an example of what I'm talking about.


                  Essentially I need a custom header, footer, and border around every HTML
                  page I'm printing from within my VB.NET WinForms application, running on
                  v2.0 of the framework.

                  IE Print Templates seem to be the only way to go on this. Can you give me
                  some example VB.NET (or C#) code that illustrates how to use print templates
                  with the managed web-browser control, if it's even possible?

                  Thanks,
                  Alex Clark







                  ""TerryFei" " <v-terryf@online.m icrosoft.com> wrote in message
                  news:PpU5OcNSGH A.5168@TK2MSFTN GXA03.phx.gbl.. .[color=blue]
                  > Hi Alex,
                  > After researching, we can use WebBrowser to print, just like the following
                  > code:
                  > m_axWebBrowser. ExecWB(SHDocVw. OLECMDID.OLECMD ID_PRINT,
                  > SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DODEFAULT ,
                  > ref o, ref o);
                  >
                  > I also the following article will be helpful for you:
                  > Title: Using the WebBrowser control in .NET
                  > URL: http://www.codeproject.com/csharp/webbrowser.asp
                  >
                  > Thanks for your understanding!
                  >
                  > Best Regards,
                  >
                  > Terry Fei[MSFT]
                  > Microsoft Community Support
                  > Get Secure! www.microsoft.com/security
                  > (This posting is provided "AS IS", with no warranties, and confers no
                  > rights.)
                  >
                  > --------------------[color=green]
                  >>Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                  >>From: "Alex Clark" <honeycomb@news groups.nospam>
                  >>References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
                  > <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                  > <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                  > <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>
                  > <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                  > <npn7UC0RGHA.48 24@TK2MSFTNGXA0 3.phx.gbl>[color=green]
                  >>Subject: Re: WebBrowser Control Printing
                  >>Date: Wed, 15 Mar 2006 11:44:28 -0000
                  >>Lines: 207
                  >>X-Priority: 3
                  >>X-MSMail-Priority: Normal
                  >>X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                  >>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                  >>X-RFC2646: Format=Flowed; Original
                  >>Message-ID: <uYswLXCSGHA.46 00@TK2MSFTNGP11 .phx.gbl>
                  >>Newsgroups: microsoft.publi c.dotnet.langua ges.vb
                  >>NNTP-Posting-Host: host81-152-10-23.range81-152.btcentralpl us.com[/color]
                  > 81.152.10.23[color=green]
                  >>Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP11.phx. gbl
                  >>Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321889
                  >>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                  >>
                  >>Hi Terry,
                  >>
                  >>Any chance you could give me some example code in either C# or VB.NET for
                  >>using Print Templates with the WebBrowser control? I'm using .NET 2.0 and
                  >>my clients will have IE6 installed as a minimum. A simple example just to
                  >>get me started would be much appreciated.
                  >>
                  >>Many thanks,
                  >>Alex
                  >>
                  >>
                  >>""TerryFei" " <v-terryf@online.m icrosoft.com> wrote in message
                  >>news:npn7UC0R GHA.4824@TK2MSF TNGXA03.phx.gbl ...[color=darkred]
                  >>> Hi Alex,
                  >>> Thanks for your response!
                  >>>
                  >>>>>After further investigation on the web I'm still fairly convinced this[/color][/color]
                  > is[color=green][color=darkred]
                  >>> a
                  >>>>>C++ only option, due to the wrapping of COM Variant types - .NET
                  >>>>>interop
                  >>>>>will, apparently, not support this at all, unless something has changed
                  >>> as
                  >>>>>.of 2.0.
                  >>> WebBrowser control provide us IWebBrowser2 com-interface and we can use
                  >>> this interface to control WebBrowser control's operation. IWebBrowser2
                  >>> is
                  >>> an IDispatch interface, in a word, this is a dual-interface, so we can[/color][/color]
                  > use[color=green][color=darkred]
                  >>> it in C++ and VB. If your environment is .Net, we could use it with
                  >>> Interoperabilit y mechanism. I hope the following articles will be
                  >>> helpful
                  >>> for you:
                  >>> Title: Using the WebBrowser control in .NET
                  >>> URL: http://www.codeproject.com/csharp/webbrowser.asp
                  >>>
                  >>> Title: Using MSHTML Advanced Hosting Interfaces
                  >>> URL: http://www.codeproject.com/csharp/advhost.asp
                  >>>
                  >>> Title: Microsoft Web Browser Automation using C#
                  >>> URL: http://www.codeproject.com/csharp/mshtml_automation.asp
                  >>>
                  >>> I hope the above information is helpful for you. If there is anything I
                  >>> can do for you, please feel free to let me know. Thanks and have a nice
                  >>> day!
                  >>>
                  >>> Best Regards,
                  >>>
                  >>> Terry Fei[MSFT]
                  >>> Microsoft Community Support
                  >>> Get Secure! www.microsoft.com/security
                  >>> (This posting is provided "AS IS", with no warranties, and confers no
                  >>> rights.)
                  >>>
                  >>>
                  >>>
                  >>> --------------------
                  >>>>Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                  >>>>From: "Alex Clark" <honeycomb@news groups.nospam>
                  >>>>Reference s: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>
                  >>> <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                  >>> <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                  >>> <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>
                  >>>>Subject: Re: WebBrowser Control Printing
                  >>>>Date: Thu, 9 Mar 2006 16:22:23 -0000
                  >>>>Lines: 116
                  >>>>X-Priority: 3
                  >>>>X-MSMail-Priority: Normal
                  >>>>X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                  >>>>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                  >>>>X-RFC2646: Format=Flowed; Response
                  >>>>Message-ID: <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                  >>>>Newsgroup s: microsoft.publi c.dotnet.langua ges.vb
                  >>>>NNTP-Posting-Host: host86-134-248-72.range86-134.btcentralpl us.com
                  >>> 86.134.248.72
                  >>>>Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
                  >>>>Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:321151
                  >>>>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                  >>>>
                  >>>>Hi Colin,
                  >>>>
                  >>>>After further investigation on the web I'm still fairly convinced this
                  >>>>is
                  >>> a
                  >>>>C++ only option, due to the wrapping of COM Variant types - .NET interop
                  >>>>will, apparently, not support this at all, unless something has changed[/color][/color]
                  > as[color=green][color=darkred]
                  >>>>of 2.0.
                  >>>>
                  >>>>I think you're right about the report-writing avenue however. It's a
                  >>> shame,
                  >>>>as what I'm trying to do would be ideally suited to generating a quick
                  >>> HTML
                  >>>>file and printing it, if only I could have slightly more control over
                  >>>>the
                  >>>>printed output :-(
                  >>>>
                  >>>>Thanks for your help,
                  >>>>Alex Clark
                  >>>>
                  >>>>
                  >>>>
                  >>>>
                  >>>>"Colin Neller" <cneller@gmail. com> wrote in message
                  >>>>news:OkLFEw 4QGHA.5500@TK2M SFTNGP12.phx.gb l...
                  >>>>> Alex,
                  >>>>>
                  >>>>> Print Templates are certainly non-trivial, but they do not require
                  >>>>> C++.
                  >>>>> The key line of code from the example I gave is:
                  >>>>>
                  >>>>> pCmdTarg->Exec(&CGID_MSH TML,
                  >>>>> IDM_PRINT,
                  >>>>> OLECMDEXECOPT_P ROMPTUSER,
                  >>>>> &vTemplatePa th,
                  >>>>> NULL);
                  >>>>>
                  >>>>> Basically, what you would do in .NET is cast your IWebBrowser2 object[/color][/color]
                  > to[color=green][color=darkred]
                  >>>>> an IOleCommandTarg et and call the Exec method (as above) passing in
                  >>>>> the
                  >>>>> path to your print template (vTemplatePath in the above example.) The
                  >>>>> vast majority of the Print Template code will be written in
                  >>>>> JavaScript.
                  >>>>>
                  >>>>> Honestly, I think you would be better investing in a report writing[/color][/color]
                  > tool[color=green][color=darkred]
                  >>>>> (e.g. ActiveReports) The path you are headed down with the WB is not[/color][/color]
                  > an[color=green][color=darkred]
                  >>>>> easy one.
                  >>>>>
                  >>>>> --
                  >>>>> Colin Neller
                  >>>>> http://www.colinneller.com/blog
                  >>>>>
                  >>>>>
                  >>>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
                  >>>>> news:%238dKtk4Q GHA.2436@TK2MSF TNGP11.phx.gbl. ..
                  >>>>>> Hi Colin,
                  >>>>>>
                  >>>>>> These look really useful but the article seems to imply that this is
                  >>> only
                  >>>>>> possible when using C++. I know it was written a long time ago[/color][/color]
                  > (before[color=green][color=darkred]
                  >>>>>> .NET) but it doesn't seem as though it could be very VB.NET friendly
                  >>>>>> :-(
                  >>>>>>
                  >>>>>> Thanks,
                  >>>>>> Alex
                  >>>>>>
                  >>>>>>
                  >>>>>>
                  >>>>>> "Colin Neller" <cneller@gmail. com> wrote in message
                  >>>>>> news:e68kZa4QGH A.2536@tk2msftn gp13.phx.gbl...
                  >>>>>>> Alex,
                  >>>>>>>
                  >>>>>>> I suggest you look into Print Templates:
                  >>>>>>>
                  >>>>>>>
                  >>>[/color][/color]
                  > http://msdn.microsoft.com/library/de...us/dnie55/html[color=green][color=darkred]
                  >>> /beyondprintprev iew.asp
                  >>>>>>>
                  >>>>>>>
                  >>>[/color][/color]
                  > http://msdn.microsoft.com/library/de...us/dnie55/html[color=green][color=darkred]
                  >>> /printtemplate2. asp?frame=true
                  >>>>>>>
                  >>>>>>> --
                  >>>>>>> Colin Neller
                  >>>>>>> http://www.colinneller.com/blog
                  >>>>>>>
                  >>>>>>>
                  >>>>>>> "Alex Clark" <honeycomb@news groups.nospam> wrote in message
                  >>>>>>> news:%235I1TE4Q GHA.2156@tk2msf tngp13.phx.gbl. ..
                  >>>>>>>> Greetings,
                  >>>>>>>>
                  >>>>>>>> (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).
                  >>>>>>>>
                  >>>>>>>> I've decided to take advantage of the layout characteristics of
                  >>>>>>>> HTML
                  >>>>>>>> documents to simplify my printing tasks, but of course it's thrown[/color][/color]
                  > up[color=green][color=darkred]
                  >>> a
                  >>>>>>>> whole host of new issues...
                  >>>>>>>>
                  >>>>>>>> I'm generating a multi page printable document in HTML from my app,
                  >>> and
                  >>>>>>>> displaying it in a WebBrowser control. I've looked into using some
                  >>> CSS
                  >>>>>>>> commands to control pagination, but nothing seems to fit the bill
                  >>>>>>>> so
                  >>>>>>>> far.
                  >>>>>>>>
                  >>>>>>>> I need to include a custom header/footer (imported from another
                  >>>>>>>> HTML
                  >>>>>>>> file) on every page that's printed. I also need to draw a border
                  >>>>>>>> around each page. The closest I can get to the border is putting[/color][/color]
                  > all[color=green][color=darkred]
                  >>>>>>>> my print-content inside an HTML table, which looks ugly because it
                  >>>>>>>> doesn't close off at the foot of each page - it only draws its
                  >>>>>>>> final
                  >>>>>>>> horizontal line at the very end of the document.
                  >>>>>>>>
                  >>>>>>>> I tried inheriting from WebBrowser and overriding the OnPrint
                  >>>>>>>> event,
                  >>>>>>>> but this never seems to get called? I've found an example on the
                  >>> MSDN
                  >>>>>>>> site, but it's all in C++ and seems designed around MFC.
                  >>>>>>>>
                  >>>>>>>> How can I hang on to the snazzy built-in formatting features of[/color][/color]
                  > HTML,[color=green][color=darkred]
                  >>>>>>>> but still have control over the printed output & pagination? Help!
                  >>>>>>>>
                  >>>>>>>> Thanks in advance,
                  >>>>>>>> Alex Clark
                  >>>>>>>>
                  >>>>>>>>
                  >>>>>>>>
                  >>>>>>>>
                  >>>>>>>
                  >>>>>>>
                  >>>>>>
                  >>>>>>
                  >>>>>
                  >>>>>
                  >>>>
                  >>>>
                  >>>>
                  >>>[/color]
                  >>
                  >>
                  >>[/color]
                  >[/color]


                  Comment

                  • Alex Clark

                    #10
                    Re: WebBrowser Control Printing

                    Hi Terry,

                    After some tinkering I've managed to get it to work with a sample Print
                    Template! However, I am left with another problem.

                    If I call .ExecWB of the ActiveX control, it works no problem. However, I
                    have a requirement to use the managed .NET 2.0 WebBrowser control rather
                    than the COM control. This is easy enough, as all I then do is the
                    following:

                    WebBrowser1.Act iveXInstance.Ex ecWB(SHDocVw.OL ECMDID.OLECMDID _PRINTPREVIEW,
                    SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DODEFAULT , "c:\Template.ht m", Nothing)

                    (Note: Option Strict is OFF to permit late binding calls like this).

                    However, this returns an error message:

                    "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED ))"

                    Why would this work fine using the COM version of the control, but fail when
                    trying it with the managed version? Any ideas?

                    Thanks,
                    Alex Clark



                    Comment

                    • TerryFei

                      #11
                      Re: WebBrowser Control Printing

                      Hi Alex,
                      Thanks for your feedback! :)
                      [color=blue][color=green]
                      >>After some tinkering I've managed to get it to work with a sample Print
                      >>Template! However, I am left with another problem.[/color][/color]
                      We are glad our information is helpful for you.
                      [color=blue][color=green]
                      >>Why would this work fine using the COM version of the control, but fail[/color][/color]
                      when[color=blue][color=green]
                      >>trying it with the managed version?[/color][/color]
                      After researching, this issue needs trace code further in dinput.dll and
                      debug internal to find what happens at all. This is beyond Newsgroup
                      support. So in this scenario, we suggest you contact with our CSS (Customer
                      Support Service) support team to get more information and support. This may
                      need you submit a support incident in Microsoft CSS. As a MSDN subscriber,
                      you have two free support incidents.

                      By the way, if the problem is confirmed by Microsoft CSS as a product
                      issue, CSS won't charge money. Every MSDN subscriber has two free support
                      incidents. You could use one of them to contact Microsoft CSS. So you don't
                      need to pay money yet. Surely if the issue is a product issue, you still
                      have two free support incidents.

                      For your reference, I attached steps to contact Microsoft CSS here: You can
                      contact Microsoft Customer Support directly to discuss additional support
                      options you may have available, by contacting us at 1-(800)936-5800 or by
                      choosing one of the options listed at:


                      If you have any questions or concerns, please let me know. I am standing by
                      to help you. Thanks for your understanding!

                      Best Regards,

                      Terry Fei [MSFT]
                      Microsoft Community Support
                      Get Secure! www.microsoft.com/security

                      --------------------[color=blue]
                      >Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                      >From: "Alex Clark" <honeycomb@news groups.nospam>
                      >References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
                      <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                      <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                      <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>
                      <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                      <npn7UC0RGHA.48 24@TK2MSFTNGXA0 3.phx.gbl>
                      <uYswLXCSGHA.46 00@TK2MSFTNGP11 .phx.gbl>
                      <PpU5OcNSGHA.51 68@TK2MSFTNGXA0 3.phx.gbl>[color=blue]
                      >Subject: Re: WebBrowser Control Printing
                      >Date: Thu, 16 Mar 2006 15:21:36 -0000
                      >Lines: 27
                      >X-Priority: 3
                      >X-MSMail-Priority: Normal
                      >X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                      >X-RFC2646: Format=Flowed; Original
                      >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                      >Message-ID: <ueWnL1QSGHA.16 08@TK2MSFTNGP09 .phx.gbl>
                      >Newsgroups: microsoft.publi c.dotnet.langua ges.vb
                      >NNTP-Posting-Host: host81-152-10-23.range81-152.btcentralpl us.com[/color]
                      81.152.10.23[color=blue]
                      >Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
                      >Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:322116
                      >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                      >
                      >Hi Terry,
                      >
                      >After some tinkering I've managed to get it to work with a sample Print
                      >Template! However, I am left with another problem.
                      >
                      >If I call .ExecWB of the ActiveX control, it works no problem. However, I
                      >have a requirement to use the managed .NET 2.0 WebBrowser control rather
                      >than the COM control. This is easy enough, as all I then do is the
                      >following:
                      >
                      >WebBrowser1.Ac tiveXInstance.E xecWB(SHDocVw.O LECMDID.OLECMDI D_PRINTPREVIEW,
                      >SHDocVw.OLECMD EXECOPT.OLECMDE XECOPT_DODEFAUL T, "c:\Template.ht m", Nothing)
                      >
                      >(Note: Option Strict is OFF to permit late binding calls like this).
                      >
                      >However, this returns an error message:
                      >
                      >"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED ))"
                      >
                      >Why would this work fine using the COM version of the control, but fail[/color]
                      when[color=blue]
                      >trying it with the managed version? Any ideas?
                      >
                      >Thanks,
                      >Alex Clark
                      >
                      >
                      >
                      >[/color]

                      Comment

                      • Alex Clark

                        #12
                        Re: WebBrowser Control Printing

                        Hi Terry,
                        [color=blue]
                        > http://support.microsoft.com/d-efaul...Offe-rProPhone[/color]

                        This link seems to be broken? :-(

                        -Alex


                        Comment

                        • TerryFei

                          #13
                          Re: WebBrowser Control Printing

                          Hi Alex,
                          Please use the following link:
                          Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


                          Thanks for your understanding!

                          Best Regards,

                          Terry Fei [MSFT]
                          Microsoft Community Support
                          Get Secure! www.microsoft.com/security

                          --------------------[color=blue]
                          >Reply-To: "Alex Clark" <honeycomb@news groups.nospam>
                          >From: "Alex Clark" <honeycomb@news groups.nospam>
                          >References: <#5I1TE4QGHA.21 56@tk2msftngp13 .phx.gbl>[/color]
                          <e68kZa4QGHA.25 36@tk2msftngp13 .phx.gbl>
                          <#8dKtk4QGHA.24 36@TK2MSFTNGP11 .phx.gbl>
                          <OkLFEw4QGHA.55 00@TK2MSFTNGP12 .phx.gbl>
                          <e7P0gW5QGHA.50 36@TK2MSFTNGP12 .phx.gbl>
                          <npn7UC0RGHA.48 24@TK2MSFTNGXA0 3.phx.gbl>
                          <uYswLXCSGHA.46 00@TK2MSFTNGP11 .phx.gbl>
                          <PpU5OcNSGHA.51 68@TK2MSFTNGXA0 3.phx.gbl>
                          <ueWnL1QSGHA.16 08@TK2MSFTNGP09 .phx.gbl>
                          <6QIuvc8SGHA.55 36@TK2MSFTNGXA0 3.phx.gbl>[color=blue]
                          >Subject: Re: WebBrowser Control Printing
                          >Date: Wed, 22 Mar 2006 12:44:15 -0000
                          >Lines: 9
                          >X-Priority: 3
                          >X-MSMail-Priority: Normal
                          >X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
                          >X-RFC2646: Format=Flowed; Original
                          >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
                          >Message-ID: <#BZoO5aTGHA.58 08@TK2MSFTNGP12 .phx.gbl>
                          >Newsgroups: microsoft.publi c.dotnet.langua ges.vb
                          >NNTP-Posting-Host: host86-134-249-208.range86-134.btcentralpl us.com[/color]
                          86.134.249.208[color=blue]
                          >Path: TK2MSFTNGXA03.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
                          >Xref: TK2MSFTNGXA03.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:322967
                          >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                          >
                          >Hi Terry,
                          >[color=green]
                          >> http://support.microsoft.com/d-efaul...Offe-rProPhone[/color]
                          >
                          >This link seems to be broken? :-(
                          >
                          >-Alex
                          >
                          >
                          >[/color]

                          Comment

                          Working...