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 number of labels per row and per column.
- The paper width and height.
- The paper margins.
Example code snippet
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
For LabelMaker, you must use the FourRpProcessor; you cannot use the shortcut.