Use method approach to different first page header

This commit is contained in:
Dolan
2018-06-26 00:03:28 +01:00
parent 84ebf8e6c3
commit cee091fa58
3 changed files with 17 additions and 33 deletions

View File

@ -1,6 +1,6 @@
const docx = require('../build');
var doc = new docx.Document(undefined,{differentFirstPageHeader:true});
var doc = new docx.Document();
doc.createParagraph("First Page").pageBreak()
doc.createParagraph("Second Page");
@ -10,7 +10,8 @@ var pageNumber = new docx.TextRun().pageNumber()
var pageoneheader = new docx.Paragraph("First Page Header ").right();
pageoneheader.addRun(pageNumber);
doc.firstPageHeader.addParagraph(pageoneheader);
var firstPageHeader = doc.createFirstPageHeader();
firstPageHeader.addParagraph(pageoneheader);
var pagetwoheader = new docx.Paragraph("My Title ").right();

View File

@ -40,7 +40,6 @@ export class SectionProperties extends XmlComponent {
space: 708,
linePitch: 360,
orientation: PageOrientation.PORTRAIT,
differentFirstPageHeader: false,
headerType: HeaderReferenceType.DEFAULT,
headerId: 0,
footerType: FooterReferenceType.DEFAULT,
@ -69,17 +68,6 @@ export class SectionProperties extends XmlComponent {
this.root.push(new Columns(mergedOptions.space));
this.root.push(new DocumentGrid(mergedOptions.linePitch));
// TODO
// if (mergedOptions.differentFirstPageHeader) {
// this.root.push(
// new HeaderReference({
// headerType: HeaderReferenceType.FIRST,
// headerId: 5,
// }),
// );
// this.root.push(new TitlePage());
// }
this.root.push(
new HeaderReference({
headerType: mergedOptions.headerType,

View File

@ -3,7 +3,7 @@ import { AppProperties } from "./app-properties/app-properties";
import { ContentTypes } from "./content-types/content-types";
import { CoreProperties, IPropertiesOptions } from "./core-properties";
import { Document } from "./document";
import { FooterReferenceType, HeaderReferenceType } from "./document/body/section-properties";
import { FooterReferenceType, HeaderReference, HeaderReferenceType } from "./document/body/section-properties";
import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties";
import { FooterWrapper } from "./footer-wrapper";
import { HeaderWrapper } from "./header-wrapper";
@ -65,24 +65,8 @@ export class File {
this.contentTypes = new ContentTypes();
this.media = new Media();
const header = new HeaderWrapper(this.media, this.nextId++);
this.headerWrapper.push(header);
this.docRelationships.createRelationship(
header.Header.referenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
`header1.xml`,
);
this.contentTypes.addHeader(this.headerWrapper.length);
const footer = new FooterWrapper(this.media, this.nextId++);
this.footerWrapper.push(footer);
this.docRelationships.createRelationship(
footer.Footer.referenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
"footer1.xml",
);
this.contentTypes.addFooter(this.footerWrapper.length);
const header = this.createHeader();
const footer = this.createFooter();
this.fileRelationships = new Relationships();
this.fileRelationships.createRelationship(
@ -198,6 +182,17 @@ export class File {
return footer;
}
public createFirstPageHeader(): HeaderWrapper {
const headerWrapper = this.createHeader();
this.document.Body.DefaultSection.addChildElement(new HeaderReference({
headerType: HeaderReferenceType.FIRST,
headerId: headerWrapper.Header.referenceId,
}));
return headerWrapper;
}
public get Document(): Document {
return this.document;
}