diff --git a/src/file/document/document.ts b/src/file/document/document.ts index d8db84adf3..1e795c06d6 100644 --- a/src/file/document/document.ts +++ b/src/file/document/document.ts @@ -1,7 +1,7 @@ // http://officeopenxml.com/WPdocument.php import { IMediaData } from "file/media"; import { XmlComponent } from "file/xml-components"; -import { Paragraph, PictureRun } from "../paragraph"; +import { Image, Paragraph } from "../paragraph"; import { Table } from "../table"; import { Body } from "./body"; import { SectionPropertiesOptions } from "./body/section-properties/section-properties"; @@ -57,18 +57,11 @@ export class Document extends XmlComponent { return table; } - public addDrawing(pictureParagraph: Paragraph): void { - this.body.push(pictureParagraph); - } + public createDrawing(imageData: IMediaData): Image { + const image = new Image(imageData); + this.addParagraph(image); - public createDrawing(imageData: IMediaData): PictureRun { - const paragraph = new Paragraph(); - const run = new PictureRun(imageData); - - paragraph.addRun(run); - this.addDrawing(paragraph); - - return run; + return image; } get Body(): Body { diff --git a/src/file/file.ts b/src/file/file.ts index 9c9e1a073b..71a2a2fbad 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -10,7 +10,7 @@ import { FootNotes } from "./footnotes"; import { HeaderWrapper } from "./header-wrapper"; import { Media } from "./media"; import { Numbering } from "./numbering"; -import { Bookmark, Hyperlink, Paragraph, PictureRun } from "./paragraph"; +import { Bookmark, Hyperlink, Image, Paragraph } from "./paragraph"; import { Relationships } from "./relationships"; import { Styles } from "./styles"; import { ExternalStylesFactory } from "./styles/external-styles-factory"; @@ -125,7 +125,7 @@ export class File { return this.document.createTable(rows, cols); } - public createImage(filePath: string): PictureRun { + public createImage(filePath: string): Image { const mediaData = Media.addImage(this, filePath); return this.document.createDrawing(mediaData); } @@ -135,7 +135,7 @@ export class File { return this; } - public createImageFromBuffer(buffer: Buffer, width?: number, height?: number): PictureRun { + public createImageFromBuffer(buffer: Buffer, width?: number, height?: number): Image { const mediaData = Media.addImageFromBuffer(this, buffer, width, height); return this.document.createDrawing(mediaData); }