extract styles from dotx
This commit is contained in:
@ -57,7 +57,13 @@ export class File {
|
||||
this.currentRelationshipId = fileProperties.template.currentRelationshipId + 1;
|
||||
}
|
||||
|
||||
if (options.externalStyles) {
|
||||
// set up styles
|
||||
if (fileProperties.template && options.externalStyles) {
|
||||
throw Error("can not use both template and external styles");
|
||||
}
|
||||
if (fileProperties.template) {
|
||||
this.styles = fileProperties.template.styles;
|
||||
} else if (options.externalStyles) {
|
||||
const stylesFactory = new ExternalStylesFactory();
|
||||
this.styles = stylesFactory.newInstance(options.externalStyles);
|
||||
} else {
|
||||
|
@ -7,6 +7,9 @@ import { FooterWrapper, IDocumentFooter } from "file/footer-wrapper";
|
||||
import { HeaderWrapper, IDocumentHeader } from "file/header-wrapper";
|
||||
import { convertToXmlComponent, ImportedXmlComponent, parseOptions } from "file/xml-components";
|
||||
|
||||
import { Styles } from "file/styles";
|
||||
import { ExternalStylesFactory } from "file/styles/external-styles-factory";
|
||||
|
||||
const importParseOptions = {
|
||||
...parseOptions,
|
||||
textNodeName: "",
|
||||
@ -36,6 +39,7 @@ export interface IDocumentTemplate {
|
||||
currentRelationshipId: number;
|
||||
headers: IDocumentHeader[];
|
||||
footers: IDocumentFooter[];
|
||||
styles: Styles;
|
||||
}
|
||||
|
||||
export class ImportDotx {
|
||||
@ -48,6 +52,10 @@ export class ImportDotx {
|
||||
public async extract(data: Buffer): Promise<IDocumentTemplate> {
|
||||
const zipContent = await JSZip.loadAsync(data);
|
||||
|
||||
const stylesContent = await zipContent.files["word/styles.xml"].async("text");
|
||||
const stylesFactory = new ExternalStylesFactory();
|
||||
const styles = stylesFactory.newInstance(stylesContent);
|
||||
|
||||
const documentContent = zipContent.files["word/document.xml"];
|
||||
const documentRefs: IDocumentRefs = this.extractDocumentRefs(await documentContent.async("text"));
|
||||
|
||||
@ -88,7 +96,7 @@ export class ImportDotx {
|
||||
footers.push({ type: footerRef.type, footer });
|
||||
}
|
||||
|
||||
const templateDocument: IDocumentTemplate = { headers, footers, currentRelationshipId: this.currentRelationshipId };
|
||||
const templateDocument: IDocumentTemplate = { headers, footers, currentRelationshipId: this.currentRelationshipId, styles };
|
||||
return templateDocument;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user