diff --git a/src/file/document/body/body.ts b/src/file/document/body/body.ts index 776c7fe0f0..4487a09c9a 100644 --- a/src/file/document/body/body.ts +++ b/src/file/document/body/body.ts @@ -1,8 +1,8 @@ import { XmlComponent } from "file/xml-components"; -import { SectionProperties } from "./section-properties/section-properties"; +import { SectionProperties, SectionPropertiesOptions } from "./section-properties/section-properties"; export class Body extends XmlComponent { - constructor() { + constructor(sectionPropertiesOptions?: SectionPropertiesOptions) { super("w:body"); } diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 88f1299b7d..e498b01394 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -12,10 +12,29 @@ import { PageSize } from "./page-size/page-size"; export type SectionPropertiesOptions = IPageSizeAttributes & IPageMarginAttributes & IColumnsAttributes & IDocGridAttributesProperties; export class SectionProperties extends XmlComponent { - constructor(options: SectionPropertiesOptions) { + constructor(options?: SectionPropertiesOptions) { super("w:sectPr"); - this.root.push(new PageSize(11906, 16838)); + const defaultOptions = { + width: 11906, + height: 16838, + top: 1440, + right: 1440, + bottom: 1440, + left: 1440, + header: 708, + footer: 708, + gutter: 0, + space: 708, + linePitch: 360, + }; + + const mergedOptions = { + ...defaultOptions, + ...options, + }; + + this.root.push(new PageSize(mergedOptions.width, mergedOptions.height)); this.root.push(new PageMargin(1440, 1440, 1440, 1440, 708, 708, 0)); this.root.push(new Columns(708)); this.root.push(new DocumentGrid(308)); diff --git a/src/file/document/document.ts b/src/file/document/document.ts index d19803edee..f29b2795b4 100644 --- a/src/file/document/document.ts +++ b/src/file/document/document.ts @@ -4,12 +4,13 @@ import { XmlComponent } from "file/xml-components"; import { Paragraph, PictureRun } from "../paragraph"; import { Table } from "../table"; import { Body } from "./body"; +import { SectionPropertiesOptions } from "./body/section-properties/section-properties"; import { DocumentAttributes } from "./document-attributes"; export class Document extends XmlComponent { private body: Body; - constructor() { + constructor(sectionPropertiesOptions?: SectionPropertiesOptions) { super("w:document"); this.root.push( new DocumentAttributes({ @@ -32,7 +33,7 @@ export class Document extends XmlComponent { Ignorable: "w14 w15 wp14", }), ); - this.body = new Body(); + this.body = new Body(sectionPropertiesOptions); this.root.push(this.body); } diff --git a/src/file/file.ts b/src/file/file.ts index 59af3c5ff3..03265a083e 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -1,5 +1,6 @@ import { Relationships } from "file/relationships"; import { Document } from "./document"; +import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties"; import { Media } from "./media"; import { Numbering } from "./numbering"; import { Paragraph } from "./paragraph"; @@ -16,8 +17,8 @@ export class File { private media: Media; private relationships: Relationships; - constructor(options?: IPropertiesOptions) { - this.document = new Document(); + constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) { + this.document = new Document(sectionPropertiesOptions); const stylesFactory = new DefaultStylesFactory(); this.styles = stylesFactory.newInstance();