Introduction
Printout definitions are stored in the c:\Retail\POS2\Printouts\ directory. Each definition is kept in a separate directory, the name of which is also the name of a given definition. At least three files defining the data source, the printout layout, and the printout formatting must be placed in the directory. Each of these files must be a valid xml file with a specified name. The exact structure of these files is described below.
Data source
The data source for a printout must be located in a file named Data.xml. The primary element of the file is data that needs to contain precisely one setf element. The setf element must contain one or more set elements.
Each set element represents one data set (the result of one SQL query). It must contain two subelements: name, defining the set’s name, and query, defining the SQL query.
Sample Data.xml file
<?xml version="1.0" encoding="utf-8"?> <data> <setf> <set> <name>SummaryAmount</name> <query> SELECT FORMAT(Value,'N2','pl-PL') as Amount, c.Symbol as Currency from Configuration.Currencies c, [Documents].[TradeDocuments] ts join Documents.Payments dp on dp.DocumentId = ts.Id where ts.Id = {0} and c.IsSystem = 1 </query> </set> <set> <name>DocumentRates</name> <query> SELECT cvr.Name as Name, FORMAT(dva.NetValue,'N2','pl-PL') as NetValue, FORMAT(dva.GrossValue,'N2','pl-PL') as GrossValue, FORMAT(dva.VatValue,'N2','pl-PL') as Vat FROM Documents.VATAggregates dva JOIN Configuration.VATRates cvr ON cvr.id = dva.VATRateId where DocumentId={0} </query> </set> </setf> </data>>
The query may be a standard SQL query or the name of a stored procedure that returns the desired result. To use a stored procedure, add the type attribute with the StoredProcedure value to the query element.
Data source parameters
When queries from the Data.xml file are executed, parameters are passed to them that depend on the printout’s type and context. The example above uses one @DocumentId parameter.
Printout layout
The content and layout of a printout is defined in the Layout.xml file. The primary element of the file is document. It must include at least the body element that contains the main printout body. Additionally, the document element may contain the title element and multiple header and footer elements. The content of the body, header, and footer elements may be composed of elements described in the Printout layout chapter. These elements may be nested.
Printout formatting
Printout formatting may be adjusted in the Styles.xml file. The primary element of this file is style, that contains elements defining the formatting of particular printout elements defined in the Layout.xml file.
One of the subelements of the style element is fonts, that specifies all fonts to be used for a given printout. It may contain one or more font elements that define the typeface, size, appearance, and style of a given font.
<font name="title" face="Arial" size="20" color="#9fc54c"/>
The attributes of the font element are:
- name – it specifies the font’s name
- face – it specifies the typeface’s name
- size – size given in points
- color
- style – it defines a font’s styles. it can contain one or more of the following values (separated with a space character): bold, italic, underline.
The fonts element should also contain one font element with the name attribute omitted. This font will be used as the default font of a given printout.
<fonts> <font face="Trebuchet MS" size="10"/> <font name="title" face="Arial" size="20" color="#9fc54c"/> <font name="header" face="Tahoma" size="8" color="#999999"/> <font name="summary_value" face="Trebuchet MS" size="15" color="#9fc54c" style="bold"/> </fonts>
In addition to the fonts element, the Styles.xml file may contain elements in the following schema:
<selectpr> <rule/> <rule/> [...] </selector>
In such a schema, selector determines whether rules subordinate to it are to be used for a given element. Most selectors have the same name as the element they style. For instance, to style a paragraph (p element in the Layout.xml file), the p selector should be used.
<p> <margin top="5"/> </p>
In the example below, all printout paragraphs will be assigned a 5-point upper margin.
Selectors may choose only some elements of a given type to be styled. To do so, it is necessary to add the class attribute to an element in the Layout.xml file and to a selector in the Styles.xml file. The selector will then choose only those elements that have the same value of the class attribute.
<p> <text font="normal"/> </p> <p class="title"> <text font="title"/> </p>
The above example will set the font of all paragraphs to normal, but those whose class attribute is title will be assigned the title font.
The detailed description of other selector attributes and the list of styling rules may be found in the Printout formatting chapter. The list of selectors and rules that can be used for a given element may be found in the description of particular elements in the Printout layout section.
Rules from the Styles.xml file are applied from top to bottom, i.e. if two selectors adjust the same element and contain the same rules with different values, then the value occurring later will be applied.
Printout layout
All available elements that can be used when creating a printout layout are described in this chapter. Descriptions of each element include the following sections:
- Contents – it describes which subelements can be placed within a given element
- Parameters – it describes all available attributes that can be added to an element
- Styling element – it contains the list of selectors that adjust a given element in the Styles.xml file
- Subelements – it is an optional section describing elements that can be found only within a given element. The description of each subelement is structured similarly as in the case of primary elements.
- Example – it presents a code snippet with an example of the use of a described element
Elements
Barcode
Description | Barcode |
---|---|
Contents | Inside the barcode element, text data to be encoded by this code is placed. |
type - it specifies a barcode type. Available values include:
|
|
Styling elements |
|
Example | <barcode type="Code 93"><data set="DocumentHeader" var="EAN" /> |
Body
Description | The main printout body. |
---|---|
Contents | Any non-text element. |
Parameters | None |
Styling elements |
|
Example | <?xml version="1.0" encoding="utf-8"?> |
Br
Description | Line break in the text. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters | None |
Styling elements |
|
Example | <p>Text<br/> in multiple<br/>lines</p> |
Data
Description | It returns data from a data source in text form. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters |
|
Styling elements | None |
Example | <barcode type="Code 93"><data set="DocumentHeader" var="EAN" /></barcode> |
Footer
Description | Printout footer. |
---|---|
Contents | Any non-text element. |
Parameters | page - printout page. If this parameter is not specified, the footer is treated as the main footer. Available values include:
|
Styling elements |
|
Example |
|
Header
Description | Printout header |
---|---|
Contents | Any non-text element. |
Parameters | page - printout page. If this parameter is not specified, the header is treated as the main header. Available values include:
|
Styling elements |
|
Example | <?xml version="1.0" encoding="utf-8"?> |
Horizontal and Section
Horizontal
Description | Division into sections arranged horizontally. |
---|---|
Contents | One or more section elements |
Parameters | None |
Styling elements |
|
Subelements |
|
Section
Description | Section. |
---|---|
Contents | Any non-text elements. |
Parameters | None |
Styling elements | weight - weight of column width. The default value is 1. |
Subelements |
|
Example for Horizontal and Section
<horizontal> <section><p class="sign">Document issued by</p></section> <section weight="0,1"></section> <section><p class="sign">Item(s) released by</p></section> <section weight="0,1"></section> <section><p class="sign">Date collected</p></section> <section weight="0,1"></section> <section><p class="sign">Item(s) collected by</p> <p class="footer">Page <pageNumber/> of <numOfPages/></p></section> </horizontal>
Hr
Description | Horizontal line |
---|---|
Contents | The element cannot contain any other elements. |
Parameters | None |
Styling elements |
|
Example | <p>text1</p> |
If
Description | A text element enabling the adjustment of a printout layout depending on any conditions. |
---|---|
Contents | The test element and at least one of the elements true and false |
Parameters | None |
Styling elements | None |
Subelements |
|
Test
Description | It contains a condition determining whether to add elements from the true or false section to a given printout. The condition may be any logical expression containing basic mathematical operations, comparisons. It can also contain parentheses. |
---|---|
Contents | Any text elements. |
Parameters | None |
Styling elements | None |
True
Description | It contains elements that will be used if a condition from the test section is met. |
---|---|
Contents | Any elements that may be placed in the parent of the test element. |
Parameters | None |
Styling elements | None |
False
Description | It contains elements that will be used if a condition from the test section is not met. |
---|---|
Contents | Any elements that may be placed in the parent of the test element. |
Parameters | None |
Styling elements | None |
Example for If
<if> <test><data set="DocumentsPositions" var="Id" /> < 3123</test> <true> <horizontal> <section weight="2"> <p><data set="DocumentsPositions" var="Name" /></p> <p><data set="DocumentsPositions" var="Barcode" /></p> </section> <section weight="3"> <p><data set="DocumentsPositions" var="Name" /></p> <p><data set="DocumentsPositions" var="Barcode" /></p> </section> </horizontal> </true> <false> <p><data set="Header" var="CompanyName" /></p> </false> </if>
Image
Description | An image from a database or disk. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters |
|
Styling elements |
|
Example | <image path="logowms.png" /> |
PageNumber
Description | The number of the current page. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters | None |
Styling elements | None |
Example | <footer> |
P
Description | A paragraph. |
---|---|
Contents | Any text element. |
Parameters | None |
Styling elements |
|
Example | <p class="date">Data di emissione: <data set="DocumentHeader" |
RowNumber
Description | The number of the current table row. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters | None |
Styling elements | None |
Example | <table set="DocumentPositions"> |
StaticTable
Description | A static table with a set number of columns and rows. |
---|---|
Contents | The head element and one or more row elements |
Parameters |
|
Styling elements |
|
Subelements |
|
Head
Description | An element defining a table header. |
---|---|
Contents | One or more column elements |
Parameters | None |
Styling elements | None |
Column
Description | An element defining a single table column. |
---|---|
Contents | Any non-text elements. |
Parameters | weight - weight of column width. The default value is 1. |
Styling elements |
|
Row
Description | An element defining a single table row. |
---|---|
Contents | One or more cell elements |
Parameters | None |
Styling elements | None |
Cell
Description | An element defining a single table row cell. |
---|---|
Contents | Any non-text elements. |
Parameters |
|
Styling elements |
|
Example
<staticTable class="customer"> <head> <column weight="1"><p class="tableHead">Secondary Customer</p></column> <column weight="1"><p class="tableHead">Customer</p></column> </head> <row> <cell> <p class="customer"><data set="DocumentHeader" var="CustomerName" /><br/> <data set="DocumentHeader" var="Street" /><br/> <data set="DocumentHeader" var="ZipCode" /> <data set="DocumentHeader" var="City" /><br/> IVA: <data set="DocumentHeader" var="Tin" /><br/> </p> </cell> <cell> <p class="customer"><data set="DocumentHeader2" var="CustomerName" /><br/> <data set="DocumentHeader2" var="Street" /><br/> <data set="DocumentHeader2" var="ZipCode" /> <data set="DocumentHeader2" var="City" /><br/> IVA: <data set="DocumentHeader2" var="Tin" /><br/> </p> </cell> </row> <row> <cell collspan="2"> <p>...</p> </cell> </row> </staticTable>
Table
Description | A dynamic table with a fixed or dynamic number of columns. |
---|---|
Contents | One or more elements:
|
Parameters |
|
Styling elements | |
Subelements |
Column
Description | An element defining a table column. |
---|---|
Contents | Any text elements. |
Parameters |
|
Styling elements |
|
Dynamic-columns
Description | An element defining the series of columns with a name defined by a regular expression. |
---|---|
Contents | Any text elements. |
Parameters |
|
Styling elements |
|
If
A conditioning element making it possible to hide or show selected columns.
See the generic If element.
TableData
Description | An element returning a text value from a data set, based on a table data set, a column indicated in the var parameter, and the current table row. |
---|---|
Contents | The element cannot contain any other elements. |
Parameters |
|
Styling elements | None |
Example 1 – Static and conditional columns
<table set="DocumentPositions"> <column weight="2" description="N." class="number"> <rowNumber /> </column> <column weight="12" description="[Code] Item name"> [<tableData var="Code" />] <tableData var="Name" /> </column> <if> <test> <hasColumn var="Column15" /> = 1 </test> <true> <column weight="2" description="Test" class="number"> <tableData var="Column15" /> </column> </true> </if> <column weight="4" description="Quantity" class="number"> <tableData var="RealizedQuantity" /> </column> <column weight="4" description="UOM (base)"> <tableData var="BasicUnitSymbol" /> </column> <column weight="4" description="Quantity" class="number"> <tableData var="SecondaryQuantityRealized" /> </column> <column weight="4" description="UOM (additional)"> <tableData var="SecondaryUnitSymbol" /> </column> </table>
Example 2 – Dynamic columns
<table set="DocumentPositions"> <column weight="2" description="N." class="number"> <rowNumber /> </column> <column weight="12" description="[Code] Item name"> [<tableData var="Code" />] <tableData var="Name" /> </column> <dynamic-columns weight="4" description="Currency {{1}}" names="Currency(.+)"> <tableData var="{{0}}" /> {{1}} </dynamic-columns>
Title
Description | A document title used to name a PDF file. |
---|---|
Contents | Any text element. |
Parameters | None |
Styling elements | None |
Printout formatting
This chapter describes all styling elements (selectors) and rules. The description of each selector contains the list of elements a given selector styles and the list of rules that can be placed within the selector.
The description of each rule contains the list of attributes that can be used for it.
Narrowing attributes
Each selector may be narrowed down with the class attribute. Additionally, element selectors related to tables may be narrowed down with the index attribute that can contain an integer or an expression in the form An+B, where A and B are integers. Such a selector adjusts an element if it is consistent with a table row index (table rows are numbered from 0, from top to bottom).
- index=”0″ – it adjusts the first table row
- index=”first” – it adjusts the first table row
- index=”last” – it adjusts the last table row
- index=”5″ – it adjusts the sixth table row
- index=”2n” – it adjusts even table rows, i.e. those with indexes equal to 0, 2, 4…, i.e. the first, third, fifth… row
- index=”3n+1″ – it adjusts rows with indexes equal to 1, 4, 7…
- index=”3n+2″ – it adjusts rows with indexes equal to 2, 5, 8…
Selectors
Barcode
Description | A selector for barcodes. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Body
Description | A selector for the main printout element. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Cell
Description | A selector for a cell in a static table. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
DataCell
Description | A selector for a cell in a dynamic table. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Footer
Description | A selector for a document footer. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
HeadCell
Description | A selector for a header cell in a dynamic table. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Header
Description | A selector for a document header. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Hr
Description | A selector for a horizontal line. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Image
Description | A selector for an image. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
P
Description | A selector for a paragraph. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Section
Description | A selector for a section. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
StaticTable
Description | A selector for a static table. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Table
Description | A selector for a dynamic table. |
---|---|
Styled elements |
|
Narrowing parameters |
|
Rules |
|
Rules
Background
A rule defining an element’s background.
- color – an element background color. It can be entered in the #RRGGBB or 0xRRGGBB or 0xAARRGGBB format.
Border
A rule defining an element’s border.
- left – the width of the left border.
- right – the width of the right border.
- top – the width of the top border.
- bottom – the width of the bottom border.
- color – the color of an element’s border. It can be entered in the #RRGGBB or 0xRRGGBB or 0xAARRGGBB format.
- borderStyle – a border’s style. It accepts the following values:
- dashdot
- dashdotdot
- dashlargegap
- dashsmallgap
- dot
- none
- single
Border width can be entered in different units, including cm, in, mm, pt. The default unit is pt.
Styling a selected border element
It is possible to style only a selected part of a border, e.g. only the left edge of an element. To do so, use one of the following selectors:
- borderLeft
- borderRight
- borderTop
- borderBottom
Each of these selectors can contain the following rules:
- width – a border’s width
- color – a border’s color
- borderStyle – a border’s style
Fit
A rule defining the size of an element.
Attributes
- width – an element’s width
- height – an element’s height
Width and height can be entered in different units, including cm, in, mm, pt. A styled element retains its proportions, taking the smaller of the specified dimensions.
Margin
A rule defining an element’s margins.
Attributes
- left – the left margin
- right – the right margin
- top – the top margin
- bottom – the bottom margin
Margin width can be entered in different units, including cm, in, mm, pt.
Page
Special rules for a page.
Attributes
- orientation – page orientation
- size – page size
- width – page width
- footer-distance – distance of the footer from the bottom of a page
- header-distance – distance of the header from the top of a page
Text
A rule defining a text style.
Attributes
- align – text alignment. It accepts the following values:
- right – right alignment
- left – left alignment
- justify – text justification
- center – text centering
- indent – the indentation of the first line of text.
- leftIndent – left indentation of text.
- rightIndent – right indentation of text.
- font – a font name defined earlier in the fonts section.
- color – text color. It can be entered in the #RRGGBB or 0xRRGGBB or 0xAARRGGBB format.
Width
A rule defining an element’s width.
Attributes
- percentage – the percentage width of an element based on the width of its parent element.