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).
|
|
|
|
|
2019-08-21 00:05:46 +01:00
|
|
|
Every Section has a sections which you can define its Headers and Footers:
|
2018-08-04 03:28:27 +01:00
|
|
|
|
2019-08-06 17:51:13 +01:00
|
|
|
```ts
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [{
|
|
|
|
headers: {
|
|
|
|
default: new Header({ // The standard default header
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
first: new Header({ // The first header
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
even: new Header({ // The header on every other page
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
footers: {
|
|
|
|
default: new Footer({ // The standard default footer
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
first: new Footer({ // The first footer
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
even: new Footer({ // The footer on every other page
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
children: [],
|
|
|
|
}];
|
2019-08-21 00:05:46 +01:00
|
|
|
});
|
2018-08-04 03:28:27 +01:00
|
|
|
```
|
|
|
|
|
2019-08-21 00:05:46 +01:00
|
|
|
## Example
|
2018-08-04 03:28:27 +01:00
|
|
|
|
2019-08-21 00:05:46 +01:00
|
|
|
Example showing basic header and footer
|
2018-08-04 03:28:27 +01:00
|
|
|
|
2019-08-21 00:51:26 +01:00
|
|
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/8-header-footer.ts ':include')
|
2018-08-04 03:28:27 +01:00
|
|
|
|
2019-08-21 00:05:46 +01:00
|
|
|
_Source: https://github.com/dolanmiu/docx/blob/master/demo/8-header-footer.ts_
|
2018-08-04 03:28:27 +01:00
|
|
|
|
|
|
|
## Multiple Headers and Footers
|
|
|
|
|
2019-08-21 00:05:46 +01:00
|
|
|
More headers and footers can be accomplished by creating more `Section`. New headers and footers can be set per `Section`
|