Skip to main content
Module

x/docx/demo/37-images-to-header-and-footer.ts

Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
Go to Latest
File
// Add images to header and footer// Import from 'docx' rather than '../build' if you install from npmimport * as fs from "fs";import { Document, Header, ImageRun, Packer, Paragraph } from "../build";
const doc = new Document({ sections: [ { headers: { default: new Header({ children: [ new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/image1.jpeg"), transformation: { width: 100, height: 100, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 100, height: 100, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/image1.jpeg"), transformation: { width: 100, height: 100, }, }), ], }), ], }), }, children: [new Paragraph("Hello World")], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});