Syntax 2 For printing text in a print job
Description
Sends one or more lines of text as part of a print job that
you have opened with the PrintOpen function.
You can specify tab settings before or after the text. The tab settings
control the text’s horizontal position on the page.
Controls
Not object-specific
Syntax
|
1 |
<span>Print</span> ( <span>printjobnumber</span>, { <span>tab1</span>, } <span>string</span> {, <span>tab2</span> } ) |
|
Argument |
Description |
|---|---|
|
printjobnumber |
The number the PrintOpen function |
|
tab1 |
The position, measured from the left |
|
string |
The string you want to print. If the |
|
tab2 |
The new position, measured from the left |
Return Values
Integer. Returns 1 if it succeeds and
-1 if an error occurs. If any argument’s value is null,
Print returns null.
Usage
PowerBuilder manages print jobs by opening the job, sending
data, and closing the job. When you use Syntax 2 or 3, you must
call the PrintOpen function and the PrintClose or PrintCancel functions
yourself to manage the process.
Print cursor
In a print job, PowerBuilder uses a print cursor to keep track
of the print location. The print cursor stores the coordinates of
the upper-left corner of the location at which print will being.
PowerBuilder updates the print cursor after printing text with Print.
Line spacing when printing text
Line spacing in PowerBuilder is proportional to character
height. The default line spacing is 1.2 times the character height.
When Print starts a new line, it sets the x coordinate
of the cursor to 0 and increases the y coordinate by the current
line spacing. You can change the line spacing with the PrintSetSpacing function,
which lets you specify a new factor to be multiplied by the character
height.
Because Syntax 3 of Print increments the y coordinate each
time it creates a new line, it also handles page breaks automatically.
When the y coordinate exceeds the page size, PowerBuilder automatically
creates a new page in the print job. You do not need to call the PrintPage function,
as you would if you were using the printing functions that control
the cursor position (for example, PrintText or PrintLine).
Print area and margins
The print area is the physical page size minus any margins
in the printer itself.
Using fonts
You can use PrintDefineFont and PrintSetFont to
specify the font used by the Print function when
you are printing a string.
Fonts for multiple languages
The default font for print functions is the system font, but
multiple languages cannot be printed correctly using the system
font. The Tahoma font typically produces good results. However,
if the printer font is set to Tahoma and the Tahoma font is not
installed on the printer, PowerBuilder downloads the entire font
set to the printer when it encounters a multilanguage character.
Use the PrintDefineFont and PrintSetFont functions
to specify a font that is available on users’ printers
and supports multiple languages.
Examples
This example opens a print job, prints the string Sybase in the default font, and then starts
Corporation
a new line:
|
1 |
long Job |
|
1 |
|
1 |
// Define a blank page and assign the job an ID |
|
1 |
Job = PrintOpen( ) |
|
1 |
|
1 |
// Print the string and then start a new line |
|
1 |
<span>Print</span>(Job, "Sybase Corporation") |
|
1 |
... |
|
1 |
PrintClose(Job) |
This example opens a print job, prints the string Sybase in the default font, tabs 5 inches
Corporation
from the left edge of the print area but does not start a new line:
|
1 |
long Job |
|
1 |
|
1 |
// Define a blank page and assign the job an ID |
|
1 |
Job = PrintOpen( ) |
|
1 |
|
1 |
// Print the string but do not start a new line |
|
1 |
<span>Print</span>(Job, "Sybase Corporation", 5000) |
|
1 |
... |
|
1 |
PrintClose(Job) |
The first Print statement below
tabs half an inch from the left edge of the print area, prints the
string Sybase Corporation,
and then starts a new line. The second Print statement
tabs one inch from the left edge of the print area, prints the string Directors:,
and then starts a new line:
|
1 |
long Job |
|
1 |
// Define a blank page and assign the job an ID |
|
1 |
Job = PrintOpen( ) |
|
1 |
// Print the string and start a new line |
|
1 |
<span>Print</span>(Job, 500, "Sybase Corporation") |
|
1 |
// Tab 1 inch from the left edge and print |
|
1 |
<span>Print</span>(Job, 1000, "Directors:") |
|
1 |
... |
|
1 |
PrintClose(Job) |
The first Print statement below
tabs half an inch from the left edge of the print area prints the
string Sybase Corporation,
and then tabs 6 inches from the left edge of the print area but
does not start a new line. The second Print statement
prints the current date and then starts a new line:
|
1 |
long Job |
|
1 |
// Define a blank page and assign the job an ID |
|
1 |
Job = PrintOpen( ) |
|
1 |
// Print string and tab 6 inches from the left edge |
|
1 |
<span>Print</span>(Job, 500, "Sybase Corporation", 6000) |
|
1 |
// Print the current date on the same line |
|
1 |
<span>Print</span>(Job, String(Today())) |
|
1 |
... |
|
1 |
PrintClose(Job) |
In a window that displays a database error message
in a MultiLineEdit mle_message, the
following script for a Print button prints a title with the date and
time and the message:
|
1 |
long li_prt |
|
1 |
li_prt = PrintOpen("Database Error") |
|
1 |
Print(li_prt, "Database error - " & |
|
1 |
   + String(Today(), "mm/dd/yyyy") & |
|
1 |
      + " - " & |
|
1 |
      + String(Now(), "HH:MM:SS")) |
|
1 |
<span>Print</span>(li_prt, " ") |
|
1 |
<span>Print</span>(li_prt, mle_message.text) |
|
1 |
PrintClose(li_prt) |