Add section properties to root File

This commit is contained in:
Dolan
2018-01-24 13:09:34 +00:00
parent 2132c7b6da
commit 448572d7a1
4 changed files with 29 additions and 8 deletions

View File

@ -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");
}

View File

@ -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));

View File

@ -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);
}

View File

@ -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();