2018-01-24 00:01:38 +00:00
|
|
|
// http://officeopenxml.com/WPsection.php
|
|
|
|
import { XmlComponent } from "file/xml-components";
|
2018-06-22 22:59:38 +01:00
|
|
|
import { FooterReferenceType, IPageNumberTypeAttributes, PageNumberFormat, PageNumberType } from "./";
|
2018-01-24 00:01:38 +00:00
|
|
|
import { Columns } from "./columns/columns";
|
2018-01-29 02:56:35 +00:00
|
|
|
import { IColumnsAttributes } from "./columns/columns-attributes";
|
2018-01-24 00:01:38 +00:00
|
|
|
import { DocumentGrid } from "./doc-grid/doc-grid";
|
|
|
|
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
|
2018-06-22 22:59:38 +01:00
|
|
|
import { FooterOptions, FooterReference } from "./footer-reference/footer-reference";
|
|
|
|
import { HeaderOptions, HeaderReference } from "./header-reference/header-reference";
|
|
|
|
import { HeaderReferenceType } from "./header-reference/header-reference-attributes";
|
2018-01-24 00:01:38 +00:00
|
|
|
import { PageMargin } from "./page-margin/page-margin";
|
2018-01-29 02:56:35 +00:00
|
|
|
import { IPageMarginAttributes } from "./page-margin/page-margin-attributes";
|
2018-01-24 00:01:38 +00:00
|
|
|
import { PageSize } from "./page-size/page-size";
|
2018-06-21 12:03:34 +02:00
|
|
|
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
|
2018-05-17 11:54:13 -06:00
|
|
|
import { TitlePage } from "./title-page/title-page";
|
2018-01-24 00:01:38 +00:00
|
|
|
|
2018-06-21 12:03:34 +02:00
|
|
|
export type SectionPropertiesOptions = IPageSizeAttributes &
|
|
|
|
IPageMarginAttributes &
|
|
|
|
IColumnsAttributes &
|
|
|
|
IDocGridAttributesProperties &
|
|
|
|
HeaderOptions &
|
|
|
|
FooterOptions &
|
|
|
|
IPageNumberTypeAttributes;
|
2018-01-24 00:01:38 +00:00
|
|
|
|
|
|
|
export class SectionProperties extends XmlComponent {
|
2018-06-21 12:03:34 +02:00
|
|
|
private options: SectionPropertiesOptions;
|
2018-01-24 13:09:34 +00:00
|
|
|
constructor(options?: SectionPropertiesOptions) {
|
2018-01-24 00:01:38 +00:00
|
|
|
super("w:sectPr");
|
|
|
|
|
2018-01-24 13:09:34 +00:00
|
|
|
const defaultOptions = {
|
|
|
|
width: 11906,
|
|
|
|
height: 16838,
|
|
|
|
top: 1440,
|
|
|
|
right: 1440,
|
|
|
|
bottom: 1440,
|
|
|
|
left: 1440,
|
|
|
|
header: 708,
|
|
|
|
footer: 708,
|
|
|
|
gutter: 0,
|
|
|
|
space: 708,
|
|
|
|
linePitch: 360,
|
2018-06-21 12:03:34 +02:00
|
|
|
orientation: PageOrientation.PORTRAIT,
|
2018-05-17 11:45:06 -06:00
|
|
|
differentFirstPageHeader: false,
|
2018-06-21 12:03:34 +02:00
|
|
|
headerType: HeaderReferenceType.DEFAULT,
|
|
|
|
headerId: 0,
|
|
|
|
footerType: FooterReferenceType.DEFAULT,
|
|
|
|
footerId: 0,
|
|
|
|
pageNumberStart: undefined,
|
|
|
|
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
2018-01-24 13:09:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const mergedOptions = {
|
|
|
|
...defaultOptions,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
|
2018-01-25 01:47:47 +00:00
|
|
|
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
|
2018-01-28 20:34:49 +00:00
|
|
|
this.root.push(
|
|
|
|
new PageMargin(
|
|
|
|
mergedOptions.top,
|
|
|
|
mergedOptions.right,
|
|
|
|
mergedOptions.bottom,
|
|
|
|
mergedOptions.left,
|
|
|
|
mergedOptions.header,
|
|
|
|
mergedOptions.footer,
|
|
|
|
mergedOptions.gutter,
|
|
|
|
),
|
|
|
|
);
|
2018-01-25 01:21:03 +00:00
|
|
|
this.root.push(new Columns(mergedOptions.space));
|
|
|
|
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
2018-05-18 09:21:27 -06:00
|
|
|
|
2018-05-17 11:45:06 -06:00
|
|
|
if (mergedOptions.differentFirstPageHeader) {
|
2018-06-22 22:59:38 +01:00
|
|
|
this.root.push(
|
|
|
|
new HeaderReference({
|
|
|
|
headerType: HeaderReferenceType.FIRST,
|
|
|
|
headerId: 5,
|
|
|
|
}),
|
|
|
|
);
|
2018-05-17 11:45:06 -06:00
|
|
|
this.root.push(new TitlePage());
|
|
|
|
}
|
2018-05-18 09:21:27 -06:00
|
|
|
|
2018-06-21 12:03:34 +02:00
|
|
|
this.root.push(
|
|
|
|
new HeaderReference({
|
|
|
|
headerType: mergedOptions.headerType,
|
|
|
|
headerId: mergedOptions.headerId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
this.root.push(
|
|
|
|
new FooterReference({
|
|
|
|
footerType: mergedOptions.footerType,
|
|
|
|
footerId: mergedOptions.footerId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
this.root.push(new PageNumberType(mergedOptions.pageNumberStart, mergedOptions.pageNumberFormatType));
|
|
|
|
|
|
|
|
this.options = mergedOptions;
|
|
|
|
}
|
|
|
|
|
2018-06-22 22:59:38 +01:00
|
|
|
get Options(): SectionPropertiesOptions {
|
2018-06-21 12:03:34 +02:00
|
|
|
return this.options;
|
2018-01-24 00:01:38 +00:00
|
|
|
}
|
|
|
|
}
|