Fix missing media in Document Template
This commit is contained in:
@ -15,10 +15,22 @@ const item2 = new Paragraph("line with contextual spacing");
|
|||||||
const item3 = new Paragraph("line without contextual spacing");
|
const item3 = new Paragraph("line without contextual spacing");
|
||||||
const item4 = new Paragraph("line without contextual spacing");
|
const item4 = new Paragraph("line without contextual spacing");
|
||||||
|
|
||||||
item1.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
item1
|
||||||
item2.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
.setNumbering(concrete, 0)
|
||||||
item3.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
.spacing({ before: 200 })
|
||||||
item4.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
.contextualSpacing(true);
|
||||||
|
item2
|
||||||
|
.setNumbering(concrete, 0)
|
||||||
|
.spacing({ before: 200 })
|
||||||
|
.contextualSpacing(true);
|
||||||
|
item3
|
||||||
|
.setNumbering(concrete, 0)
|
||||||
|
.spacing({ before: 200 })
|
||||||
|
.contextualSpacing(false);
|
||||||
|
item4
|
||||||
|
.setNumbering(concrete, 0)
|
||||||
|
.spacing({ before: 200 })
|
||||||
|
.contextualSpacing(false);
|
||||||
|
|
||||||
doc.addParagraph(item1);
|
doc.addParagraph(item1);
|
||||||
doc.addParagraph(item2);
|
doc.addParagraph(item2);
|
||||||
@ -29,4 +41,4 @@ const packer = new Packer();
|
|||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
});
|
});
|
||||||
|
@ -53,8 +53,9 @@ export class Document extends XmlComponent {
|
|||||||
return para;
|
return para;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTable(table: Table): void {
|
public addTable(table: Table): Document {
|
||||||
this.body.push(table);
|
this.body.push(table);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createTable(rows: number, cols: number): Table {
|
public createTable(rows: number, cols: number): Table {
|
||||||
|
@ -56,12 +56,13 @@ export class File {
|
|||||||
this.coreProperties = new CoreProperties(options);
|
this.coreProperties = new CoreProperties(options);
|
||||||
this.numbering = new Numbering();
|
this.numbering = new Numbering();
|
||||||
this.docRelationships = new Relationships();
|
this.docRelationships = new Relationships();
|
||||||
this.media = new Media();
|
|
||||||
this.fileRelationships = new Relationships();
|
this.fileRelationships = new Relationships();
|
||||||
this.appProperties = new AppProperties();
|
this.appProperties = new AppProperties();
|
||||||
this.footNotes = new FootNotes();
|
this.footNotes = new FootNotes();
|
||||||
this.contentTypes = new ContentTypes();
|
this.contentTypes = new ContentTypes();
|
||||||
|
|
||||||
|
this.media = fileProperties.template && fileProperties.template.media ? fileProperties.template.media : new Media();
|
||||||
|
|
||||||
if (fileProperties.template) {
|
if (fileProperties.template) {
|
||||||
this.currentRelationshipId = fileProperties.template.currentRelationshipId + 1;
|
this.currentRelationshipId = fileProperties.template.currentRelationshipId + 1;
|
||||||
}
|
}
|
||||||
@ -108,8 +109,9 @@ export class File {
|
|||||||
this.settings = new Settings();
|
this.settings = new Settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTableOfContents(toc: TableOfContents): void {
|
public addTableOfContents(toc: TableOfContents): File {
|
||||||
this.document.addTableOfContents(toc);
|
this.document.addTableOfContents(toc);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addParagraph(paragraph: Paragraph): File {
|
public addParagraph(paragraph: Paragraph): File {
|
||||||
@ -121,8 +123,9 @@ export class File {
|
|||||||
return this.document.createParagraph(text);
|
return this.document.createParagraph(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTable(table: Table): void {
|
public addTable(table: Table): File {
|
||||||
return this.document.addTable(table);
|
this.document.addTable(table);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createTable(rows: number, cols: number): Table {
|
public createTable(rows: number, cols: number): Table {
|
||||||
|
@ -44,6 +44,7 @@ export interface IDocumentTemplate {
|
|||||||
readonly footers: IDocumentFooter[];
|
readonly footers: IDocumentFooter[];
|
||||||
readonly styles: Styles;
|
readonly styles: Styles;
|
||||||
readonly titlePageIsDefined: boolean;
|
readonly titlePageIsDefined: boolean;
|
||||||
|
readonly media: Media;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImportDotx {
|
export class ImportDotx {
|
||||||
@ -73,6 +74,7 @@ export class ImportDotx {
|
|||||||
currentRelationshipId: this.currentRelationshipId,
|
currentRelationshipId: this.currentRelationshipId,
|
||||||
styles: stylesFactory.newInstance(stylesContent),
|
styles: stylesFactory.newInstance(stylesContent),
|
||||||
titlePageIsDefined: this.checkIfTitlePageIsDefined(documentContent),
|
titlePageIsDefined: this.checkIfTitlePageIsDefined(documentContent),
|
||||||
|
media: media,
|
||||||
};
|
};
|
||||||
|
|
||||||
return templateDocument;
|
return templateDocument;
|
||||||
|
Reference in New Issue
Block a user