Add new Image class
This commit is contained in:
15
demo/demo24.js
Normal file
15
demo/demo24.js
Normal 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!');
|
18
src/file/paragraph/image.ts
Normal file
18
src/file/paragraph/image.ts
Normal 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);
|
||||
}
|
||||
}
|
@ -3,3 +3,4 @@ export * from "./paragraph";
|
||||
export * from "./properties";
|
||||
export * from "./run";
|
||||
export * from "./links";
|
||||
export * from "./image";
|
||||
|
Reference in New Issue
Block a user