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.
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).
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).
PXMLConsumer layout = new PXMLLayouter(renderer); if ("OrderLabels".equals(filename)) { LabelMapper labelMapper = new LabelMapper(layout); labelMapper.setPaperTopMargin("5mm"); labelMapper.setPaperBottomMargin("5mm"); labelMapper.setPaperLeftMargin("4mm"); labelMapper.setPaperRightMargin("4mm"); labelMapper.setPaperWidth("a4width"); labelMapper.setPaperHeight("a4length"); labelMapper.setLabelsPerRow(2); labelMapper.setLabelsPerColumn(6); layout = labelMapper; } FourRpProcessor report = new FourRpProcessor(fourRpfilepath, layout); //Run the report report.setDebugLevel(9); // some code omitted - view full source in demo report.runFromJAXBObject(data); // open the generated file: File result = new File(outputFilename); Desktop desktop = Desktop.getDesktop(); desktop.open(result); // stop code snippet
Figure 1. Output of labels on a physical page