Create labels: the report application (C#)

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 C# application

To create an 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 OrderReportCSharp.cs. 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);
    labelMapper.paperTopMargin = "5mm";
    labelMapper.paperBottomMargin = "5mm";
    labelMapper.paperLeftMargin = "4mm";
    labelMapper.paperRightMargin = "4mm";
    labelMapper.paperWidth ="a4width";
    labelMapper.paperHeight = "a4length";
    labelMapper.labelsPerRow =2;
    labelMapper.labelsPerColumn =6;
    layout = labelMapper;
}

FourRpProcessor report = new FourRpProcessor(fourRpfilepath, layout);

//Run the report 
report.debugLevel = 9;

// some code omitted - view full source in demo

report.runFromSerializable(data);

// open the file
System.Diagnostics.Process.Start(outputFilename);
Figure: Output of labels on a physical page

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