Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Setting Document/Printer Properties with ie5 browser ocx or with html

Posted on 2001-08-22
Medium Priority
Last Modified: 2013-12-25
Setting Document/Printer Properties with ie5 browser ocx or with html

I want to print html forms in differen sizes, orintation with the browser control.

I tried three approaches:
1. size and orientation in the .html file
   example: <style> @page { size:21.0cm 14.5cm;landscape } </style>
   but this needs CSS2 support which the internet explorer does not
   -or is there another way?

2. application driven
   at the moment i have a small VB sample application that works quit well

       WebBrowser.Navigate (AnyUrl)

   Private Sub WebBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)
   End Sub

   except for the fact, that i have to configure the printer manually
   OLECMDEXECOPT_PROMPTUSER shows the printer dialog but i would rather use
   OLECMDEXECOPT_DONTPROMPTUSER and apply the settings programatically

   -can i change the settings  with VB or do i have to do this in C++ using COM?
   -does anyone hav an example.
   -i am a C++ programmer with some basic knowledge of MFC.
   -but i dont know how to handle IPrint::Print  with DEVMODE

3. default printer settings
   i also tried to change the printer properties (start/settings/printers)
   but the browser just does not use them.
   may be there is somewhere a template i could use
   internet explorer/ properties / general (tab) / accessibility (button) / user style sheet
   -how must a stylesheet look?
   -would it work like this? or are these stylesheets only for display?  


Yours Sincerely // Mit freundlichen Grussen

Theo Portmann

Atraxis AG
CH-8058 Zurich-Airport

Phone: +41 1 812 28 63
Telefax: +41 1 812 90 31
E-mail: theo.portmann@atraxis.com

Question by:Baloon
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
  • 6
LVL 14

Accepted Solution

wsh2 earned 800 total points
ID: 6415728
Background Information From MSDN (which you have already implemented):

Q188271 HOWTO: Print Contents of the Web Browser Control From VB

HOWTO: Print Contents of the Web Browser Control From VB

The information in this article applies to:

Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0
Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0


The Web Browser control (version 3.x or 4.x) does not offer a direct Print method. This article demonstrates how to print the contents of the Web Browser control from Visual Basic.


Step-by-Step Example
Create a new Standard EXE project in Visual Basic. Form1 is created by default.

Select Components from the Project menu. Add a reference to the "Microsoft Internet Controls."

Add the following controls to Form1:

1 CommandButton
1 Web Browser

Add the following code to Form1:

      Option Explicit

      Private Sub Command1_Click()

         ' print the contents of the Web Browser control.
         WebBrowser1.ExecWB _

      End Sub

      Private Sub Form_Load()

         ' set the caption of the command button.
         Command1.Caption = "&Print"

         ' position the print command button at the top-left.
         Command1.Move 0, 0

         ' position the Web Browser control below the command button.
          WebBrowser1.Move 0, 750

          ' navigate to a Web site for testing purposes.
          WebBrowser1.Navigate "http://www.microsoft.com"

      End Sub

      Private Sub Form_Resize()

         ' when the form is resized, the Web Browser control should
         ' remain the same size as the form.
         WebBrowser1.Width = Form1.Width
         WebBrowser1.Height = Form1.Height

      End Sub

Press the F5 key to run the project. When the test site has been downloaded and rendered in the Web Browser, click the "Print" command button, and the contents of the Web Browser will be printed.

NOTE: Using version 3.x of the Web Browser control will result in a Print Dialog appearing when you attempt to print the content of the control. This is by design.
LVL 14

Expert Comment

ID: 6415769
However, this is very interesting.. Registry settings?.. Notice that they are using OLECMD, and NOT the Print() method now available with IEv5.5. Hmmmm...

From MSDN:

PRB: Programmatically Issuing Print Command May Not Print to Default Printer

The information in this article applies to:

Microsoft Internet Explorer (Programming) versions 5.5, 5.5 Service Pack 1


IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring the Registry" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.

In Internet Explorer 5.5, when you issue a print command, the print job may not be sent to the default system printer. This occurs whether you click Print on the File menu or if you call the ExecWB method of the WebBrowser control.

When you select a printer in Internet Explorer (on the File menu, click Page Setup, click Printer, and choose a printer that is not the system default), your printer selection is stored in the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PageSetup\printer
After you make this selection, Internet Explorer continues to use the printer value that is stored in the registry.

WARNING: Using Registry Editor incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect use of Registry Editor can be solved. Use Registry Editor at your own risk.

For information about how to edit the registry, view the "Changing Keys and Values" Help topic in Registry Editor (Regedit.exe) or the "Add and Delete Information in the Registry" and "Edit Registry Data" Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT or Windows 2000, you should also update your Emergency Repair Disk (ERD).

If you want to use the Microsoft Windows default printer when you host a WebBrowser control, you can use the code in this section to set this registry key to an empty string "", issue your print command, and then restore the value in the registry. Because there is no value under this key, Internet Explorer uses the default system printer.

NOTE: Make sure that you do not restore the registry value until after you are sure that the print job has finished; otherwise, you may restore the printer in the registry before Internet Explorer has actually read this key. This can occur when you print more complex Web pages.

To set the registry key to an empty string "", use the following Microsoft Visual Basic code:

    Dim wsh As Object
    Dim printer As String
    Const reg = "HKCU\Software\Microsoft\Internet Explorer\PageSetup\printer"
    Set wsh = CreateObject("WScript.Shell")
    printer = wsh.RegRead(reg)
    If Not printer = "" Then
        '   Clear the value
        wsh.RegWrite reg, ""
    End If

    ' NOTE: Because Internet Explorer may not have read the registry key
    ' yet, additional code may be required to ensure that Internet Explorer
    ' has read the registry key before you set it back to "".
    If Not printer = "" Then
        wsh.RegWrite reg, printer
    End If
    Set wsh = Nothing
LVL 14

Expert Comment

ID: 6415800
Checked the registy Internet Explorer PageSetup settings.. Printer Name, Margins, Page Header and Footer templates are there.. but no Paper size (sighs?) and orientation (which, it seems, has to be a function of Printer Name).  
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!

LVL 14

Expert Comment

ID: 6415841
LVL 14

Expert Comment

ID: 6415849
Interesting reading (although I can't make sense of it yet.. lol):

Develop Your Own Browser
LVL 14

Expert Comment

ID: 6415861
Nevermind on that previous link.. nothing special in it.. <sigh>.

Expert Comment

ID: 6862685
Per recommendation, force-accepted by
Community Support Moderator
Experts Exchange

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 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