Add new Image class

This commit is contained in:
Dolan
2018-08-02 21:07:37 +01:00
parent f7c02f4679
commit 2d12f6e54c
3 changed files with 34 additions and 0 deletions

15
demo/demo24.js Normal file
View File

@ -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!');

View File

@ -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);
}
}

View File

@ -3,3 +3,4 @@ export * from "./paragraph";
export * from "./properties";
export * from "./run";
export * from "./links";
export * from "./image";