2018-08-21 02:46:21 +01:00
|
|
|
// Scaling images
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { Document, Packer, Paragraph } from "../build";
|
2018-03-24 19:06:10 +00:00
|
|
|
|
2018-08-21 02:46:21 +01:00
|
|
|
const doc = new Document();
|
2018-03-24 19:06:10 +00:00
|
|
|
|
2018-08-21 02:46:21 +01:00
|
|
|
const paragraph = new Paragraph("Hello World");
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.add(paragraph);
|
2018-03-24 19:06:10 +00:00
|
|
|
|
2018-08-12 23:07:31 +01:00
|
|
|
const image = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
|
|
const image2 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
|
|
const image3 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
|
|
|
const image4 = doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
|
2018-03-24 19:06:10 +00:00
|
|
|
|
|
|
|
image.scale(0.5);
|
2018-08-21 02:46:21 +01:00
|
|
|
image2.scale(1);
|
2018-03-24 19:11:25 +00:00
|
|
|
image3.scale(2.5);
|
2018-03-24 19:06:10 +00:00
|
|
|
image4.scale(4);
|
|
|
|
|
2018-08-21 02:46:21 +01:00
|
|
|
const packer = new Packer();
|
2018-03-24 19:06:10 +00:00
|
|
|
|
2018-08-21 02:46:21 +01:00
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|