Search manual:

- Main page
- Introduction
- Hello, world!
- Basics
  - How to write the layout
  - Structure of the data file and the layout rules
  - Outputting objects
  - Grid
  - Areas on the page (PositioningArea)
  - File organization
  - Hyphenation / language settings
  - Using fonts
  - Text formats
  - Text formatting
  - Colors
- Programming
- Image inclusion
- Tables
- Advanced topics
  - Bookmarks
  - Creation of XML structures
  - Print output / crop marks
  - Using CSS with the speedata Publisher
  - Groups (virtual objects)
  - Virtual pages
  - Rotation of contents
  - Sorting data
  - Wrap around images
  - Page types
  - Starting the Publisher via the Hotfolder
  - Lua-Filter / pre-processing
  - Schema validation
  - Quality assurance and PDF comparison
  - Troubleshooting / Debugging
  - Server mode (REST API)
  - Control of the layout when calling the Publisher
  - Create and use images with MetaPost
- Cookbook
  - Thumb index
  - Embed multipage PDF files
  - Layout optimization using groups
  - Imitate bulleted lists
  - Automatically generated directories
  - Create table of contents in one go
  - Page numbers: Page x of y
- Installation instructions
- File name in the Publisher
- speedata Publisher defaults
- Running the speedata publisher on the command line
- How to configure the speedata publisher
- Lenghts and units
- XPath- and Layoutfunctions
- Internal variables
- Associate XML editor with schema
  - Visual Studio Code
  - OxygenXML
  - Atom
- Changelog
- Glossary
- Compatibility with other software
- Command reference
  - A
  - Action
  - AddSearchpath
  - AtPageCreation
  - AtPageShipout
  - AttachFile
  - Attribute
  - B
  - Barcode
  - Bold
  - BoldItalic
  - Bookmark
  - Box
  - Br
  - Case
  - Circle
  - Color
  - Column
  - Columns
  - Compatibility
  - Contents
  - Copy-of
  - DefineColor
  - DefineColorprofile
  - DefineFontalias
  - DefineFontfamily
  - DefineGraphic
  - DefineMatter
  - DefineTextformat
  - Element
  - Fallback
  - Fontface
  - ForAll
  - Frame
  - Grid
  - Group
  - Groupcontents
  - HSpace
  - Hyphenation
  - I
  - Image
  - Include
  - Initial
  - InsertPages
  - Italic
  - Layout
  - Li
  - LoadDataset
  - LoadFontfile
  - Loop
  - Makeindex
  - Margin
  - Mark
  - Message
  - NewPage
  - NextFrame
  - NextRow
  - NoBreak
  - Ol
  - Options
  - Otherwise
  - Output
  - Overlay
  - Pageformat
  - Pagetype
  - Paragraph
  - PDFOptions
  - PlaceObject
  - Position
  - PositioningArea
  - PositioningFrame
  - ProcessNode
  - Record
  - Regular
  - Rule
  - SaveDataset
  - SavePages
  - SetGrid
  - SetVariable
  - SortSequence
  - Stylesheet
  - Span
  - Sub
  - Sup
  - Switch
  - Table
  - TableNewPage
  - Tablefoot
  - Tablehead
  - Tablerule
  - Td
  - Text
  - Textblock
  - Tr
  - Trace
  - Transformation
  - U
  - Ul
  - Until
  - URL
  - Value
  - VSpace
  - While

Version 4.4.1
Search manual

- Main page
- Introduction
- Hello, world!
- Basics
  - How to write the layout
  - Structure of the data file and the layout rules
  - Outputting objects
  - Grid
  - Areas on the page (PositioningArea)
  - File organization
  - Hyphenation / language settings
  - Using fonts
  - Text formats
  - Text formatting
  - Colors
