deno.land / x / docx@8.5.0 / demo / 12-scaling-images.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// Scaling images
import * as fs from "fs";import { Document, ImageRun, Packer, Paragraph } from "docx";
const doc = new Document({ sections: [ { children: [ new Paragraph("Hello World"), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 50, height: 50, }, }), ], }), 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/pizza.gif"), transformation: { width: 250, height: 250, }, }), ], }), new Paragraph({ children: [ new ImageRun({ data: fs.readFileSync("./demo/images/pizza.gif"), transformation: { width: 400, height: 400, }, }), ], }), ], }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
Version Info