What's UBL4J?

UBL4J provides a Java implementation for Universal Business Language (UBL) Order to Invoice process. Given an UBL order document, it produces an UBL invoice document and renders its output to TeX, PDF or HTML formats. UBl4J uses the order document country and language information to tailor locale-sensitive invoices.

Installation

To install UBL4J, download UBL4J distribution file and extract it into your desired directory. By default, UBL4J reads its configuration from the .ubl4j.properties in the user home directory. Copy the cfg/ubl4j.properties file that is in your UBL4J install directory to your home directory, and adapt it to fit your needs. Refer to UBL4JConfigurationBean for configuration parameters that control the behaviour of UBL4J.

Customization

The invoice output file can be customized via the following files:

  • PDF rendering property file contains the PDF output configuration information such as layout and color information. Copy the cfg/PDFInvoiceRenderer.properties file that is in your UBL4J install directory, to your home directory, and adapt it to fit your needs.
  • TeX template file contains the TeX output template. See the TeX template resources/templates/invoice.tex, in your UBL4J install directory, for a sample file. You can adapt it to fit your needs and use the '-t' option to pass your customized TeX template to UBL4J.
  • HTML template file contains the HTML output template. See the HTML template resources/templates/invoice.html, in your UBL4J install directory, for a sample file. You can adapt it to fit your needs and use the '-t' option to pass your customized HTML template to UBL4J.

The UBL4J behaviour can also be customized via its API.

Usage

UBL4J is meant to serve as a framework or library, refer to OpenInvoice documentation to see how you can use UBL4J as a building block of your own application. But UBL4J can also be invoked via the command-line.

Command-line usage examples

Assuming that you are in the UBL4J install directory, the following command creates an invoice based on the UBL order, MyOrder.xml, and renders its output to PDF format by default. Also, by default the output invoice file is saved in the output directory (specified by the 'output.dir' property in the '.ubl4j.properties' file). By default, the invoice issue date and the invoice identifier are used to compose the invoice file name.

$ java -jar lib/ubl4j-0.6.jar -c MyOrder.xml

Assuming that you are in the UBL4J install directory, the following command creates an invoice based on the UBL order, MyOrder.xml, and renders its output to TeX format. '-f' option is used to specify the TeX format and '-t' option is used to specify the TeX template, MyTeXTemplate.tex. If the template is not specified, UBL4J uses its own default TeX template. '-o' option is used to specify the invoice output file.

$ java -jar lib/ubl4j-0.6.jar -c MyOrder.xml -f TEX -t MyTexTemplate.tex -o MyInvoice.tex

Assuming that you are in the UBL4J install directory, the following command creates an invoice based on the UBL order, MyOrder.xml, and renders its output to HTML format. The default HTML template is used to render the invoice output. The output invoice file is saved in the output directory (specified by the 'output.dir' property in the '.ubl4j.properties' file). The invoice issue date and the invoice identifier are used to compose the invoice file name.

$ java -jar lib/ubl4j-0.6.jar -c MyOrder.xml -f HTML

Java code snippet for transforming UBL order to invoice

The following code snippet shows how to create a UBL invoice based on an UBL order.

InvoiceCreationInput input = new CreateInvoiceBasedOnOrderInput();
File orderFile = new File(options.convertOrderToInvoice);
((CreateInvoiceBasedOnOrderInput)input).setOrderURI(URI.create(orderFile.toURI().getPath()));
CreateInvoiceBasedOnOrderTask task = new CreateInvoiceBasedOnOrderTask();
InvoiceCreationOutput output = task.execute(input);
System.out.println(output.toString());