// add header contents in a specific section in a DOCX template

import { CreateDocx, OptionsHeader, WordFragment } from "../../../build";
import * as fs from "fs";

const docxTemplate = fs.readFileSync("../../files/TemplateVariables.docx");

const docx = new CreateDocx();
// load the template
docx.openTemplate(docxTemplate).then(docx => {
    const headers: OptionsHeader[] = [];

    const headerFragmentDefault = new WordFragment();
    headerFragmentDefault.addText("Text header.");
    const headerContentDefault: OptionsHeader = {
        text: headerFragmentDefault,
    };

    headers.push(headerContentDefault);

    docx.addHeader(headers);

    docx.save().then(contents => {
        fs.writeFileSync("addHeader_4.docx", Buffer.from(contents));
    });
});
