creapage.net

HOWTO - Sashipa development

 How to print mailing labels.

You wish to make a print report with mailing labels for a listForm.

In this page we explain an example of the DemoContact application. This report contains two list levels. We begin with a general skeleton:

  <printReport name='PRtblContactaddress_Mailing'>
    <pageFormat format='A4' orientation='portrait' />
    <pageImageableArea x='40' y='35' w='515' h='772' relativeLocation='no' />

    <caption>Mailing labels Addresses</caption>

    <pageContent>
      <mailingDistribution labelsInWidth='2' labelsInHeight='7'>
        <mailingLabelSize w='217' h='95' />
        <mailingLabelGap firstWidth='40' firstHeight='46' width='75' height='16' />

        ... dataRecordPrinter ...

      </mailingDistribution>
    </pageContent>

  </printReport>

At first we define how many labels are on a page width (here labelsInWidth='2') and on a page height (here labelsInHeight='7'). We know gaps to keep around the page (it depends of your printer). Then we can compute following attributes.

NB: here we prefer to compute locations in absolute mode (relativeLocation='no'). So the (0; 0) location is the top left corner of the page (and not of the drawing area).

An A4 format is 595 * 842. Here are arithmetic details:

          A4: page width = 595, page height = 842
          Label width : 1st gap = 40; w; 2nd gap = 40
          => middle gap = 40 + 40 = 80
          Label height : 1st gap = 11; h; 2nd gap = 0
          Page width : top gap page = 0 ; bottom gap page = 0
          Page height : left gap page = 35 ; right gap page = 35
          w: (595 - 40*2 - 40*2) / 2 = 435 / 2 = 217 (+1)
          h: (842 - 46 - 35 - 16*6) / 7 = 665 / 7 = 95 (+0)

Once these formalities are done, content of label can be defined. A dataRecordPrinter is used, for creating one label for each data row:

  <dataRecordPrinter>

    ... serieDrawFigure ...

    ... printerDataSource ...

  </dataRecordPrinter>

First we look at the serieDrawFigure. We want to print:

  <serieDrawFigure locations='relativeVertical' atomic='yes' checkMaxHeight='no'>
    <defaultFont name='arial' style='plain' size='10' />
    <defaultSubDrawFigureAttributes maxHeight='26' />

    <!-- ContactName, ContactFirstname -->
    <serieDrawFigure locations='relativeHorizontal' checkMaxWidth='no'>
      <defaultSubDrawFigureAttributes y='0' maxHeight='26' />
      <!-- ContactFirstname -->
      <textDrawFigure x='0' maxWidth='150'>
        <instanceColumn schemaColumn='tblContact_Contactfirstname' />
      </textDrawFigure>
      <!-- ContactName -->
      <textDrawFigure x='4' maxWidth='150'>
        <instanceColumn schemaColumn='tblContact_Contactname' />
      </textDrawFigure>
    </serieDrawFigure>

    <!-- street -->
    <textDrawFigure maxHeight='50'>
      <instanceColumn schemaColumn='tblContactaddress_AddressStreet' />
    </textDrawFigure>

    <!-- Postcode, city -->
    <serieDrawFigure locations='relativeHorizontal' checkMaxWidth='no'>
      <defaultSubDrawFigureAttributes y='0' maxHeight='26' />
      <!-- Postcode -->
      <textDrawFigure x='0' maxWidth='38'>
        <instanceColumn schemaColumn='tblContactaddress_Addresspostcode' />
      </textDrawFigure>
      <!-- city -->
      <textDrawFigure x='4' maxWidth='200'>
        <instanceColumn schemaColumn='tblContactaddress_Addresscity' />
      </textDrawFigure>
    </serieDrawFigure>
  </serieDrawFigure>

Several remarks:

Now we just have to look at the data source:

  <printerDataSource>
    <selectQuery db='dbDemoContact'>
      <selectStatement>
        <instancePk>
          <instanceTable schemaTable='tblContactaddress' />
        </instancePk>
        <instanceColumnList>
          <instanceColumn schemaColumn='tblContact_Contactfirstname' />
          <instanceColumn schemaColumn='tblContact_Contactname' />
          <instanceColumn schemaColumn='tblContactaddress_AddressStreet' />
          <instanceColumn schemaColumn='tblContactaddress_Addresspostcode' />
          <instanceColumn schemaColumn='tblContactaddress_Addresscity' />
        </instanceColumnList>
      </selectStatement>
      <fromStatement>
        <mainInstanceTable schemaTable='tblContactaddress' />
        <fkJoin join='inner'>
          <instanceFk schemaFk='fk_tblContactaddress_tblContact' />
        </fkJoin>
      </fromStatement>
    </selectQuery>
  </printerDataSource>

It's a static query (and not a dynamic selectQueryBuilder). It will be in the default mode: mode='merge'. Select and From statement are redefined. So the end query will take Where and OrderBy statement from the listForm query.

© Copyright 2003 Sashipa-Melba Team. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License as much as this note clearly appears.