## Overview

HTML documents can be printed by either:
1. LAUNCHing Internet Exploer to print the document
2. Printing the document currently loaded in the Web View window.

## Page Setup

This applies to either of the above methods. SM32 allows you to change the margins, the header the footer and the orientation before you print. This is done by changing the these values in the Internet Explorer and default printer registry entries. So if you change these values and do not restore them they will be in effect the next time any Internet Explorer print is preformed. The orientation is the orientation of the default printer. So if it is not restored any print will use this as its default
The following code retrieves the current registry settings:

    10 BEGIN
    20 DIM A!
    30 LET A!["type"]="GetPageSetup"
    40 WRITE GUI A![ALL];READ GUI A![ALL]
    50 PRINT "Bottom Margin is ",QUO,A!["margin_bottom"],QUO
    60 PRINT "Top Margin is ",QUO,A!["margin_top"],QUO
    70 PRINT "Left Margin is ",QUO,A!["margin_left"],QUO
    80 PRINT "Right Margin is ",QUO,A!["margin_right"],QUO
    90 PRINT "Header is ",QUO,A!["header"],QUO
    100 PRINT "Footer is ",QUO,A!["footer"],QUO
    110 PRINT "Orientation is ",QUO,A!["orientation"],QUO
    120 PRINT "Default Printer is ",QUO,A!["default_printer"],QUO

    OUTPUT(Note the margins,header and footer are the Internet Explorer Defaults):

    Bottom Margin is "0.75000"
    Top Margin is "0.75000"
    Left Margin is "0.75000"
    Right Margin is "0.75000"
    Header is "&w&bPage &p of &P"
    Footer is "&u&b&d"
    Orientation is "Protrait"
    Default Printer is "hp deskjet 920c"

The following code sets the registry entries:

    10 BEGIN
    20 DIM A!
    30 LET A!["type"]="SetPageSetup"
    40 LET A!["margin_bottom"]="0.5"
    50 LET A!["margin_top"]="0.5"
    60 LET A!["margin_left"]="0.5"
    70 LET A!["margin_right"]="0.5"
    80 LET A!["header"]="My Header"
    90 LET A!["footer"]="My Footer"
    100 LET A!["orientation"]="Landscape"
    110 WRITE GUI A![ALL]

To format a custom header or footer, use the following codes to specify the information to be printed. The codes can be combined with text (for example, "Page &p of &P").

Desired Text | Code
--- | ---
Window title | &w |
Page address (URL) | &u
Date in short format (as specified by Regional Settings in Control Panel) | &d
Date in long format (as specified by Regional Settings in Control Panel) | &D
Time in the format specified by Regional Settings in Control Panel | &t
Time in 24-hour format | &T
Current page number | &p
Total number of pages | &P
Centered text (following &b) | &b
Right-aligned text (following &b&b) | &b&b
A single ampersand (&) | &&

## $__PAGE_SETUP - Utility

The $__PAGE_SETUP utility takes either "" or a KSA as an in/out parameter.
If "" is passed in as the parameter:
CALL "$__PAGE_SETUP",""
a SetPageSetup is executed with the Inetrnet Explorer defaults.
If the parameter is a KSA it should contain at least the header and footer and maybe new margins. If there are no margins the old margins are used. The return from $__PAGE_SETUP will have the previous page setup values in the ksa so re CALLing $_PAGE_SETUP will restore the previous settings.
Example:

    10 BEGIN
    20 DIM K!
    30 LET K!["footer"]="";REM "the dim actual did this"
    40 LET K!["header"]="";REM "the dim actual did this"
    50 CALL "$__PAGE_SETUP",K![ALL];REM "Set page setup"
    60 PRINT 'LAUNCH'("-print html\temp.html","",0,0)
    70 WAIT -500;REM "Wait 1/2 second for Internet Explorer to Read Registry"
    80 CALL "$__PAGE_SETUP",K![ALL];REM "Restore page setup"

## LAUNCHing Internet Explorer to Print an HTML File

Line 60 in the above example shows one way to LAUNCH Internet Explorer to print your html documents. The user will be prompted to select the printer.
Please Note !!
Some applications take over the File Association of (.HTM,.HTML) files. AOL/Netscape and Microsoft Office are 2 of these. To get around this problem the GSYSDIR function was added. It returns the Windows System Directory (something like C:\Windows\System32). This allows you to execute the Internet Explorer print directly. Also since we are not using a file association type LAUNCH, the LAUNCH statement will return a handle that can been used to determine when the print has finished spooling. So the code below is preferable.

    10 BEGIN
    20 DIM K!
    30 LET K!["footer"]="";REM "the dim actual did this"
    40 LET K!["header"]="";REM "the dim actual did this"
    50 CALL "$__PAGE_SETUP",K![ALL];REM "Set page setup"
    60 LET L$="rundll32.exe "+GSYSDIR+"\mshtml.dll,PrintHTML "
    70 LET F$=DIR(-1)+"HTML\temp.html"
    80 LAUNCH L$+$22$+F$+$22$,"",0,0
    90 LET H=TCB(8);REM "Handle to Launced program"
    100 WAIT -100
    110 IF GEC(H)=259 THEN GOTO 0100;REM "Still Running"
    120 HANDLECLOSE H
    130 CALL "$__PAGE_SETUP",K![ALL];REM "Restore page setup"

Line 60 gets the program to run
Line 70 gets the full path name of the file we are printing
Line 80 launches the program putting the file name in quotes
Line 90 TCB(8) contains handle to lanched program
Line 110 check the Exit Code of the launched program if it is 259 it is still running
The program $__PRINT that prints programs under the file menu uses this method.

## Printing the Web View Document

The SetPageSetup WRITE GUI (or call $__PAGE_SETUP) can be used before any of the following WRITE GUI commands. The DEMO9 program demonstates the following Write Gui commands (as well as the edit commands: Cut,Copy,Paste and SelectAll).
FilePrint:
Print the Web View Document - brings up the Pring dialog box.

    185 LET P!["type"]="FilePrint"
    190 LET P!["option"]="DODEFAULT"
    195 WRITE GUI P![ALL]

Print the Web View Document - without user intervention.

    265 LET P!["type"]="FilePrint"
    270 LET P!["option"]="DONTPROMPTUSER"
    275 WRITE GUI P![ALL]

PageSetup:
Bring up the Page Setup Dialog box.

    145 LET P!["type"]="PageSetup"
    150 LET P!["option"]="DODEFAULT"
    155 WRITE GUI P![ALL]

PrintPreview:
Bring up a print preview.

    225 LET P!["type"]="PrintPreview"
    230 LET P!["option"]="DODEFAULT"
    235 WRITE GUI P![ALL]