2018-08-04 03:28:27 +01:00
|
|
|
# Headers and Footers
|
|
|
|
|
2019-08-03 13:42:24 +01:00
|
|
|
!> Headers and Footers requires an understanding of [Sections](usage/sections.md).
|
|
|
|
|
2018-08-04 03:28:27 +01:00
|
|
|
## Example
|
|
|
|
|
|
|
|
Creating Headers and footers is simple. Access the `Header` and `Footer` by doing so like this:
|
|
|
|
|
2019-08-06 17:51:13 +01:00
|
|
|
```ts
|
2018-08-04 03:28:27 +01:00
|
|
|
doc.Header;
|
|
|
|
doc.Footer;
|
|
|
|
```
|
|
|
|
|
|
|
|
You can call the same methods as you would with a `File`:
|
|
|
|
|
2019-08-06 17:51:13 +01:00
|
|
|
```ts
|
2018-08-04 03:28:27 +01:00
|
|
|
doc.Header.createParagraph("Header text");
|
|
|
|
doc.Footer.createParagraph("Footer text");
|
|
|
|
```
|
|
|
|
|
|
|
|
Even add images:
|
|
|
|
|
2019-08-06 17:51:13 +01:00
|
|
|
```ts
|
2018-08-12 23:07:31 +01:00
|
|
|
doc.Header.createImage([BUFFER_OF_YOUR_IMAGE]);
|
|
|
|
doc.Footer.createImage([BUFFER_OF_YOUR_IMAGE]);
|
2018-08-04 03:28:27 +01:00
|
|
|
```
|
|
|
|
|
2019-08-20 22:23:14 +01:00
|
|
|
Refer to [`8-header-footer`](https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts) for more information.
|
2018-08-04 03:28:27 +01:00
|
|
|
|
|
|
|
## Multiple Headers and Footers
|
|
|
|
|
|
|
|
Also all the supported section properties are implemented according to: http://officeopenxml.com/WPsection.php
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
2019-08-06 17:51:13 +01:00
|
|
|
```ts
|
2018-08-04 03:28:27 +01:00
|
|
|
const header = this.document.createHeader();
|
|
|
|
const footer = this.document.createFooter();
|
|
|
|
|
|
|
|
// Add new section with another header and footer
|
|
|
|
doc.addSection({
|
2018-11-09 10:37:36 -02:00
|
|
|
headers: {
|
2019-04-25 09:49:44 -04:00
|
|
|
default: header
|
2018-11-09 10:37:36 -02:00
|
|
|
},
|
|
|
|
footers: {
|
2019-04-25 09:49:44 -04:00
|
|
|
default: footer
|
2018-11-09 10:37:36 -02:00
|
|
|
},
|
2018-08-04 03:28:27 +01:00
|
|
|
pageNumberStart: 1,
|
|
|
|
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
|