Files
docx-js/docs/usage/headers-and-footers.md

52 lines
1.0 KiB
Markdown
Raw Normal View History

2018-08-04 03:28:27 +01:00
# Headers and Footers
## Example
Creating Headers and footers is simple. Access the `Header` and `Footer` by doing so like this:
2018-08-04 04:03:08 +01:00
```js
2018-08-04 03:28:27 +01:00
doc.Header;
doc.Footer;
```
You can call the same methods as you would with a `File`:
2018-08-04 04:03:08 +01:00
```js
2018-08-04 03:28:27 +01:00
doc.Header.createParagraph("Header text");
doc.Footer.createParagraph("Footer text");
```
Even add images:
2018-08-04 04:03:08 +01:00
```js
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
```
Refer to `demo8.js` for more information
## Multiple Headers and Footers
Also all the supported section properties are implemented according to: http://officeopenxml.com/WPsection.php
### Example
2018-08-04 04:03:08 +01:00
```js
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({
headers: {
default: header
},
footers: {
default: footer
},
2018-08-04 03:28:27 +01:00
pageNumberStart: 1,
pageNumberFormatType: docx.PageNumberFormat.DECIMAL,
});
```