2019-02-26 22:20:20 +00:00
|
|
|
// Add image to table cell
|
2018-12-24 16:50:53 +00:00
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { Document, Media, Packer, Table } from "../build";
|
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
|
|
|
2019-03-18 23:50:21 +00:00
|
|
|
const table = new Table({
|
|
|
|
rows: 2,
|
|
|
|
columns: 2,
|
|
|
|
});
|
2019-02-26 22:20:20 +00:00
|
|
|
table.getCell(1, 1).addParagraph(image.Paragraph);
|
2018-12-24 16:50:53 +00:00
|
|
|
|
|
|
|
// doc.createParagraph("Hello World");
|
|
|
|
doc.addTable(table);
|
|
|
|
|
|
|
|
// doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
|
|
doc.Header.addTable(table);
|
|
|
|
// doc.Footer.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|