StyledTextPrinter

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)


Used to print styled text stored in a TextArea.

Properties
EndOfText fa-lock-32.png Width
Methods
DrawBlock

Notes

StyledTextPrinter is not supported on Windows and will raise an UnsupportedOperationException if called.

Sample Code

The following code prints the styled text in a TextArea. The TextArea's MultiLine and Styled properties must be set to True to accept and print styled text.

Var stp As StyledTextPrinter
Var g As Graphics
g = OpenPrinterDialog
If g <> Nil Then
// 72 pixels per inch * 7.5 inches
Var textWidth As Integer = 72 * 7.5
stp = TextArea1.StyledTextPrinter(g, textWidth)
stp.DrawBlock(0, 0, 72 * 10)
End If

This code prints the contents of TextArea1 in two columns with a quarter-inch of spacing between them. The EOF property is used to determine if all the text has been printed. When EOF is False, it prints the second column or prints another page.

Var g As Graphics
Var stp As StyledTextPrinter
Var columnWidth, spaceBetweenColumns, pageHeight As Integer
Var columnToPrint As Integer
columnWidth = 261
// 7.5 inches minus 1/4 inch for space
// divided by 2
spaceBetweenColumns = 18
// 18 pixels is 1/4 inch
pageHeight = 10 * 72
// 10 inches * 72 pixels per inch
g = OpenPrinterDialog
If g <> Nil Then
stp = TextArea1.StyledTextPrinter(g, 540)
stp.Width = columnWidth
columnToPrint = 1
Do Until stp.EndOfText
stp.DrawBlock((columnWidth + spaceBetweenColumns) * (columnToPrint - 1), 0, PageHeight)
If columnToPrint = 2 Then // printing last column
If Not stp.EOF Then // more text to print
g.NextPage
columnToPrint = 1
End If
Else // more columns to print on this page
columnToPrint = columnToPrint + 1
End If
Loop
End If

See Also

TextArea control; OpenPrinter, OpenPrinterDialog functions; Graphics, PrinterSetup classes.