Link to home
Start Free TrialLog in
Avatar of Baloon
Baloon

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wsh2
wsh2

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
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).  
Now looking at OLECMDID_PAGESETUP
Interesting reading (although I can't make sense of it yet.. lol):

Develop Your Own Browser
http://www.vbsquare.com/internet/browser/index.html
Nevermind on that previous link.. nothing special in it.. <sigh>.
Per recommendation, force-accepted by
Netminder
Community Support Moderator
Experts Exchange