Files
docx-js/demo/demo37.ts

19 lines
634 B
TypeScript
Raw Normal View History

2018-12-24 16:50:53 +00:00
// Add images to header and footer
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2019-06-13 01:07:00 +01:00
import { Document, Media, Packer, Paragraph } from "../build";
2018-12-24 16:50:53 +00:00
const doc = new Document();
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
2019-06-25 23:17:56 +01:00
doc.add(new Paragraph("Hello World"));
2018-12-24 16:50:53 +00:00
doc.Header.addImage(image);
doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
doc.Header.createImage(fs.readFileSync("./demo/images/image1.jpeg"));
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});