> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
