Merge branch 'master' of https://github.com/h4buli/docx into feat/h4buli-update
# Conflicts: # package.json # src/file/numbering/numbering.ts
This commit is contained in:
@ -11,7 +11,9 @@ import { Paragraph, PictureRun } from "./paragraph";
|
||||
import { Relationships } from "./relationships";
|
||||
import { Styles } from "./styles";
|
||||
import { DefaultStylesFactory } from "./styles/factory";
|
||||
import { ExternalStylesFactory } from "./styles/external-styles-factory";
|
||||
import { Table } from "./table";
|
||||
import { IMediaData } from "index";
|
||||
|
||||
export class File {
|
||||
private readonly document: Document;
|
||||
@ -28,8 +30,6 @@ export class File {
|
||||
|
||||
constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) {
|
||||
this.document = new Document(sectionPropertiesOptions);
|
||||
const stylesFactory = new DefaultStylesFactory();
|
||||
this.styles = stylesFactory.newInstance();
|
||||
|
||||
if (!options) {
|
||||
options = {
|
||||
@ -39,6 +39,14 @@ export class File {
|
||||
};
|
||||
}
|
||||
|
||||
if (options.externalStyles) {
|
||||
const stylesFactory = new ExternalStylesFactory();
|
||||
this.styles = stylesFactory.newInstance(options.externalStyles);
|
||||
} else {
|
||||
const stylesFactory = new DefaultStylesFactory();
|
||||
this.styles = stylesFactory.newInstance();
|
||||
}
|
||||
|
||||
this.coreProperties = new CoreProperties(options);
|
||||
this.numbering = new Numbering();
|
||||
this.docRelationships = new Relationships();
|
||||
@ -111,6 +119,16 @@ export class File {
|
||||
return this.document.createDrawing(mediaData);
|
||||
}
|
||||
|
||||
public createImageData(imageName: string, data: Buffer, width?: number, height?: number): IMediaData {
|
||||
const mediaData = this.media.addMediaWithData(imageName, data, this.docRelationships.RelationshipCount, width, height);
|
||||
this.docRelationships.createRelationship(
|
||||
mediaData.referenceId,
|
||||
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
||||
`media/${mediaData.fileName}`,
|
||||
);
|
||||
return mediaData;
|
||||
}
|
||||
|
||||
public get Document(): Document {
|
||||
return this.document;
|
||||
}
|
||||
|
Reference in New Issue
Block a user