> For the complete documentation index, see [llms.txt](https://docs.dbnetsoft.com/dbnetsoft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dbnetsoft.com/dbnetsoft/scory/expressions/pdf-page-template.md).

# PDF page template

The frame of every PDF page - header, footer, logos, banners and the list's look - per event or per list, built visually or as HTML, with the event's own fonts.

The **page template** decides how a list's PDF looks around its rows: a header on top of every page (logos, the event's name, the list's title, a banner), a footer at the bottom (organiser, page number, sponsors) and the look of the list itself (column headers, row lines, group headers). It is set once per event and every list's PDF uses it; a list may change parts of it.

**Setup → Event → Lists / PDF → Page frame** decides the frame above and below each page's table - one of two:

| Page frame        | Above and below the table                                                                                            |
| ----------------- | -------------------------------------------------------------------------------------------------------------------- |
| **Simple**        | the title block (title, subtitle - modern also organiser and place) and a header and footer line of three cells each |
| **Page template** | your own header and footer, with logos and styles for the table - this page                                          |

Only one of them is used; the other is kept and comes back when you switch. Paper, margins, fonts, the text styles, rows and colours apply to both. An event that has a page template uses it until you switch to Simple.

The same header and footer also show above and below the list on the Lists page, on the public live results, on MyScory and on MyScory's screen board (the footer - a sponsor band - at the bottom of the display) - there without page numbers. A bracket's PDF gets them too.

## Templates

The **Templates** menu fills the template in:

| Template                       | Looks like                                                                                                                                                                                                                                                                           |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Standard                       | title and subtitle left, organiser and place right, a rule in the accent colour under them                                                                                                                                                                                           |
| Classic                        | the event in small type on top, the title, rules in the accent colour                                                                                                                                                                                                                |
| Ski World Cup sheet            | a banner, logos left and right of the centred event, place and title lines, a two-line footer and a sponsors band                                                                                                                                                                    |
| Ski race sheet (FIS, DSV, ÖSV) | a points race's official sheet: the association's logo left, the organiser's right, event, place and nation, the list's subtitle (codex, category) and title; the footer with the TD and nation, timing and data processing from the event fields; the sponsors on result lists only |

The ski sheets use images under fixed keys - upload them on Setup → Event → Assets; an image the event does not have is left out:

* Ski World Cup sheet: `banner`, `logo-left`, `logo-left-2`, `logo-right`, `sponsors`.
* Ski race sheet: `association` (the FIS, DSV or ÖSV logo), `organizer`, `sponsors`. Its footer reads the event fields the ski race template creates (`TD`, `TDNation`, `Nation`, `TimingBy`, `DataProcessingBy`); an empty one is left out.

Further down the same menu:

* **Save as template…** keeps the event's template on the server: every event offers it under Templates, as *Saved* (× removes it again). Only the template is kept - its images stay with the event.
* **Copy from event…** takes another event's whole PDF layout - page template, fonts, sizes, margins - with its images and fonts. Images with the same key are replaced, the others stay.
* **Export to file…** saves the template as an `.html` file on your computer; **Import from file…** loads one (asking before it replaces the template there). The file holds only the template: upload its images under the same keys on the Assets tab of the event you import it into, or use *Copy from event…* to take them along.

## The visual editor

The editor shows the header and the footer as they come out, line by line; **Source** shows the HTML instead (per browser).

* **Lines:** *Row of cells* (side by side - e.g. a logo left, the title in the middle, a date right), *Heading*, *Text*, *Image*, *Rule line*. A new line goes under the selected one.
* **Click** a cell or a line: its settings open in a box right under it, an arrow pointing at it - content, width, alignment, vertical alignment, background, font, size, colour, weight, italic, upper case, rounded corners, borders per side and spacing. *Close* or Esc closes it. The PDF preview beside the editor stays in view while you scroll.
* **Content** is text with fields: *Insert field* (list title, event name, date, location, organiser, page number, created at), *Insert image* (a picker with the event's images, *Upload…*, or a flag like `AUT`), *Title* / *Subtitle* / **B** / *I* / *Small* for the selected text.
* **Spacing:** margin outside and padding inside, a field for each side; the chain sets all four at once. A plain number is in points; `mm` and `%` work too. A row also has *Space between cells*.
* **Cells:** *Merge with next* (the contents one under the other, the widths added up), *Split* (a new cell after it, the width shared), *Split into rows* - two rows inside the cell, e.g. a tall logo beside two lines of text; *Row inside* adds more.
* **Move** lines and cells at their grip (⋮⋮) - cells also into another row. **Drag the edge** between two cells to change their widths.
* **Drop an image file** onto a cell: it is uploaded to the event's images and put into the cell.
* **Values** shows what the fields give for the list chosen in the PDF preview instead of the field names.
* **Duplicate**, the copy and paste icons (copy a style, paste it onto another cell or line - not the width), **Undo** / **Redo** (Ctrl+Z / Ctrl+Y).
* Whatever the editor does not know - comments, loops, tags of your own - stays exactly as written.

### Show only when

A line can be shown only sometimes: select it, **Show only when** - a condition. ▾ offers common ones:

| Condition                                                    | The line shows                    |
| ------------------------------------------------------------ | --------------------------------- |
| `list.name \| string.contains "Start"`                       | on lists whose name has "Start"   |
| `list.name \| string.contains "Result"`                      | on result lists                   |
| `event.fields.sponsor != null && event.fields.sponsor != ""` | when the event field is filled in |
| `list.rows > 0`                                              | on lists with rows                |
| `list.firstPage`                                             | on the first page only            |
| `!list.firstPage`                                            | on every page but the first       |
| `list.lastPage`                                              | on the last page only             |

In the HTML it is written as `{{ if condition }}` before the line and `{{ end }}` after it. A page condition joins one that is there already: `list.firstPage && list.name | string.contains "Start"`.

**First page, last page:** a big title on the first page and a one-line title on the others, or a signature line at the end of the last page only. The PDF then draws the header and footer page by page. Whether a page is the last one is known only at the end, so every page keeps room for the taller of the two footers it may get. On the Lists page, the live results and MyScory - one page - the list is first and last page at once.

## List styles

**List styles** (chips under the footer) give the list itself its look - over the design's (the Lists / PDF settings above): what a style does not set stays as it was.

| Chip                      | Styles                        |
| ------------------------- | ----------------------------- |
| Column headers            | the line of column headers    |
| Rows, Every other row     | the rows (zebra: every other) |
| Group headers, level 1, 2 | the group header lines        |

Each takes text (font, size, colour, weight, italic, upper case, alignment), background, padding above and below, and a line above / below. *Rows → Border bottom → None* removes the lines between the rows.

A border side offers three choices:

| Choice        | Writes               | The side                                                                                  |
| ------------- | -------------------- | ----------------------------------------------------------------------------------------- |
| –             | nothing              | stays as it is underneath - the design's line, or the event's template under a list's own |
| **Rule line** | e.g. `1pt solid ink` | gets a line in the width, style and colour beside it                                      |
| **None**      | `none`               | has no line, even where the design or the event's template draws one                      |

On a plain cell of the header or footer nothing lies underneath: there – and None look the same.

## A list's own page

**Lists → a list → PDF page:**

* **The event's** - as Setup → Event → Lists / PDF.
* **Without the title on top** - no title block or template header; the list starts at the top of the page. The footer and the list styles stay.
* **Own template over the event's** - the list holds only what differs: its styles win property by property, a header or footer of its own replaces the event's, the rest stays the event's. *Copy the event's template* starts from the event's. The list's **Columns → List styles** chips open it too.

The list editor's preview shows the list as **HTML** or as **PDF** - the PDF as the list is in the editor, saved or not; on a wide screen it stays in view while you scroll. Its **Columns** stand side by side with the first rows (**Visual**; **Source** is the table): click one to edit it - its settings open in a box right under it -, drag it at its grip to move it, drag the edge between two to set their widths.

**Grouping → New page:** each group of that level starts on a new page of the PDF (the HTML list too, when printed) - e.g. each competition or class on its own page.

## Fonts

Upload TrueType fonts (`.ttf`, up to 10 MB) on **Setup → Event → Assets**, a file per style - regular, bold, italic. The PDF's font lists then offer the family under *This event's fonts*, and `font-family: Name` in the template uses it. Fonts go with the event to and from the cloud.

## The template as HTML

The template is a small HTML with inline CSS. Before it is drawn it is a template like a list title: `{{ ... }}` is replaced by its value.

```html
<style>
  columns { border-top: 1pt solid #000; border-bottom: 1pt solid #000 }
  row { border-bottom: none }
  group { text-align: center; text-transform: uppercase }
</style>
<header>
  <row style="gap: 4pt; border-bottom: 0.5pt solid #000; margin-bottom: 6pt">
    <cell style="width: 22%; vertical-align: middle"><img src="logo-left" height="26"></cell>
    <cell style="text-align: center">
      <h2>{{ event.name | string.upcase }}</h2>
      <h1>{{ list.title }}</h1>
    </cell>
    <cell style="width: 22%; text-align: right"><img src="logo-right" height="24"><br>{{ event.date }}</cell>
  </row>
</header>
<footer>
  <row><cell>{{ event.location }}</cell><cell style="text-align: right">Page {{ page }} / {{ pages }}</cell></row>
  <img src="sponsors" style="width: 100%">
</footer>
```

| Element                                        | Draws                                                                               |
| ---------------------------------------------- | ----------------------------------------------------------------------------------- |
| `<header>`, `<footer>`                         | on top / at the bottom of every page (a line with a page condition on those pages)  |
| `<row>` with `<cell>` (`tr`, `td`)             | cells side by side; `width` in % or mm, the rest shared; a cell may hold rows       |
| `<div>`, `<p>`                                 | a block                                                                             |
| `<h1>`, `<h2>`, `<h3>`                         | in the title's size, the subtitle's in bold, the subtitle's                         |
| `<b>`, `<i>`, `<u>`, `<small>`, `<br>`, `<hr>` | bold, italic, underlined, smaller, a new line, a line across                        |
| `<img src="key">`                              | an event image (or `flag:AUT`) with `height="26"` (points) or `style="width: 100%"` |
| `<style>`                                      | the list styles: `columns`, `row`, `row:even`, `group`, `group1`, `group2`          |

**CSS:** `font-family`, `font-size`, `font-weight`, `font-style`, `color`, `background`, `text-align`, `vertical-align`, `text-transform`, `padding` and `margin` (each side too), `border`, `border-top` … (`0.5pt solid #000`, `dashed`, `none`), `border-radius`, `width`, `height`, `gap`. Colours: `#hex`, names, and the layout's `accent`, `line`, `zebra`, `ink`. Lengths in `pt` (default), `mm`, `cm`, `px`, `in`, `%`.

**Names** in the template: `list.title`, `list.subTitle`, `list.name`, `list.createdAt`, `list.rows`, `event.name`, `event.date`, `event.location`, `event.organizer`, `event.fields.<key>`, `page`, `pages`, `list.firstPage`, `list.lastPage` - and the functions `image` and `flag`. A script error shows in the PDF's header instead of the header.

{% hint style="info" %}
The Assistant (Other → Assistant) can write page templates too: "logo left, sponsor banner at the bottom, title centred". It asks before it saves.
{% endhint %}
