How-to create a custom print layout

GeoMoose uses jsPDF to perform client-side generation of PDF printouts. It has four built-in templates but they are relatively plain and may not be for everyone.

What is in a print layout

A print layout is comprised of a label, orientation, page size, unit specification, and a list of page elements. These are defined as a JavaScript object which can be passed to the PrintModal component.

The default configuration

In the desktop example application, the PrintModal uses its built-in layouts defined in examples/desktop/app.js:

 var print_preview = app.add(gm3.components.PrintModal, 'print-preview', {});

Adding a custom layout

To override the default layouts the layouts need to be configured for the PrintModal:


var custom_layouts = [
  {
    label: 'Landscape Letter',
    orientation: 'landscape',
    page: 'letter',
    units: 'in',
    elements: [
        {
            type: 'text',
            size: 18, fontStyle: 'bold',
            x: .5, y: .70, text: '{{title}}'
        },
        {
            type: 'map',
            x: .5, y: .75,
            width: 10, height: 7
        },
        {
            type: 'rect',
            x: .5, y: .75,
            width: 10, height: 7,
            strokeWidth: .01
        },
        {
            type: 'text',
            x: .5, y: 8, text: 'Printed on {{month}} / {{day}} / {{year}}'
        }
    ]
  }
];

 var print_preview = app.add(gm3.components.PrintModal, 'print-preview', {
   layouts: custom_layouts
 });

custom_layouts contains:

The following elements are available: