Files
docx-js/src/importDocx/importDocx.ts

28 lines
1002 B
TypeScript
Raw Normal View History

2018-08-29 18:36:48 +03:00
import * as JSZip from "jszip";
import * as fastXmlParser from "fast-xml-parser";
import { convertToXmlComponent, parseOptions, ImportedXmlComponent } from "file/xml-components";
export class ImportDocx {
constructor() {
}
read(data) : Promise<any> {
return new Promise((resolve) => {
JSZip.loadAsync(data).then((zipContent) => {
let headerContent = zipContent['files']['word/header2.xml'];
headerContent.async('text').then((xmlData : string) => {
console.log('\n\n-------\n\n');
console.log('headerContent', JSON.stringify(xmlData, null, 2));
console.log('\n\n-------\n\n');
const jsonObj = fastXmlParser.parse(xmlData, parseOptions);
let xmlComp = convertToXmlComponent('w:hdr', jsonObj['w:hdr']) as ImportedXmlComponent;
resolve(xmlComp);
})
});
})
}
}