Create labels: the report application (Java)

A common use of reports is to create a page of labels, such as address labels. Creating labels requires you to create a report design document representing a single label and a report application that prints multiple labels on a page.

Create the report design document

The report design document (.4rp) contains the design for a single label. You can put anything you wish on the label, as long as it fits onto the page.

See Design labels for details on creating the single-label report design document (.4rp).

Create the Label report Java application

To create a Java application that creates labels, you use a LabelMapper object. The LabelMapper class is for configuring label output. It allows a logical to physical page mapping. The label report defines the layout of a single label, which is then placed multiple times onto a larger page. The labels are arranged in a grid with a specifiable amount of rows and columns.

The application requires a FourRpProcessor object (conversion of an XML data stream to a PXML document) and a PXMLLayouter object (conversion of a PXML data stream to a layouted PXML document).

The application then calls specific configurations APIs to set:
  • The number of labels per row and per column.
  • The paper width and height.
  • The paper margins.

Example code snippet

This code snippet is taken from the report demo file It prints the labels on a physical page, two labels per row and six labels per column.
PXMLConsumer layout = new PXMLLayouter(renderer);

if ("OrderLabels".equals(filename))
    LabelMapper labelMapper = new LabelMapper(layout);
    layout = labelMapper;

FourRpProcessor report = new FourRpProcessor(fourRpfilepath, layout);

//Run the report 

// some code omitted - view full source in demo

// open the generated file:
File result = new File(outputFilename);
Desktop desktop = Desktop.getDesktop();;

// stop code snippet
Note: For LabelMaker, you must use the FourRpProcessor; you cannot use the shortcut.
Figure: Output of labels on a physical page

This figure shows an example of output from a report configured to create Labels.