# Adding Headers & Footers from Components in PDF Templates

Consider this use case:

PDF A is the main template with no header and outputs 1 page.\
PDF B and PDF C are included (called) within PDF A and each defines its own header/footer and can output multiple pages.

Example final page order:

* page 1 - PDF A (no header)
* page 2 - PDF B (Header B)
* page 3 - PDF B (Header B)
* page 4 - PDF C (Header C)
* page 5 - PDF C (Header C)
* page 6 - PDF C (Header C)

To accomplish this, specific CSS and formatting rules must be followed.

Main template (PDF A)

{% code title="PDF A" %}

```html
{{{{!PDF A}}}}
<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>
{{{{!PDF B}}}}

<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>
{{{{!PDF B}}}}

<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>
{{{{!PDF C}}}}

<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>
{{{{!PDF C}}}}

<div style="page-break-after: always"><span style="display: none;">&nbsp;</span></div>
{{{{!PDF C}}}}
```

{% endcode %}

Template B

{% code title="PDF B" %}

```html
<style type="text/css">#page-header-PDFB {
    display: block;
    position: running(header);
}
#page-footer-PDFB {
    display: block;
    position: running(footer);
}
</style>
<div id="page-header-PDFB">PDF B - Header</div>
PDF B - Body

<div id="page-footer-PDFB">PDF B - Footer</div>
```

{% endcode %}

Template C

{% code title="PDF C" %}

```html
<style type="text/css">#page-header-PDFC {
    display: block;
    position: running(header);
}
#page-footer-PDFC {
    display: block;
    position: running(footer);
}
</style>
<div id="page-header-PDFC">PDF C - Header</div>
PDF C - Body

<div id="page-footer-PDFC">PDF C - Footer</div>
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/advanced-template-logic/build-reusable-templates/component-template-how-to-article/adding-headers-footers-from-components-in-pdf-templates.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
