Example

The Landscape macro sends PCL escape control codes to set an HP LaserJet printer to landscape orientation. A printer event is runs this macro when the printer is opened. The Reset macro resets the printer and is triggered by a printer event that runs after the printer is closed. Note: Because PrintTransparentChar enables transparent mode, all subsequent data is sent directly to the printer.

Sub Landscape()

 Dim i As Integer

 Dim landscape(6) As Byte

 

 ' HP PCL command

 ' EscE   - reset printer

 ' Esc&l1O  - change to landscape orientation

 landscape(0) = &H1B ' Escape control code

 landscape(1) = Asc("E")

 landscape(2) = &H1B ' Escape control code

 landscape(3) = Asc("&")

 landscape(4) = Asc("l") 'lowercase letter L

 landscape(5) = Asc("1") 'number 1

 landscape(6) = Asc("O") 'uppercase letter O

 

 With Session

  For i = 0 To 6

   .PrintTransparentChar landscape(i)

  Next i

 End With

End Sub

 

Sub Reset()

 Dim i As Integer

 Dim reset(1) As Byte

 

 ' HP PCL command

 ' EscE  - reset printer

 reset(0) = &H1B ' Escape control code

 reset(1) = Asc("E")

 

 With Session

  For i = 0 To 1

   .PrintTransparentChar reset(i)

  Next i

 End With

End Sub

To define the events:

You can define the printer events using the Reflection Event Properties dialog box or you can create them programmatically as shown here:

OnEvent 1, rcPrinterOpened, "RunMacro ""Landscape"", """"", rcEnable, rcEventReEnable, "", 1, 1

OnEvent 1, rcBeforePrinterClosed, "RunMacro ""Reset"", """"", rcEnable, rcEventReEnable, "", 1, 1