Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

Developer intro to printing

See also Printing with Lino in the User Guide.

This page is a tested document and the following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_book.projects.min9.settings')
>>> from lino.api.shell import *
>>> from lino.api.doctest import *

End users see a printable document by invoking the Print button on any database object whose model inherits from Printable.

The print action

Here is what happens when a user invokes the do_print action of a printable object:

  • Lino generates ("builds") the printable document on the server. For cached printables (see CachedPrintable), Lino may skip this step if that document had been generated earlier.

  • Lino delivers the document to the user by letting the action respond with open_url.

Build methods

Lino comes with a series of "build methods".

>>> rt.show(printing.BuildMethods)
============ ============ ======================
 value        name         text
------------ ------------ ----------------------
 appydoc      appydoc      AppyDocBuildMethod
 appyodt      appyodt      AppyOdtBuildMethod
 appypdf      appypdf      AppyPdfBuildMethod
 appyrtf      appyrtf      AppyRtfBuildMethod
 latex        latex        LatexBuildMethod
 pub          pub          PublisherBuildMethod
 rtf          rtf          RtfBuildMethod
 weasy2html   weasy2html   WeasyHtmlBuildMethod
 weasy2pdf    weasy2pdf    WeasyPdfBuildMethod
 xml          xml          XmlBuildMethod
============ ============ ======================

Template engines

A template engine is responsible for replacing template commands by their result. The template engine determines the syntax for specifying template commands when designing templates.

  • PisaBuildMethod and LatexBuildMethod use Django's template engine whose template commands look for example like {% if instance.has_family %}yes{% else %}no{% endif %} or My name is {{ instance.name }}..

  • RtfBuildMethod uses pyratemp as template engine whose template commands looks like @!instance.name!@. We cannot use Django's template engine because both use curly braces as command delimiters.

    This build method has a flaw: I did not find a way to "protect" the template commands in your RTF files from being formatted by Word.

Markup versus WYSIWYG

There are two fundamentally different categories of templates: WYSIWYG (.odt, .rtf) or Markup (.html, .tex).

Template collections that use some markup language are usually less redundant because you can design your collection intelligently by using template inheritance.

On the other hand, maintaining a collection of markup templates requires a relatively skilled person because the maintainer must know two "languages": the template engine's syntax and the markup syntax.

WYSIWYG templates (LibreOffice or Microsoft Word) increase the probability that an end-user is able to maintain the template collection because there's only on language to learn (the template engine's syntax)

Post-processing

Some print methods need post-processing: the result of parsing must be run through another software in order to turn into a usable format. Post-processing creates dependencies to other software and has of course influence on runtime performance.

Utility functions

Some usage examples of the lino.core.site.Site.decfmt() method:

>>> from lino.core.site import TestSite as Site
>>> from decimal import Decimal
>>> self = Site()
>>> print(self.decimal_group_separator)
\xa0
>>> print(self.decimal_separator)
,
>>> x = Decimal(1234)
>>> print(self.decfmt(x))
1\xa0234,00
>>> print(self.decfmt(x, sep="."))
1.234,00
>>> self.decimal_group_separator = '.'
>>> print(self.decfmt(x))
1.234,00
>>> self.decimal_group_separator = "oops"
>>> print(self.decfmt(x))
1oops234,00