2018-09-25 23:46:55 +01:00
|
|
|
import * as fs from "fs";
|
|
|
|
import { Document, ImportDotx, Packer, Paragraph } from "../build";
|
|
|
|
|
|
|
|
const importDotx = new ImportDotx();
|
|
|
|
const filePath = "./demo/dotx/template.dotx";
|
|
|
|
|
|
|
|
fs.readFile(filePath, (err, data) => {
|
|
|
|
if (err) {
|
|
|
|
throw new Error(`Failed to read file ${filePath}.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
importDotx.extract(data).then((templateDocument) => {
|
|
|
|
// This any needs fixing
|
|
|
|
const sectionProps = {
|
2018-10-02 17:52:55 +03:00
|
|
|
titlePage: templateDocument.titlePageIsDefined,
|
2018-09-25 23:46:55 +01:00
|
|
|
} as any;
|
|
|
|
|
|
|
|
const doc = new Document(undefined, sectionProps, {
|
|
|
|
template: templateDocument
|
|
|
|
});
|
|
|
|
const paragraph = new Paragraph("Hello World");
|
|
|
|
doc.addParagraph(paragraph);
|
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|