Create or modify a template of sample

Create or modify a template of sample

The labels are created using the FOP software, written in Java.

Here are the operations performed by the application to generate the labels:

  • for each concerned object (containers or samples associated to a container type, and if the container type is attached to a label model), an image of the QRcode is generated in the temp folder ;
  •  in the temp folder, a file in XML format is generated, containing the information to be printed on the label ;
    a file in XSL format, which contains the orders for creating the label, is also created in the same folder. The content of this file comes from a record from the label table ;
  • the PHP program uses FOP to generate, from the XML file and using the XSL file, a PDF file. One page of the file corresponds to a label (the mechanism used by label printers to separate them).

The configuration of the label template means defining both the content of the information that will be inserted in the QRCODE and the form that the label will take, i.e. the information that will be printed, the format, etc. The label template is then used to print the information on the label. This form uses the XSL syntax understood by FOP.

Defining the contents of the QRcode

QRcode is a standardized two-dimensional barcode format that can store up to 2000 characters in 8 bits.
The principle used in the application is to store the information in JSON format. To limit the size of the barcode, the names of the tags must be as small as possible. Here are the mandatory tags to be systematically inserted in a tag :

NameDescription
uidUnique identifier of the object in the database
dbDatabase identifier. It’s the value of APPLI_code parameter

Others informations can be inserted:

NameDescription
idMain working identifier
colCollection code, for samples
pnSampling protocol name
clpRisk code associated to the container
Others codesAll secondary identification codes defined in the parameter table Identifier types
Fields used in metadatathe codes for the fields used in the metadata description. A label template can only be associated with one metadata type

XSL file configuration

The particular syntax of the XSL file should only be modified while keeping the initial version (copy in a notepad, for example), to avoid losing an operational configuration due to a wrong setting.
Here is a description of the file contents and the fields that can be modified.

File header

It allows you to change the size of the label (maximum width and height). You should only change the page-height and page-width attributes. For margins (margin- attributes), be careful and check in particular that QRcodes are not cropped because of insufficient margins.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="objects">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="label"
page-height="5cm" page-width="10cm"
margin-left="0.5cm"
margin-top="0.5cm"
margin-bottom="0cm"
margin-right="0.5cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="label">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates select="object" />
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="object">

Label format

The content of the tag is described in the form of a table (fo :table tags). The first column contains the QRCode, the second column contains the associated text.
Here, two columns of identical size (4 cm each) are defined.

<fo:table table-layout="fixed" border-collapse="collapse"
border-style="none" width="8cm"
keep-together.within-page="always">
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="4cm" />
<fo:table-body border-style="none" >

The cells (table-cell) are inserted into a row (table-row):

<fo:table-row>

QRcode insertion

The QRcode is inserted in a block. The only information that can be modified is that concerning the
height (height attribute and width (content-width attribute)). Make sure that the height and width
are identical, and do not change any other information.

<fo:table-cell>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="src">
<xsl:value-of select="concat(uid,’.png’)" />
</xsl:attribute>
<xsl:attribute name="content-height">
scale-to-fit
</xsl:attribute>
<xsl:attribute name="height">4cm</xsl:attribute>
<xsl:attribute name="content-width">4cm</xsl:attribute>
<xsl:attribute name="scaling">uniform</xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:table-cell

Textual content

Other information is displayed in blocks, with one line per information category.
The label starts here with the establishment (here, IRSTEA), written in bold.

<fo:table-cell>
<fo:block>
<fo:inline font-weight="bold">
IRSTEA
</fo:inline>
</fo:block>

Each piece of information is displayed in a block, including a title (for example, uid), associated with one or more values. Thus, the first line displays on the same line, and in bold (font-weight=”bold” attribute), the database code (&lt.xsl :value-of select=”db”/>) and the UID of the object (&lt.xsl :value-of select=”uid”/>).

<fo:block>uid:
<fo:inline font-weight="bold">
<xsl:value-of select="db"/>:
<xsl:value-of select="uid"/></fo:inline>
</fo:block>
<fo:block>id:
<fo:inline font-weight="bold">
<xsl:value-of select="id"/></fo:inline>
</fo:block>
<fo:block>prj:
<fo:inline font-weight="bold">
<xsl:value-of select="prj"/></fo:inline>
</fo:block>
<fo:block>clp:
<fo:inline font-weight="bold">
<xsl:value-of select="clp"/></fo:inline>
</fo:block>

Label end

Once all the information is displayed, the table is closed, and a page break is systematically generated:

</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<fo:block page-break-after="always"/>

Finally, the XSL file is correctly closed:

</xsl:template>
</xsl:stylesheet>

It is possible to create labels with different formats, for example by creating several
lines. Remember to close your tags, and make sure they are nested correctly, to avoid any worries.
To go further in the layout, consult the project documentation FOP.

Modification date : 15 May 2023 | Publication date : 22 March 2023 | Redactor : Éric Quinton