diff --git a/demo/demo14.js b/demo/demo14.js index 0e3859eadf..b2262f106a 100644 --- a/demo/demo14.js +++ b/demo/demo14.js @@ -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(); diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 450f2e9c33..bb12cda3c3 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -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, diff --git a/src/file/file.ts b/src/file/file.ts index 4efdba7dcb..fb7c6c83a0 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -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; }