This section contains very valuable information to understand how the XML to PDF conversion takes place. First of all we will describe when and how areas are generated, then we will explain how the layout of the fields in the areas occur and last we will explain the meaning of the properties of each object involved in the template.
In most cases your templates will have only one page master, that is, all pages look the same, they just contain different data. A page master describes the layout of a type of page and the areas it contains, including page header and page footer. What to do however if you want to have no page header and no page footer in the first page? in that case the first page would be using a different page master. This is for example the case when you want to have a cover page followed by the regular pages.
The departmentEmpCoverPage.xre contains such a template.
Each template can have up to 5 page masters that can be selected from the Outline view. Note the page master 1 must always be active but master 2 to 5 must be explicitly be activated, see "Master active" property in the screenshot below.
Note the XML schema and test data are common to all page masters. All page masters share the same source data (XML data), they just create different pages with different layouts.
If you run the provided template and generate the PDF, you will
see the output is a PDF file with 3 pages, where the first page
is the report cover page.
Properties of the page master
In the name section
the name
the activation flag
the condition. This is an Xpath expresion to
make masters optional
In the Dimensions section you can define a different page size
and orientation for the master which overrides the report
settings in the report properties.
The following screenshot shows a PDF file which can be split in 5 areas:
- The header of the page (in this case it is empty).
- The header of the document (in this case the header of a purchase order).
- The header of the detail area, it contain the labels of the columns in the detail area.
- The detail area, in this case 2 repetitions (lines) of the detail area.
- The footer of the document (commonly used for showing totals).
- Additionally there is a page footer (not shown in this screenshot) which can contain, for example, the page number.
In the same way a normal business document contains this kind of areas the template you create in the FO designer contains also the following types of area:
- One template header and footer. Each PDF file will normally contain only one document header and one document footer, however it is possible to have several headers in one PDF file, for example if you are printing several invoices in one PDF file.
- One page header and footer. These areas are printer in each page
- detail areas (optional).
- Area can have subareas. Each time an area is generated (added to the PDF file), the dependent (sub)areas will be generated. The template Header is the first area generated , afterwards all first level areas (those that are right below the master in the outline view)
- the XML node property specifies when the area must be generated. The XML node property contains an XPath expression which points to an element in the input XML file. The area will be generated if the element exists in the XML file, if several elements exist, several repetitions of the areas will be generated. If the XML Node property is left empty, the area will be generated only once.
- Detail areas may have a detail area header (as in area
number 3 in the screenshot above), this header area however
can be removed from the PDF output (see Visible checkbox
below)
The delivery includes a file called order.xre which is the template used to create the above PDF file. This template uses a XML purchase order (using the xcbl schema) as input file. The following screenshot provides and overview of the schema:
The root element is called Order, under this root element there is a OrderHeader element, a OrderDetail element and a OrderSummary element.
In the following screenshot you see an overview of the template
file.
It contains the 6 areas we mentioned above:
- The document header (contains the purchase order header) and footer (contains the total values)
- The page header (is empty) and footer (contains the page number)
- The detail area (for the articles) and the columns header of the detail area.
When the template is executed:
- The page header and footer will be added to each page
- The Header area will be generated. If the XML node property is empty, the area will be generated only once, if it contains a XPath expression as in this case, it will be generated as often as elements are return by the XPath expression. In the example the header will be created once for each /Order element in the input XML file.
- For each instance of the header , the dependent areas will
be generated. These will be all first level areas (the ones
right below the master in the outline view). In this case the
Detail area.
so we know the detail area will be generated after the header area , but how often? this depends on the XML node property (see arrow 1 in the screenshot). In this example we will create one repetition (line of the detail area) for each ItemDetail node in the input XML file. In other words, we will create one detail line for each item in the purchase order.
Last as you see in the Visible property in the „Detail Columns header“ this header which will be generated before the detail area and contain the labels of the columns.
In this example each XML input file can contain only 1 purchase
order, however let's suppose it does contain two /Order
elements. In this case we would get two instances of the
header area and of course we want the items belonging to the
first order to be selected when the first header has been
generated and the items belonging to the second order to be
selected after the second header has been generated. That is why
the XML node type property of the detail
area has been set to relative.
That means, select only the ItemDetail elements which belong to the /Order element being generated. If you for example set that value to absolute, you would be selecting all items in the XML file, not only those belonging to the current order.
The same logic applies to the individual fields. Each field has a XPath property and XPath type property:
In the screenshot above you can see the value for the description field will be selected from the ItemDescription element which is located somewhere below the ItemDetail an element (which is the XML Node of the area). Since we want to select the item description of the current ItemDetail node, we set the XPath type to relative.
How to analyze the report execution
The magnifying glass in the toolbar will trigger the creation of the PDF file and will trace the execution of the XSLT engine.
Let‘s run this feature for the departmentEmployees.xre report. This report will create a new report for each department (note the /departments/department node in the Header area), and will list all the employees of the department (/departments/department/person node selection).
The input test XML file will be:
If we click on the PDF button the result will be as below since the test XML file contains 2 departments with 4 and 2 employees each.
Click now on the Analyze button, a new window will open.
- First the „Area Header“ will be generated (step 1), but only if there are „departments“ in the input XML file (step 2, runs a test on XPath departments/department). Since step 2 determines there are departments, it will select them (step 3), which returns 2 departments. This means for each one of these departments a new report header area will be generated.
- Next you see the 2 constant labels „lblEmployees“ and „lblDepartment“ (the constant value itself is not visible in the trace) and the one variable field „fldDepartment“ begin generated. In step 1 the executed XPath expression for the variable field is visible, in step 2 the result of the XPath will be displayed (in this case the value „R & D“)
- Now the detail area will be generated. That is, the list of employees belonging to the first department. As in the case of the report header, there is first a test to check whether the area will be generated at all. In this case, the detail area will be generated 4 times.
- For each person (detail area), a comment „repetition of Detail“ can be found in the trace.
- Further down in the trace the second repetition of the Header (second department node) can be found. The second department name „Sales“ has been generated, a new detail area will be created, this time with 2 employees.
XSL / FO Troubleshooting
In case you get an XSL or FO error while running the report you can use this the trace to find the location. For example , when there is an execution error the trace shows the link below
The link will open the location of the XSL or FO trace where the error happened (red text below). This make is easy to locate and fix errors because of the comments located nearby
Areas can have background color or background images, the available options are:
- Set the opaque property to Yes (check) and select a background color
- or set the opaque property to No (uncheck) and
set a background image. The background image can be align
horizontally and vertically by using the Background
align properties. Select the image in the local
system (back Image field), for later execution on the
server, fill in the „Image dir. Server“.
You can use the „show b. Image“ flag for showing the image in the designer, if you remove this flag the image will still be created in the output but not shown in the designer
- The embed image will include the image in the xslfo file as
base64 resource so no image file will be required at runtime,
Finally the scale flag will scale the image in a uniform way
(i.e. without changing the aspect ratio)
The BackgroundAlign.xre example shows how to use a background image and align some data fields to the background contents.
In order to align the field to the background the following flag must be set:
Note this means fields may not grow since they could overlap other fields placed at fixed positions.
The embed setting will include the image within the xslfo file so there is no need of having the image in a separate image file.
Finally the scale image flag will scale the image to fill the area. It is however recommended to provide at image with the correct size since scaling can distort the image. The image must be approximately 37,5 per CM (or 96 pixels per inch)
The background area contains objects that will be placed on
each page at a fixed location. The background area is located as
last area in the Master object in the outline view:
as with header areas you can remove the area from the output using the visibility flag in the area properties view.
If you use the background area, make sure regular areas have the opaque property set to false otherwise they will be overlap the background area.
You can see an example of a background area in tasks_background.xre.
It is possible to add the original input XML file to the PDF file as an attachment. In the report‘s properties that are two entries:
• XML attachment. Set this flag to add the input XML to the PDF
• Attach. Name: enter here a Xpath or constant value. If empty the attachment name will be generated at runtime.
After setting the properties as above the xml file will be available as an attachment
The metadata tab in the properties can be used to set the PDF metadata information as below
The result will be visible in the File – properties menu of the PDF viewer
The two PDF modes properties can be set to make sure the PDF is complaint with the following standards:
• PDF/A-1b : more information at https://en.wikipedia.org/wiki/PDF/A
• PDF/X-3:2003 : more information at https://en.wikipedia.org/wiki/PDF/X
FO designer will always internally create a
You use the Row and Column marker object of the palette and
place them in the position where you want to have the row and
column separation of the generated table
The cases where you need to define the columns and rows separator yourself are:
- if you have an object that expands several rows (for example an image)
- if you want to paint a frame or line around the column, row or cell ( see the frame properties in the area's properties)
- in case the automatic layout of fields does not produce the expected output, you may need to define the columns and rows yourself to have a better control how the objects will be aligned.
The following example illustrates case 1. The following screenshot shows a purchase order template with an image on the right side
the output PDF is:
the problem here is the image and the "Purchase order" text are placed on the top which is correct but all other fields and moved further down in the page. If you however define the rows and columns yourself like this:
the output will look correct because you tell the designer the area has 2 rows, in the first one you have the "Purchase order" text and the image, furthermore the image occupies both rows.
Note the rules for placing the column and row separators are:
1.Objects can span one or more rows, if they span more than 1 row, no other objects must be placed in the cells below it (as in the logo image object above)
2.Objects can span one or more columns. See for example, Name, address and City fields above, they occupy columns 1 and 2.
3.You can have several objects in one cell but they have to be place at different heights (top to bottom placement). Placing several objects in the same cell, from left to right will not produce the desired output.
The following example illustrates case 3. If you remove the columns separator between the Number:
Number field like this:
You have now 2 objects at the same height and the output will be incorrect (see below) because the designer is unable to put 2 object at the same Y position unless there is a column separator:
Note: if you do not create any column, the designer will automatically (internally) do it for you, however if you define at least one column separator, the automatic mode will be disabled and in this case you have to place all columns separators (as shown in this last example).
Drawing lines with columns and rows markers
Columns and row marker can be used for drawing vertical and horizontal lines. By clicking on the marker icon, the properties will be displayed. If the property yes, the line will be painted.
Conditional data using row
conditions
Some properties of the object, like the position (X and Y) and
size are
Select the report object in the outline view to display the properties of the template.
- Date format: format of the dates in the input XML file. The default one is yyyyMMdd"T"hh:mm:ss. This property is important if the template has to reformat the date fields (see format property in the field object). This is the input date format in the XML file.
- Orientation: horizontal for landscape and vertical for Portrait.
- Size: page size. it can be custom or predefined.
- Margins: define the margins of the page.
- Name: name of the template, used for information purposes only.
- Base template file: this is a template report file which contains 3 areas (page header, page footer and background area). It can be used to have a common page header for all reports in a company (see the Base Template example further down in this document)
- Documentation: free text for documentation purposes
Click on the area ruler or on the area in the outline view to display the area‘s properties:
- XML Node: if this element is empty, the area will be generated only once. If this area however contains a XPath expression, the area will be generated as many times as elements returned by the XPath.
- XML Node Type: If absolute the XPath will be evaluated as you see it in the designer. If relative, the XPath will be relative to the current element (XML Node property) in the super area.
- XML Sort: enter an XPath if you want to sort the elements returned by the XML Node property. The XML Sort property is a XPath that returns a list of elements used as key for sorting. For example, you could set the XML Node to be the items in the purchase order as in our example /Order/OrderDetail/ListOfItemDetail/ItemDetail. The you could sort using the article number /Order/OrderDetail/ListOfItemDetail/ItemDetail/BaseItemDetail/ItemIdentifiers/PartNumbers/BuyerPartNumber/PartNum/PartID.
- XML Sort type: whether the sorting elements are numeric of alphanumeric values.
- XML Sort order: ascending or descending.
- XML Group by: used for grouping values (see additional section of this topic)
- Local group: select this if the grouping shall
not be propagated to the subareas.
- Set row height: this setting makes sure the
area will have the same height as you define in the
designer. If you remove this setting the area will shink
when there is no data in it. In some cases if you have
conditional fields (using flavours) this can be useful to
avoid empty spaces.
- Background: background color of the area
- Background image: select background image for the area.
- Back H align: horizontal alignment of the background image.
- Back V align: vertical alignment of the background image.
- Image dir server: directory where the file will be found at runtime.
- Show b image: show or hide image in the designer.
- Scale b image: Scale the image to fill the area , the aspect ratio will not change.
- Embedd b image: embed the image in the XSLFO as Base64 encoded resource.
- Frame: select a value different from NONE to enable the area's frame. Possible values are: o AREA BORDER: paint only the border of the area
- ONLY ROWS: paint only horizontal lines to separate area repetitions and rows within the area.
- ONLY COLUMNS: paint only vertical lines to separate columns in the area (see column markers).
- GRID: all above will be painted.
- Frame color: select the color with the color .
- Frame style: select one of the styles
- Frame width: select THIN, MEDIUM or THICK.
- New page (page break): if true the area will be generated in a new page.
- Keep together (in detail areas only): if true the area will be printed in the next page when not all fields fit in the current page.
- Fixed fields: This flag allows placing the fields at a fixed position in the area. This means fields are not allowed (shall not) to expand since they have fixed positions and would overlap the fields below or to the right. Also this setting disables the creation automatic of columns and rows, furthermore columns and row markers you place in the area will be ignored. The main purpose of this flag is to align the fields to a fixed background image (for predefined form images).
- Rows per page: if you set this value to a number higher than 0, a new page after X repetitions of the area (being X the number you enter).
Click on the object to display its properties.
- constant: set it to true if this is a constant field (ie. a label). Note if a field has been declared as constant (as a label), the border will be black instead of blue, in this way you can easily recognize which fields contain variable data and which field are labels.
- value: constant value (instead of using a XPath). It will be used if the constant property is set to true or the XPath property is empty.
- XPath: path to the source XML element of this field. It can be any valid XPath expression, that is, it can contain conditions and functions. The employee tutorial contains an example how to use functions and the invoice IDOC example uses the condition technik extensively.
- XPath type: If absolute the XPath will be evaluated as you see it in the designer. If relative, the XPath will be relative to the current element (XML Node property) of the area.
- Align: text alignment
- Background: select background color of the field.
- Background opaque: set it to true to activate the background color.
- Border: set it to true to activate the border of the field
- Border Color, Style and width: properties of the border.
- FO attributes: any
xsl-fo attributes to add to the field. Note this might lead to errors if you use attributes not compatible with the one generated by the designer. - Font: currently only the
built-in fonts are supported (SansSerif, Courier, Times Roman and Symbol). - Font color: self explanatory.
- Format: output format for dates and numbers. For numbers the format is:
- # denotes an optional digit.
- 0 denotes a digit.
- . decimal point.
- , is the group separator for thousands.
- ; Pattern separator. The first pattern will be used for positive numbers and the
- second for negative numbers.
- % percentage sign
- y: year
- M: month
- day of month
- H: hour
(0-23) - m: minute
- s: second
- Rotation: use this field to rotate the text
- Preserve LF: set it to true to keep all spaces in the value..
Click on the object to display its properties (see also properties of a text field).
- Key List: a list or key/value pair. The element returned by the XPath will be used as key to find the value in the list. This value will be the output in the PDF File.
- Memo text: contains the long styled text.
- Variables: Xpath for the placeholders in the memo text. The variable placeholder texts are $1 to $5 . See HelloWorldMemo example in this document.
Click on the object to display its properties (see also properties of a text field).
- Image: path to the image. There are 3 types of images (Constant property):
- CONSTANT FILE. These are fixed image files which can be loaded into the report.They do not have to be available at runtime. See for example order.xre.
- DYNAMIC FILE: these are images which are located on the file system but the name is calculated at runtime using a XPath expression. See example personCard.xre. We recommend placing images below the working directory. That will be either in the FODesigner directory or in the server, below the J4LFOPServer directory.
- FROM XML. These are images located inside the source XML
file as a base64 image, they are also referenced with an
XPath expression. See for example "order_logo.xml" and test
file "OrderSample-ABC-Image.xml".
- Load image in FO file (for constant images): select to load a base64 representation of the image, otherwise the image will be read from the file system at runtime.
- Local image URL (for constant images): if the the above flag is not selected this will be the location of the image in your computer at design time.
- Server image URL (for constant images): if the the above flag is not selected this will be the location of the image in the server at runtime.
- Scale to Fit: scale the image to fit the size of the picture object in the template.
- Scaling: the default behaviour is to scale the image
using "uniform" scaling which makes sure the aspect ratio of
the image does not change. Use
"non-uniform" if you want to scale the image without aspect ratio considerations. - Constant: see Image property.
- Type: set automatically when the image is loaded.
- Line Width: width of the line.
- Style: type of line (dots, dashed ...).
- Line length: (default 100%). You can define the length in % or in cm.
- Orientation: vertical or horizontal.
- Link label: label displayed in the PDF file. If empty, the www address will be shown.
- Value: www value, either as a constant value or as a XPath expression..
Properties of a free code objects
The free code objects are required when you need to add code to
the
The 2 main properties are:
Code: use the editor to add code. Note you have to use the prefix “fo:” for fo elements and the prefix “xsl:” for xls elements. Location: of the code. The code can be handled as attributes of the current cell/row/table or as standalone code before the area or inside the current cell.
Example 1
This simple code will add the work “Hello” to the output
In the code tab you will see the code has been added to the output
And in the preview tab you can see the generated PDF :
Example 2
This code shows how to store the value of an input field into a variable. The variable will be set before the area is created in this way it can then be used by all sub areas.
Select the property location „table before"
We can then place a text field in another area to read and show the variable (note you use the sign $ following by the variable name):
The output shows then the variable value:
The table frame object creates a complex frame (table like) around existing fields.Note this object is only a decoration object, it does not contain any fields or logic.
the properties are:
- rows: number of rows of the table.
- columns: number of columns of the table.
- round corners: select this flag to have round
corners in the tabke
- Line Width: width of border the line.
- Style: type of the border line (dots, dashed ...).
- Color: color of the border line.
- Background: select background color of the table.
- Background opaque: set it to true to activate the background color.
Properties of the cell
- expand down: set it to 2 to join the cell with the
one below. The value 3 will join 3 cells, and to on.
- expand right: set it to 2 to join the cell with the one to the right. The value 3 will join 3 cells, and to on.
- Line Width: width of the border line.
- Style: type of the border line (dots, dashed ...).
- Color: color of the border line.
- Background: select background color of the cell.
- Background opaque: set it to true to activate the background color.
Table frame object are always added to the background of existing objects. You work with table frames in this way:
- In order to select the table you can click on the empty spaces between the fields, or you select the table frame in the Outlibe window
- In order to select a table's cell you can double
click on the empty spaces between the fields, or you
select the cell object in the Outlibe window. Note the
naming of the cells is "cell <row> <column>".
- In order to resize a cell (and therefore the row or
column), you need to select the cell and drag the borders of
the cell, as you do with other objects.
the example order_tableframe.xre produces the output below, for this the properties of the table and cells area:
- the table has 3 rows and 3 columns.
- cell 0 0 (the top left) has property "expand rows" set to
3, so it will span the 2 cells below.
- cell 0 2 (the top right) has property "expand rows" set to 3, so it will span the 2 cells below.
- cell 0 1 (the top middle) and the 2 below have no change
in the properties.