deno.land / x / docx@8.5.0 / demo / 9-images-in-header-and-footer.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051// Add images to header and footer
import * as fs from "fs";import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "docx";
const doc = new Document({ sections: [ { headers: { default: new Header({ children: [ new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 100, height: 100, }, }), ], }), ], }), }, footers: { default: new Footer({ children: [ new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 100, height: 100, }, }), ], }), ], }), }, children: [new Paragraph("Hello World")], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
Version Info