Lino Website

Documentation · Modules · adamo · Examples

textprinter2.py

This script renders each sample input file using each available method. These sample input files give an overview of what TextPrinter can.

Source code:

import os
import glob

from lino.textprinter.plain import PlainTextPrinter
from lino.textprinter.pdfprn import PdfTextPrinter
from lino.textprinter.htmlprn import HtmlTextPrinter
from lino.textprinter.winprn import Win32TextPrinter

from lino import config

PSPRINTER=config.win32.get('postscript_printer')

OUTDIR=os.path.join(config.paths.get('webhome'),
                   "examples","textprinter")


def doit(inputfile,tp):
    print inputfile, "-->", tp.__class__.__name__
    tp.readfile(inputfile,encoding="cp850")
    tp.close()


if __name__ == "__main__":

    for fn in glob.glob("*.prn"):
        base,ext=os.path.splitext(fn)
        
        doit(fn,PlainTextPrinter())

        # do it in a PDF document:
        doit(fn,PdfTextPrinter(os.path.join(OUTDIR,base+".pdf")))

        # do it in a HTML file:
        doit(fn,HtmlTextPrinter(os.path.join(OUTDIR,base+".html")))

        # do it on a Windows printer:
        doit(fn,Win32TextPrinter(
            printerName=PSPRINTER,
            spoolFile=os.path.join(OUTDIR,base+".ps")))


Output:

