added error checking and updated demo
This commit is contained in:
@ -12,7 +12,7 @@ doc.addParagraph(paragraph);
|
||||
|
||||
var media = new docx.Media();
|
||||
media.addMedia("happy-penguins", "./demo/penguins.jpg");
|
||||
// var pictureRun = new docx.PictureRun("");
|
||||
var pictureRun = new docx.PictureRun(media.getMedia("happy-penguins"));
|
||||
|
||||
var exporter = new docx.LocalPacker(doc, undefined, undefined, undefined, media);
|
||||
exporter.pack('My Document');
|
||||
|
@ -7,6 +7,10 @@ export class Drawing extends XmlComponent {
|
||||
constructor(imageData: IData) {
|
||||
super("w:drawing");
|
||||
|
||||
if (imageData === undefined) {
|
||||
throw new Error("imageData cannot be undefined");
|
||||
}
|
||||
|
||||
this.root.push(new Inline(imageData.referenceId));
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,14 @@ export class Media {
|
||||
this.map = new Map<string, IData>();
|
||||
}
|
||||
|
||||
public getMedia(key: string): IData | undefined {
|
||||
return this.map.get(key);
|
||||
public getMedia(key: string): IData {
|
||||
const data = this.map.get(key);
|
||||
|
||||
if (data === undefined) {
|
||||
throw new Error(`Cannot find image with the key ${key}`);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public addMedia(key: string, filePath: string): void {
|
||||
|
Reference in New Issue
Block a user