Kraft Project

Configuration

Documentation


openSUSE.org

Output document

The design of the output document can be changed to meet users needs. The can be done without changing the program code of Kraft but editing the document template. The documents are defined in a language called RML (Report Markup Language) which is a XML format. RML is developed and maintained by a company called ReportLab.

The RML file gets transformed into PDF by Kraft automatically. A Kraft document template contains template variables, which get replaced by document content such as customer name, items etc. by Kraft before the PDF gets rendered.

For each document type a different customized template can be used. In the Kraft Configuration dialog, on tab Document Type, the custom file can be picked for each document type individually.

Detailed information about RML can be found in the RML Userguide (PDF, 530 kB).

There is a list of available template variables which Kraft replaces before rendering.

Example: Insert a logo into the document template

This is an example how to insert a company logo into a ReportLab based document template so that the resulting PDF has that logo.

In the template file, there is a section calld pageTemplate. It defines the layout of the single pages in the output document. It also defines the elements that should be displayed on the same place on a page, ie. non floating elements such as the logo.

Because the first page is usually different than page two and onwards, there are different templates: One with the id "first" for the first, and another with the id "others" for the following pages. The example logo should be displayed on the first page in the upper right corner. It only needs to go in the pageTemplate with id "first".

Within the pageTemplate there is a section pageGraphics. There are graphical elements like fixed texts and lines described.

The logo image file can be inserted here in XML notation: <image x="140mm" y="22cm" width="6cm" height="6cm" file="/home/me/pics/logo.png" />

The x and y coordinates are measured from the left bottom corner of the page. Additionally the width and height of the image display is specified. The file attribute has the absolute file path of the image.

If all goes well, the next print to PDF will contain the image.

This is the full pageTemplate section of a template for example:

    <pageTemplate id="first">
        <pageGraphics>
            <setFont name="Times-Roman" size="12" />
            <lineMode width="0.5" />
            <lines>2.41cm 2.2cm 19cm 2.2cm</lines>
            <fill color="darkgreen" />
            <drawCentredString x="105mm" y="2.3cm">{{MY_NAME}} {{MY_ORGANISATION}}</drawCentredString>

            <lines>7mm 19cm 12mm 19cm</lines>
            <lines>2mm 14.65cm 12mm 14.65cm</lines>

            <fill color="black" />
            <setFont name="Times-Roman" size="8" />
            <drawString x="25mm" y="24.7cm">{{MY_ORGANISATION}} - {{MY_STREET}} - {{MY_POSTCODE}} {{MY_LOCALITY}}</drawString>
            <lines>25mm 24.6cm 11cm 24.6cm</lines>
            <setFont name="Times-Roman" size="10" />
            <drawCentredString x="105mm" y="1.8cm">{{MY_STREET}} - {{MY_POSTCODE}} {{MY_LOCALITY}}</drawCentredString>
            <drawCentredString x="105mm" y="1.4cm">Telephone {{MY_PHONE}} - Fax {{MY_FAX}}</drawCentredString>
            <drawCentredString x="185mm" y="1.4cm">Page <pageNumber/></drawCentredString>
            <image x="140mm" y="22cm" width="6cm" height="6cm" file="/home/me/pics/logo.png" />
        </pageGraphics>
        <frame id="address"  x1="2.41cm" y1="20.62cm" width="8.5cm" height="4cm"/>
        <frame id="info"     x1="12cm" y1="20.62cm" width="7.41cm" height="1.5cm"/>
        <frame id="subject"  x1="2.41cm" y1="18.2cm" width="17cm"  height="1.2cm"/>
        <frame id="detail"   x1="2.41cm" y1="3cm"  width="17cm"  height="15cm"/>
    </pageTemplate>

Page: Main.Documenttemplate - Last Modified : Tue, 15 Mar 22

Copyright 2009-2020 Klaas Freitag and the Kraft Team