1.prn --> PlainTextPrinter
+------------------------------------------------------------------------+
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                         Café           |
|                                                         "Le Pigalle"   |
|                                                                        |
|                                                                        |
|                                                         F - 51051 REIMS|
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                 +------------------------------------------------------|
|                  FACTURE 030001                          Votre réf..: |
|                  Date : 30 mars 2003                     Votre N° TVA:|
|                 +------------------------------------------------------|
|                 Description                                     Qté    |
|                 ----------------------------------------------- ------ |
|                 Tapis-plein bleu                                 20,00 |
|                 Tapis-plein vert                                 15,00 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|                 -------------------------------------------------------|
|                                                              Total hors|
|                                                Livraison intracommunaut|
|                                                                        |
|                                                                  (Monta|
|                 Paiement dès réception facture.                        |
|                                                                        |
+------------------------------------------------------------------------+
1.prn --> PdfTextPrinter
1.prn --> HtmlTextPrinter
1.prn --> Win32TextPrinter
2.prn --> PlainTextPrinter
+------------------------------------------------------------------------+
|                     ---------------------------------------------------|
|                     DEMONSTRATIONS-LIZENZ                        Seite |
|                     P.A.C. Systems PGmbH Eupen                  19.12.0|
|                     Tel. 087/59.35.50                           05:10:0|
|                                                                        |
|                                        Postleitzahlen                  |
|                     ---------------------------------------------------|
|                                                                        |
|                     ID  Bezeichnung                    S Vorwah T Wä  I|
|                     --- ------------------------------ - ------ - --- -|
|                     AU  Österreich                     D          EUR A|
|                     B   Belgien                        D 0032   1 EUR B|
|                     CH  Schweiz                        D          CHF C|
|                     D   Deutschland                    D 0049     EUR D|
|                     DK  Dänemark                       D          EUR D|
|                     E   Spanien                        D          EUR E|
|                     F   Frankreich                     D          EUR F|
|                     GB  Groábritannien                 D          UKP G|
|                     I   Italien                        D          EUR I|
|                     IE  Irland                         D          EUR I|
|                     L   Luxemburg                      D        1 EUR L|
|                     NL  Niederlande                    D          EUR N|
|                     PT  Portugal                       D          EUR P|
|                     USA United States of America       E          USD U|
|                                                                        |
+------------------------------------------------------------------------+
2.prn --> PdfTextPrinter
2.prn --> HtmlTextPrinter
2.prn --> Win32TextPrinter
20060829.prn --> PlainTextPrinter
+------------------------------------------------------------------------+
|------------------------------------------------------------------------|
|         1         2         3         4         5         6         7  |
|123456789012345678901234567890123456789012345678901234567890123456789012|
|                                                                        |
|The full line of 137 characters should be printed on both pages.        |
|This is page 1.                                                         |
|                                                                        |
+------------------------------------------------------------------------+
+------------------------------------------------------------------------+
|------------------------------------------------------------------------|
|         1         2         3         4         5         6         7  |
|123456789012345678901234567890123456789012345678901234567890123456789012|
|                                                                        |
|The full line of 137 characters should be printed on both pages.        |
|This is page 2.                                                         |
|                                                                        |
|                                                                        |
+------------------------------------------------------------------------+
20060829.prn --> PdfTextPrinter
20060829.prn --> HtmlTextPrinter
20060829.prn --> Win32TextPrinter
3.prn --> PlainTextPrinter
+------------------------------------------------------------------------+
|12 cpi (72 cpl):                                                        |
|------------------------------------------------------------------------|
|123456789012345678901234567890123456789012345678901234567890123456789012|
|         1         2         3         4         5         6         7  |
|------------------------------------------------------------------------|
|12 cpi (72 cpl):                                                        |
|------------------------------------------------------------------------|
|123456789012345678901234567890123456789012345678901234567890123456789012|
|         1         2         3         4         5         6         7  |
|------------------------------------------------------------------------|
|12 cpi (72 cpl):                                                        |
|------------------------------------------------------------------------|
|123456789012345678901234567890123456789012345678901234567890123456789012|
|         1         2         3         4         5         6         7  |
|------------------------------------------------------------------------|
|12 cpi (72 cpl):                                                        |
|------------------------------------------------------------------------|
|123456789012345678901234567890123456789012345678901234567890123456789012|
|         1         2         3         4         5         6         7  |
|------------------------------------------------------------------------|
|12 cpi (72 cpl):                                                        |
|------------------------------------------------------------------------|
|123456789012345678901234567890123456789012345678901234567890123456789012|
|         1         2         3         4         5         6         7  |
|------------------------------------------------------------------------|
|                                                                        |
|                                                                        |
+------------------------------------------------------------------------+
3.prn --> PdfTextPrinter
3.prn --> HtmlTextPrinter
3.prn --> Win32TextPrinter
4.prn --> PlainTextPrinter
+------------------------------------------------------------------------+
|         1         2         3         4         5         6         7  |
|123456789012345678901234567890123456789012345678901234567890123456789012|
|------------------------------------------------------------------------|
|                                                                        |
|Ännchen Müller machte groáe Augen                                       |
|Cède à César les pâturages reçues.                                      |
|Tõesti, ma ütlen teile, see ei ole ükskõik.                             |
|                                                                        |
|Line 10                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 15                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 20                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 25                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 30                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 35                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 40                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 45                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 50                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 55                                                                 |
|                                                                        |
|                                                                        |
|                                                                        |
|                                                                        |
|Line 60                                                                 |
|                                                                        |
+------------------------------------------------------------------------+
4.prn --> PdfTextPrinter
4.prn --> HtmlTextPrinter
4.prn --> Win32TextPrinter
5.PRN --> PlainTextPrinter
+------------------------------------------------------------------------+
|0         1         2         3         4         5         6           |
|0123456789012345678901234567890123456789012345678901234567890123456789  |
|+--------------------------------------------------------------------+  |
|               Rumma & Ko OÜ                                          |
|               Tartu mnt 71-5                                         |
|               10115 Tallinn                                          |
|                                                                      |
|                                                                      |
|                                                                      |
|                                                                      |
|+--------------------------------------------------------------------+  |
+------------------------------------------------------------------------+
5.PRN --> PdfTextPrinter
5.PRN --> HtmlTextPrinter
5.PRN --> Win32TextPrinter

Refering articles:

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:24:06