Lino Website

Documentation · Modules · adamo · Examples

This example shows how to use TextPrinter objects.

Source code:

# -*- coding: latin1 -*-
def doit(tp):
    tp.writeln("TextPrinter Test page")
    cols = int(tp.lineWidth() / 10) + 1
    tp.writeln("".join([" "*9+str(i+1) for i in range(cols)]))
    tp.writeln("Here is some \033b1bold\033b0 text.")
    tp.writeln("Here is some \033u1underlined\033u0 text.")
    tp.writeln("Here is some \033i1italic\033i0 text.")

    tp.writeln("Here is some more text.")
    tp.writeln(u"Ännchen Müller machte groáe Augen.")
    tp.write("And here")
    tp.write(" is some")
    tp.write(" frag")
    tp.writeln("mented text.")

    tp.write("This is a very long line. ")
    tp.write("Just do demonstrate that TextPrinter ")
    tp.write("doesn't wrap paragraphs for you...")
    tp.write("Blabla bla. "*20)

if __name__ == "__main__":
    # do it on sys.stdout:
    from lino.textprinter.plain import PlainTextPrinter

    # do it in a PDF document:
    from lino.textprinter.pdfprn import PdfTextPrinter

    # do it in a HTML file:
    from lino.textprinter.htmlprn import HtmlTextPrinter

    # do it on the default printer:
    if False:
        from lino.textprinter.winprn import Win32TextPrinter


|                                                                        |
|TextPrinter Test page                                                   |
|                                                                        |
|         1         2         3         4         5         6         7  |
|                                                                        |
|Here is some bold text.                                                 |
|Here is some underlined text.                                           |
|Here is some italic text.                                               |
|Here is some more text.                                                 |
|Ännchen Müller machte groáe Augen.                                      |
|And here is some fragmented text.                                       |
|                                                                        |
|This is a very long line. Just do demonstrate that TextPrinter doesn't w|

To doit() method is called three times, each time with a different variant of textprinter Document instance.

A textprinter document has only three basic methods: write(), writeln() and endDoc().

Simple text formatting can be done by using escape sequences (as in the example) or by using the formatting methods setCpi(), setBold(), setItalic(), ...

write() may not be used to print several lines. Text that is longer than the document's lineWidth() will be cut off. This is usually what happens if you print too much text to a line of a physical text printer.

Refering articles:

Copyright 2001-2007 Luc Saffre.
Generated 2007-06-07 16:23:41