Document code examples


Handling document content

It is possible to save a generated document directly into a business object document field (obj is the business object):

obj.getField("myDoc").setDocument(obj, "mondoc.pdf", bos.toByteArray());;

QRCodes images

As of version 3.0, the standard QRCodeTool helper class provides various methods for generating QR codes images as PNG.

Typical usage is to set an image field with a URL QR code:

var appURL = getGrant().getContextURL();
obj.getField("myQRCode").setDocument(obj, "qrcode.png", QRCodeTool.qrCodeImage(appURL));

Barcodes images

As of version 3.1, the standard BarcodeTool helper class provides various methods for generating EAN13 Barcodes.

EAN13 checksum

The BarcodeTool.checkSum method can be used to calculate the checksum digit of a code. Typical usage is:

var code = "123456789012"; // 12 digits code
code += BarcodeTool.checkSum(code); // 13 digits code with checksum

EAN13 barcode image

A EAN13 code (12 digits + 1 checksum digit) can then be used to generate a JPEG image, for instance to set an image field:

obj.getField("myEAN13Barcode").setDocument(obj, code + ".jpg", BarcodeTool.ean13Image(code));

PDF documents using iText® 2.1.7

To use the iText® library classes you need to include the com.lowagie.text package explicitly.

For more information on itext 2.1.7 available on javadoc


var bos = new;

var pdf =;
pdf.add(new Paragraph("Hello world !"));

var bytes = bos.toByteArray();
// Do something with document content...

Note that it is possible to insert resource images in the PDF document, e.g.:

pdf.add(PDFTool.getImageFromResource(this.getGrant(), "MYIMAGERESOURCECODE"));

Excel(R) sheet using Apache POI®

To do advanced manipulation with the Apache POI® library you need to explicitly import the org.apache.poi.* package.

The examples bellow are simple and only uses the wrapper tool:

Create sheet fron scratch

var xls = new ExcelPOITool();
var s = xls.newSheet("MyNewSheet");
var r = xls.newRow(0);
var c = xls.newCell(0, "Hello World !");
var bytes = xls.generateToByteArray();
// Do something with document content...

Using an existing template sheet

var xls = new ExcelPOITool(this.getGrant(), doc);
var wb = xls.getWorkbook();
var s = wb.getSheetAt(0);
var r = sh.getRow(0);
var c = r.getCell(0);
c.setCellValue("Hello again World !");
var bytes = xls.generateToByteArray();
// Do something with document content...

In the above example doc is a Simplicité® document.

For instance you can get it: