27 lines
669 B
TypeScript
27 lines
669 B
TypeScript
// Add text to header and footer
|
|
|
|
import * as fs from "fs";
|
|
import { Document, Footer, Header, Packer, Paragraph } from "docx";
|
|
|
|
const doc = new Document({
|
|
sections: [
|
|
{
|
|
headers: {
|
|
default: new Header({
|
|
children: [new Paragraph("Header text")],
|
|
}),
|
|
},
|
|
footers: {
|
|
default: new Footer({
|
|
children: [new Paragraph("Footer text")],
|
|
}),
|
|
},
|
|
children: [new Paragraph("Hello World")],
|
|
},
|
|
],
|
|
});
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
});
|