StyledTextPrinter
From Xojo Documentation
Class (inherits from Object)
This class is only available on the macOS platform. For cross-platform compatibility, use #If...#Endif with the Target... specifiers to make sure you will not attempt to use this class on an incompatible platform. |
Used to print styled text stored in a TextArea.
Properties | ||
|
Methods | |
|
Notes
StyledTextPrinter no longer works on Windows starting with 2016r4. |
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
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
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.