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