Using PageScript 32


PageScript 32 is easy to use and learn. If you're programming [x]Harbour, you have the choice of using PS function calls or to instantiate an object based on the TPageScript class. The source code for these programming languages is located in TPSCRIPT.PRG.

Here's an example on how to initialize the print library, start a new print job, print some text and then end the print job using PageScript 32 functions, procedures and commands :

[x]Harbour, using functions, procedures and commands wrappers

1 #Include "PScript.ch"
2 if PSInit() == 0
3    BEGINDOC USING 0 TITLE "Hello world"
4       PSSetUnit(APS_TEXT)
5       PSSetLPI(6)
6       PSSetCPI(10)
7       @5,5 TEXTOUT "Hello world"
8    ENDDOC
9 endif

Lets explain the code, line by line.

Line 1 is the standard Include statement. PSCRIPT.CH contains all deinitions you need to work with PageScript 32.

Line 2 initializes PageScript 32. If everything is OK, it returns 0. You need to call this function only once, at application start, not everytime you start a new print job

Line 3 starts a new print job, on the default printer with the title set to "Hello world"

Line 4 sets the unit of mesurement to text coordinates that barely mimics old DOS printer's rows and columns coordinate system.

Line 5 sets the number of LPI (lines per inch) to 6. The default value is 6, so this line is not required. We added it for demonstration purposes only.

Line 6 sets the number of CPI (characters per inch) to 10. The default value is 10, so this line is not required. We added it for demonstration purposes only.

Line 7 send the command to print "Hello world" at column 5 and row 5. It uses the default/current set font, font size, font foreground and background colors.

Line 8 ends the print job.

Line 9 is the end of the if structure.


Here's an example on how to create a new TPageScript object, start a new print job, print some text and then end the print job using TPageScript methods :

[x]Harbour, using the TPageScript class

1 #Include "PScript.ch"
2 Local oPS := TPageScript:New()
3 if oPS:nError == 0
4    oPS:BeginDoc(0, "Hello world")
5       oPS:SetUnit(APS_TEXT)
6       oPS:SetLPI(6)
7       oPS:SetCPI(10)
8       oPS:TextOutEx(5, 5, "Hello world")
9    oPS:EndDoc()
10 endif

Lets explain the code, line by line.

Line 1 is the standard Include statement. PSCRIPT.CH contains all deinitions you need to work with PageScript 32.

Line 2 creates a new TPageScript object and initializes a local variable, named oPS

Line 3 checks if the object is correctly initialized by comparing oPS:nError. If everything is OK, oPS:nError is set to 0.

Line 4 starts a new print job, on the default printer with the title set to "Hello world"

Line 5 sets the unit of mesurement to text coordinates that barely mimics old DOS printer's rows and columns coordinate system.

Line 6 sets the number of LPI (lines per inch) to 6. The default value is 6, so this line is not required. We added it for demonstration purposes only.

Line 7 sets the number of CPI (characters per inch) to 10. The default value is 10, so this line is not required. We added it for demonstration purposes only.

Line 8 send the command to print "Hello world" at column 5 and row 5. It uses the default/current set font, font size, font foreground and background colors.

Line 9 ends the print job.

Line 10 is the end of the if structure.


PageScript 32 is shipped with a demo program (PSTEST.EXE) for [x]Harbour (althgough every 32 bits programming languages are supported) that demonstrates most of the aspects and techniques to produce all kind of documents. We invite you to open and study these sample programs.