This is a very simple utility that repeats a page from a source document across and down to create a new page saved to the target document. To improve performance and output file size, it encapsulates the source page in a form XObject to avoid creating multiple copies of the same content.

Form XObjects are described in section 4.9 in the PDF Reference, sixth edition from Adobe.

Mako Step & Repeat v1.0.0.X

   makostepandrepeat input.pdf|xps|pxl|pcl [output.pdf|xps|pxl|pcl] [parameter=setting] [parameter=setting] ...
   parameter=setting  one or more settings, described below.

Parameters:      source file from which to extract tile source, where xxx is pdf, xps, pxl (PCL/XL) or pcl (PCL5)
   output.yyy     target file to write the output to, where yyy is pdf, xps, pxl or pcl.
                    If no output file is declared, <input>_tiled.pdf is assumed.
   pw=<password>  PDF password, if required to open the file.
   x=<x repeat>   Number of times to repeat the 'tile' across the width of the output.
   y=<y repeat>   Number of times to repeat the 'tile' down the length of the output.
   m=<margin>     Margin to apply to the output, in points.
   f=true|false   Use a form instead of copying DOM objects repeatedly (PDF output only). Default is true

How it works

The content is extracted from the source document:

IDOMFixedPagePtr pageContent = page->getContent();

And a form XObject is created:

IDOMFormPtr form = createInstance<IDOMForm>(jawsMako);
const IDOMNodePtr formNode = edlobj2IDOMNode(form);
pageContent->getFirstChild()->cloneTreeAndAppend(jawsMako, formNode);

To make use of a form XObject, an instance is needed. The following snippet shows that being created, and a transform is applied to move it to the correct X,Y position before being added to the target page.

// Create a form instance from the IDOMForm
IDOMFormInstancePtr formInstance = createInstance<IDOMFormInstance>(jawsMako);

// Determine how to transform the contents of the page to the correct position
FMatrix transform;

// Append the form instance to the spread

There is equivalent code in this example that copies content without the use of a form, which as one would expect makes for slower performance and much larger output file size. Form XObjects are an efficient way to repeat common elements and are used by many PDF generators.

Useful sample code

  • Use of form XObjects (IDOMForm, IDOMFormInstance)
  • Simple imposition