Solved

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

Posted on 2001-08-22
7
1,226 Views
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)
     WebBrowser.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
   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
CEPM
CH-8058 Zurich-Airport

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

0
Comment
Question by:Baloon
  • 6
7 Comments
 
LVL 14

Accepted Solution

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

----------------------------------------------------------
Q188271 HOWTO: Print Contents of the Web Browser Control From VB
http://support.microsoft.com/support/kb/articles/Q188/2/71.ASP
----------------------------------------------------------

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

----------------------------------------------------------

SUMMARY
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.

MORE INFORMATION

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 _
         OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0

      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.
0
 
LVL 14

Expert Comment

by:wsh2
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
http://support.microsoft.com/support/kb/articles/Q283/7/97.ASP

----------------------------------------------------------
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.

SYMPTOMS
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.

CAUSE
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.

RESOLUTION
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

    wb.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
   
    ' 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
0
 
LVL 14

Expert Comment

by:wsh2
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).  
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 14

Expert Comment

by:wsh2
ID: 6415841
Now looking at OLECMDID_PAGESETUP
0
 
LVL 14

Expert Comment

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

Develop Your Own Browser
http://www.vbsquare.com/internet/browser/index.html
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6415861
Nevermind on that previous link.. nothing special in it.. <sigh>.
0
 
LVL 5

Expert Comment

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now