- Programming
- Image inclusion
- Tables
- Advanced topics
  - Bookmarks
  - Creation of XML structures
  - Print output / crop marks
  - Using CSS with the speedata Publisher
  - Groups (virtual objects)
  - Virtual pages
  - Rotation of contents
  - Sorting data
  - Wrap around images
  - Page types
  - Starting the Publisher via the Hotfolder
  - Lua-Filter / pre-processing
  - Schema validation
  - Quality assurance and PDF comparison
  - Troubleshooting / Debugging
  - Server mode (REST API)
  - Control of the layout when calling the Publisher
  - Create and use images with MetaPost
- Cookbook
  - Thumb index
  - Embed multipage PDF files
  - Layout optimization using groups
  - Imitate bulleted lists
  - Automatically generated directories
  - Create table of contents in one go
  - Page numbers: Page x of y
- Installation instructions
- File name in the Publisher
- speedata Publisher defaults
- Running the speedata publisher on the command line
- How to configure the speedata publisher
- Lenghts and units
- XPath- and Layoutfunctions
- Internal variables
- Associate XML editor with schema
  - Visual Studio Code
  - OxygenXML
  - Atom
- Changelog
- Glossary
- Compatibility with other software
- Command reference
  - A
  - Action
  - AddSearchpath
  - AtPageCreation
  - AtPageShipout
  - AttachFile
  - Attribute
  - B
  - Barcode
  - Bold
  - BoldItalic
  - Bookmark
  - Box
  - Br
  - Case
  - Circle
  - Color
  - Column
  - Columns
  - Compatibility
  - Contents
  - Copy-of
  - DefineColor
  - DefineColorprofile
  - DefineFontalias
  - DefineFontfamily
  - DefineGraphic
  - DefineMatter
  - DefineTextformat
  - Element
  - Fallback
  - Fontface
  - ForAll
  - Frame
  - Grid
  - Group
  - Groupcontents
  - HSpace
  - Hyphenation
  - I
  - Image
  - Include
  - Initial
  - InsertPages
  - Italic
  - Layout
  - Li
  - LoadDataset
  - LoadFontfile
  - Loop
  - Makeindex
  - Margin
  - Mark
  - Message
  - NewPage
  - NextFrame
  - NextRow
  - NoBreak
  - Ol
  - Options
  - Otherwise
  - Output
  - Overlay
  - Pageformat
  - Pagetype
  - Paragraph
  - PDFOptions
  - PlaceObject
  - Position
  - PositioningArea
  - PositioningFrame
  - ProcessNode
  - Record
  - Regular
  - Rule
  - SaveDataset
  - SavePages
  - SetGrid
  - SetVariable
  - SortSequence
  - Stylesheet
  - Span
  - Sub
  - Sup
  - Switch
  - Table
  - TableNewPage
  - Tablefoot
  - Tablehead
  - Tablerule
  - Td
  - Text
  - Textblock
  - Tr
  - Trace
  - Transformation
  - U
  - Ul
  - Until
  - URL
  - Value
  - VSpace
  - While

- Dieses Handbuch auf Deutsch

# Page types

Page types (or master pages, page templates) are used to define margins for pages, create page frames and perform actions when a page is created or written to the PDF file. Classically, there is a page template for left pages and for right pages. In the simplest case, a template looks like this:

    <Pagetype name="page" test="sd:even(sd:current-page())">
        <Margin left="1cm" right="1cm" top="1cm" bottom="1cm"/>
    </Pagetype>

The condition in the attribute 'test' can be arbitrarily complex. This attribute must always be specified. A page is selected as soon as a test of a page type yields true. Examples:

- `true()`: This page is always selected, since `true()` always results in true.
- `sd:current-page() > 1`: Here the page template is selected for all pages following the first page.
- `sd:even(sd:current-page())`: If the page number is even, this page type is used. This is usually when the page is a left page.
- It can also be more complex: `sd:even(sd:current-page()) and $part = 'main'`. As long as the condition can be evaluated to true or false, this is a valid expression.

