From 2d12f6e54ccf4e3dfd4fd1206aa2d93b43cb56d1 Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 2 Aug 2018 21:07:37 +0100 Subject: [PATCH] Add new Image class --- demo/demo24.js | 15 +++++++++++++++ src/file/paragraph/image.ts | 18 ++++++++++++++++++ src/file/paragraph/index.ts | 1 + 3 files changed, 34 insertions(+) create mode 100644 demo/demo24.js create mode 100644 src/file/paragraph/image.ts diff --git a/demo/demo24.js b/demo/demo24.js new file mode 100644 index 0000000000..8313f117cb --- /dev/null +++ b/demo/demo24.js @@ -0,0 +1,15 @@ +// Add image to table cell +const docx = require('../build'); + +var doc = new docx.Document(); + +const table = doc.createTable(4, 4); +table.getCell(2, 2).addContent(new docx.Paragraph('Hello')); + +const imageData = docx.Media.addImage(doc, "./demo/images/image1.jpeg"); +table.getCell(1, 1).addContent(new docx.Image(imageData)); + +var exporter = new docx.LocalPacker(doc); +exporter.pack('My Document'); + +console.log('Document created successfully at project root!'); diff --git a/src/file/paragraph/image.ts b/src/file/paragraph/image.ts new file mode 100644 index 0000000000..214378853c --- /dev/null +++ b/src/file/paragraph/image.ts @@ -0,0 +1,18 @@ +import { IDrawingOptions } from "../drawing"; +import { IMediaData } from "../media"; +import { Paragraph } from "./paragraph"; +import { PictureRun } from "./run"; + +export class Image extends Paragraph { + private readonly pictureRun: PictureRun; + + constructor(imageData: IMediaData, drawingOptions?: IDrawingOptions) { + super(); + this.pictureRun = new PictureRun(imageData, drawingOptions); + this.root.push(this.pictureRun); + } + + public scale(factorX: number, factorY?: number): void { + this.pictureRun.scale(factorX, factorY); + } +} diff --git a/src/file/paragraph/index.ts b/src/file/paragraph/index.ts index 68a1b0b800..222cb1bf4f 100644 --- a/src/file/paragraph/index.ts +++ b/src/file/paragraph/index.ts @@ -3,3 +3,4 @@ export * from "./paragraph"; export * from "./properties"; export * from "./run"; export * from "./links"; +export * from "./image";