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.
Applies to
Not object-specific
Syntax
|
1 |
Print ( printjobnumber, { tab1, } string {, tab2 } ) |
|
Argument |
Description |
|---|---|
|
printjobnumber |
The number the PrintOpen function assigned to the print |
|
tab1 (optional) |
The position, measured from the left edge of the print |
|
string |
The string you want to print. If the string includes |
|
tab2 (optional) |
The new position, measured from the left edge of the |
Return value
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 Appeon
Corporation in the default font, and then starts a new line:
|
1 2 3 4 5 6 7 8 9 |
long Job // Define a blank page and assign the job an ID Job = PrintOpen( ) // Print the string and then start a new line Print(Job, "Appeon Corporation") ... PrintClose(Job) |
This example opens a print job, prints the string Appeon
Corporation in the default font, tabs 5 inches from the left edge of the
print area but does not start a new line:
|
1 2 3 4 5 6 7 8 9 |
long Job // Define a blank page and assign the job an ID Job = PrintOpen( ) // Print the string but do not start a new line Print(Job, "Appeon Corporation", 5000) ... PrintClose(Job) |
The first Print statement below tabs half an inch from the left
edge of the print area, prints the string Appeon 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 2 3 4 5 6 7 8 9 |
long Job // Define a blank page and assign the job an ID Job = PrintOpen( ) // Print the string and start a new line Print(Job, 500, "Appeon Corporation") // Tab 1 inch from the left edge and print Print(Job, 1000, "Directors:") ... PrintClose(Job) |
The first Print statement below tabs half an inch from the left
edge of the print area prints the string Appeon 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 2 3 4 5 6 7 8 9 |
long Job // Define a blank page and assign the job an ID Job = PrintOpen( ) // Print string and tab 6 inches from the left edge Print(Job, 500, "Appeon Corporation", 6000) // Print the current date on the same line Print(Job, String(Today())) ... 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 2 3 4 5 6 7 8 9 |
long li_prt li_prt = PrintOpen("Database Error") Print(li_prt, "Database error - " & + String(Today(), "mm/dd/yyyy") & + " - " & + String(Now(), "HH:MM:SS")) Print(li_prt, " ") Print(li_prt, mle_message.text) PrintClose(li_prt) |
See also