Skip to content

Adding a Coverpage

Let's add a simple coverpage to our document. To do so, we'll need to position content around the coverpage and style individual frames and their content. We'll then use Press' <data> tag for the title and author on the coverpage. We'll also introduce page definitions as a way to separate the details of each page from their appearance in the document.

Page Definitions

Before we start adding the coverpage, we're going to rewrite our original layout to use page definitions. Just like Flows can be moved into a separate section called <flows>, the layout of a page can be placed in <pages> and referred to from <document>.

Here's a reminder of our previous layout - with a return to the A4 page format:

xml
<document width="21cm" height="29.7cm" page-margin="2cm">
  <repeat flow="body">
    <page>
      <frame width="100%" text-align="right" margin-bottom="0.5cm"
             font-color="grey">
        Mr P. Mill
      </frame>
      <flow name="body" />
    </page>

    <page>
      <frame margin-bottom="0.5cm" font-color="grey">
        A History of Artificial Intelligence
      </frame>
      <flow name="body" />
    </page>
  </repeat>
</document>

Let's use page definitions to make our document definition even simpler:

xml
<document width="14.8cm" height="21cm" page-margin="1cm">
  <repeat flow="body">
    <left-page />
    <right-page />
  </repeat>
</document>

<pages>
  <left-page>
    <frame width="100%" text-align="right" margin-bottom="0.5cm"
           font-color="grey">
      Mr P. Mill
    </frame>
    <flow name="body" />
  </left-page>
  
  <right-page>
    <frame margin-bottom="0.5cm" font-color="grey">
      A History of Artificial Intelligence
    </frame>
    <flow name="body" />
  </right-page>
</pages>

Now we want to add a coverpage:

xml
<document width="21cm" height="29.7cm" page-margin="2cm">
  <coverpage />
  <repeat flow="body">
    <left-page />
    <right-page />
  </repeat>
</document>

And here's the definition of our coverpage:

xml
<coverpage>
  <frame left="2cm" width="10cm">
    <h1 font-color="grey" font-size="fit">A History of Artificial
      Intelligence</h1>
    <img
        src="https://examples.papermill.io/images/alan-turing.jpg"
        left="2cm" top="6cm" height="10cm" />
  </frame>
  <frame left="2cm" top="17cm">
    <h2 font-color="grey">Mr P. Mill</h2>
  </frame>
</coverpage>

There are two ways to position frames in Press:

The first is using <frame direction="col"> or <frame direction="row"> or to position content relatively, either vertically or horizontally.

The second is using absolute positioning. By specifying the offset of a frame within its parent - using the left, right, top, or bottom properties, you can position a frame such that it is unaffected by its siblings.

In practice, you'd probably use relative approach for most elements on a coverpage, but we're using absolute positioning here as an example.

Styling

In our coverpage, we've used inlining style for the first time. Inline styling is where attributes are set individually within a tag, such as <h1 font-color="grey">. This is the simplest way to style elements, but it gets very complicated.

Instead, we can use the top-level <styles> tag:

xml
<press>
  <document>...</document>
  <pages>...</pages>
  <styles>
    <h1>
      <font-color>grey</font-color>
    </h1>
  </styles>
</press>

This is very similar to using CSS in web development, except it's a lot simpler.

Introducing Data

The <data> tag is another tag that be used to parameterise templates, dynamically generate content, and reduce repetition.

Let's use the <data> tag to replace the title and author on our coverpage:

xml
<coverpage>
  <frame left="2cm" width="10cm">
    <h1 font-size="fit">{{ data.title }}</h1>
    <img
        src="https://examples.papermill.io/images/alan-turing.jpg"
        left="2cm" top="6cm" height="10cm" />
  </frame>
  <frame left="2cm" top="17cm">
    <h2 font-color="grey">{{ data.author }}</h2>
  </frame>
</coverpage>

<data>
  <title>A History of Artificial Intelligence</title>
  <author>Mr P. Mill</author>
</data>

We can also use the same data in our headers - we'll do that in the final document below.

Putting it all together

Let's combine everything we've done to give a final document on the history of artificial intelligence.

xml
<press>
  <document width="14.8cm" height="21cm" page-margin="1cm">
    <coverpage />
    <repeat flow="body">
      <left-page />
      <right-page />
    </repeat>
  </document>

  <pages>
    <coverpage>
      <frame left="2cm" width="10cm">
        <h1 font-size="fit">{{ data.title }}</h1>
        <img
          src="https://examples.papermill.io/images/alan-turing.jpg"
          left="2cm" top="6cm" height="10cm" />
      </frame>
      <frame left="2cm" top="17cm">
        <h2 font-color="grey">{{ data.author }}</h2>
      </frame>
    </coverpage>

    <left-page>
      <frame width="100%" text-align="right" margin-bottom="0.5cm"
        font-color="grey">
        {{ data.author }}
      </frame>
      <flow name="body" />
    </left-page>

    <right-page>
      <frame margin-bottom="0.5cm" font-color="grey">
        {{ data.title }}
      </frame>
      <flow name="body" />
    </right-page>
  </pages>

  <flows>
    <body>
      <h1>The Evolution of Artificial Intelligence</h1>
      <h2>Key Milestones</h2>
      <ol>
        <li>Turing Test proposed (1950)</li>
        <li>Dartmouth Conference (1956)</li>
        <li>Expert systems boom (1980s)</li>
        <li>Deep learning revolution (2012)</li>
      </ol>
      <h2>AI Domains</h2>
      <ul>
        <li>Machine Learning</li>
        <li>Natural Language Processing</li>
        <li>Computer Vision</li>
        <li>Robotics</li>
      </ul>
      <frame width="24pt" />
      <frame>
        <img
          src="https://examples.papermill.io/images/ai-timeline.png" />
      </frame>
      <h2>Impact Timeline</h2>
      <table>
        <tr>
          <th>Decade</th>
          <th>Breakthrough</th>
        </tr>
        <tr>
          <td>1950s</td>
          <td>Theoretical foundations</td>
        </tr>
        <tr>
          <td>1980s</td>
          <td>Commercial applications</td>
        </tr>
        <tr>
          <td>2010s</td>
          <td>Human-level performance</td>
        </tr>
        <tr>
          <td>2020s</td>
          <td>Generative AI explosion</td>
        </tr>
      </table>
      <h2>Looking Forward</h2>
      <p>As we stand at the threshold of artificial general intelligence, the
        next decade promises even more dramatic changes. The foundations laid by
        pioneers like Turing continue to shape our digital future.</p>
    </body>
  </flows>

  <styles>
    <h1>
      <font-color>grey</font-color>
    </h1>
  </styles>

  <data>
    <title>A History of Artificial Intelligence</title>
    <author>Mr P. Mill</author>
  </data>
</press>

That's it for this example. The rest of the tutorial covers some advanced topics and how to use the API in practice.