What happens if there are multiple conditions that are true at the same time? Page types are evaluated from “bottom to top”. This means that special page templates must be defined later than the general ones. The default template is defined first and has as condition `true()`. So it is evaluated last according to this logic and is always used if no other page type in the test returns true (fallback).

    <Pagetype name="left pages" test="sd:even(sd:current-page())">
      ...
    </Pagetype>
    <Pagetype name="right pages" test="sd:odd(sd:current-page())">
      ...
    </Pagetype>
    <Pagetype name="first page" test="sd:current-page() = 1">
      ...
    </Pagetype>

Here, the page type for the first page after the page type for right pages must be defined, otherwise it would not be considered (sd:odd(1) returns true).

## Text frame

Text frames can be created in the page type definition. These are described in detail in the section "Areas on the page".

## AtPageCreation, AtPageShipout

The two commands `<AtPageCreation>` and `<AtPageShipout>` are responsible for executing code when a page is created and when a page is written to the PDF file. They can be used for many purposes. The most common is to create the page header in `<AtPageCreation>` and the page footer in `<AtPageShipout>`.

The following is an example of a page footer.

    <Layout xmlns="urn:speedata.de:2009/publisher/en"
      xmlns:sd="urn:speedata:2009/publisher/functions/en">

      <Pagetype name="page" test="true()">
        <Margin left="1cm" right="1cm" top="1cm" bottom="1cm"/>

        <AtPageShipout>
          <PlaceObject column="1" row="{sd:number-of-rows() - 1}">
            <Table stretch="max">
              <Tablerule/>
              <Tr>
                <Td align="left">
                  <Paragraph>
                    <Value select="sd:current-page()"/>
                  </Paragraph>
                </Td>
                <Td align="right">
                  <Paragraph>
                    <Value>Name</Value>
                  </Paragraph>
                </Td>
              </Tr>
            </Table>
          </PlaceObject>
        </AtPageShipout>
      </Pagetype>

      <Record element="data">
        <PlaceObject>
          <Textblock>
            <Paragraph>
              <Value>Content</Value>
            </Paragraph>
          </Textblock>
        </PlaceObject>
      </Record>
    </Layout>

Page with footer

## NewPage

With the command `<NewPage>` you can specify which page type should be selected for the next page, even if the condition (`test`) for `<Pagetype>' does not return true.

The following example defines two page types, a template “Standard”, which is always used and a template “Special”, which is explicitly selected with `<NewPage>`.

    <Layout xmlns="urn:speedata.de:2009/publisher/en"
      xmlns:sd="urn:speedata:2009/publisher/functions/en">

      <Pageformat width="210mm" height="50mm"/>

      <Pagetype name="Special" test="false()">
        <Margin left="1cm" right="1cm" top="1cm" bottom="1cm"/>
      </Pagetype>

      <Pagetype name="Standard" test="true()">
        <Margin left="1cm" right="1cm" top="1cm" bottom="1cm"/>
      </Pagetype>

      <Record element="data">
        <PlaceObject>
          <Textblock>
            <Paragraph>
              <Value>Page 1</Value>
            </Paragraph>
          </Textblock>
        </PlaceObject>
        <NewPage pagetype="Special" openon="right" />
        <PlaceObject>
          <Textblock>
            <Paragraph>
              <Value>Page 3</Value>
            </Paragraph>
          </Textblock>
        </PlaceObject>
      </Record>
    </Layout>

In the log file (`publisher.protocol`) you can see which page types are selected:

    ...
    Page of type "Standard" created (1)
    Number of rows: 3, number of columns = 19
    Create font metrics for "texgyreheros-regular.otf" at 10pt (id: 1) mode=harfbuzz
    PlaceObject: Textblock at (1,1) wd/ht: 19/1 in "_page" (p. 1)
    > Shipout page 1
    Page of type "Standard" created (2)
    Number of rows: 3, number of columns = 19
    > Shipout page 2
    Page of type "Special" created (3) - pagetype requested
    ...

- Wrap around images
- Starting the Publisher via the Hotfolder