2018-01-24 00:01:38 +00:00
|
|
|
// http://officeopenxml.com/WPsection.php
|
2018-10-26 01:04:07 +01:00
|
|
|
import { FooterWrapper } from "file/footer-wrapper";
|
|
|
|
import { HeaderWrapper } from "file/header-wrapper";
|
2018-01-24 00:01:38 +00:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
2018-10-26 01:04:07 +01:00
|
|
|
|
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-10-05 01:33:17 +01:00
|
|
|
import { FooterReferenceType } from "./footer-reference";
|
|
|
|
import { FooterReference } from "./footer-reference/footer-reference";
|
|
|
|
import { HeaderReferenceType } from "./header-reference";
|
|
|
|
import { HeaderReference } from "./header-reference/header-reference";
|
2018-10-26 01:04:07 +01:00
|
|
|
import { IPageBordersOptions, PageBorders } from "./page-border";
|
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-10-26 01:04:07 +01:00
|
|
|
import { IPageNumberTypeAttributes, PageNumberFormat, PageNumberType } from "./page-number";
|
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-09-04 17:16:31 +03:00
|
|
|
import { TitlePage } from "./title-page/title-page";
|
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
export interface IHeaderFooterGroup<T> {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly default?: T;
|
|
|
|
readonly first?: T;
|
|
|
|
readonly even?: T;
|
2018-10-05 01:33:17 +01:00
|
|
|
}
|
|
|
|
|
2018-09-07 21:48:59 +01:00
|
|
|
interface IHeadersOptions {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly headers?: IHeaderFooterGroup<HeaderWrapper>;
|
2018-09-07 21:48:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IFootersOptions {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly footers?: IHeaderFooterGroup<FooterWrapper>;
|
2018-10-05 01:33:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ITitlePageOptions {
|
2018-11-02 02:51:57 +00:00
|
|
|
readonly titlePage?: boolean;
|
2018-09-07 21:48:59 +01:00
|
|
|
}
|
2018-01-24 00:01:38 +00:00
|
|
|
|
2018-06-21 12:03:34 +02:00
|
|
|
export type SectionPropertiesOptions = IPageSizeAttributes &
|
|
|
|
IPageMarginAttributes &
|
|
|
|
IColumnsAttributes &
|
|
|
|
IDocGridAttributesProperties &
|
2018-09-04 17:16:31 +03:00
|
|
|
IHeadersOptions &
|
|
|
|
IFootersOptions &
|
2018-07-03 13:48:31 +02:00
|
|
|
IPageNumberTypeAttributes &
|
2018-10-05 01:33:17 +01:00
|
|
|
IPageBordersOptions &
|
|
|
|
ITitlePageOptions;
|
2018-01-24 00:01:38 +00:00
|
|
|
|
|
|
|
export class SectionProperties extends XmlComponent {
|
2018-08-07 01:38:15 +01:00
|
|
|
private readonly options: SectionPropertiesOptions;
|
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
constructor(options: SectionPropertiesOptions = {}) {
|
2018-01-24 00:01:38 +00:00
|
|
|
super("w:sectPr");
|
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
const {
|
|
|
|
width = 11906,
|
|
|
|
height = 16838,
|
|
|
|
top = 1440,
|
|
|
|
right = 1440,
|
|
|
|
bottom = 1440,
|
|
|
|
left = 1440,
|
|
|
|
header = 708,
|
|
|
|
footer = 708,
|
|
|
|
gutter = 0,
|
|
|
|
mirror = false,
|
|
|
|
space = 708,
|
|
|
|
linePitch = 360,
|
|
|
|
orientation = PageOrientation.PORTRAIT,
|
|
|
|
headers,
|
|
|
|
footers,
|
|
|
|
pageNumberFormatType = PageNumberFormat.DECIMAL,
|
|
|
|
pageNumberStart,
|
|
|
|
pageBorders,
|
|
|
|
pageBorderTop,
|
|
|
|
pageBorderRight,
|
|
|
|
pageBorderBottom,
|
|
|
|
pageBorderLeft,
|
|
|
|
titlePage = false,
|
|
|
|
} = options;
|
2018-06-21 12:03:34 +02:00
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
this.options = options;
|
|
|
|
this.root.push(new PageSize(width, height, orientation));
|
|
|
|
this.root.push(new PageMargin(top, right, bottom, left, header, footer, gutter, mirror));
|
|
|
|
this.root.push(new Columns(space));
|
|
|
|
this.root.push(new DocumentGrid(linePitch));
|
|
|
|
|
|
|
|
this.addHeaders(headers);
|
|
|
|
this.addFooters(footers);
|
2018-09-07 21:48:59 +01:00
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
this.root.push(new PageNumberType(pageNumberStart, pageNumberFormatType));
|
2018-06-21 12:03:34 +02:00
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
if (pageBorders || pageBorderTop || pageBorderRight || pageBorderBottom || pageBorderLeft) {
|
2018-07-03 13:48:31 +02:00
|
|
|
this.root.push(
|
|
|
|
new PageBorders({
|
2018-10-05 01:33:17 +01:00
|
|
|
pageBorders: pageBorders,
|
|
|
|
pageBorderTop: pageBorderTop,
|
|
|
|
pageBorderRight: pageBorderRight,
|
|
|
|
pageBorderBottom: pageBorderBottom,
|
|
|
|
pageBorderLeft: pageBorderLeft,
|
2018-07-03 13:48:31 +02:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
if (titlePage) {
|
2018-09-04 17:16:31 +03:00
|
|
|
this.root.push(new TitlePage());
|
|
|
|
}
|
2018-10-05 01:33:17 +01:00
|
|
|
}
|
2018-09-04 17:16:31 +03:00
|
|
|
|
2018-10-05 01:33:17 +01:00
|
|
|
private addHeaders(headers?: IHeaderFooterGroup<HeaderWrapper>): void {
|
|
|
|
if (headers) {
|
|
|
|
if (headers.default) {
|
|
|
|
this.root.push(
|
|
|
|
new HeaderReference({
|
|
|
|
headerType: HeaderReferenceType.DEFAULT,
|
|
|
|
headerId: headers.default.Header.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (headers.first) {
|
|
|
|
this.root.push(
|
|
|
|
new HeaderReference({
|
|
|
|
headerType: HeaderReferenceType.FIRST,
|
|
|
|
headerId: headers.first.Header.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (headers.even) {
|
|
|
|
this.root.push(
|
|
|
|
new HeaderReference({
|
|
|
|
headerType: HeaderReferenceType.EVEN,
|
|
|
|
headerId: headers.even.Header.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private addFooters(footers?: IHeaderFooterGroup<FooterWrapper>): void {
|
|
|
|
if (footers) {
|
|
|
|
if (footers.default) {
|
|
|
|
this.root.push(
|
|
|
|
new FooterReference({
|
|
|
|
footerType: FooterReferenceType.DEFAULT,
|
|
|
|
footerId: footers.default.Footer.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (footers.first) {
|
|
|
|
this.root.push(
|
|
|
|
new FooterReference({
|
|
|
|
footerType: FooterReferenceType.FIRST,
|
|
|
|
footerId: footers.first.Footer.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (footers.even) {
|
|
|
|
this.root.push(
|
|
|
|
new FooterReference({
|
|
|
|
footerType: FooterReferenceType.EVEN,
|
|
|
|
footerId: footers.even.Footer.ReferenceId,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-06-21 12:03:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 02:29:58 +01:00
|
|
|
public get Options(): SectionPropertiesOptions {
|
2018-06-21 12:03:34 +02:00
|
|
|
return this.options;
|
2018-01-24 00:01:38 +00:00
|
|
|
}
|
|
|
|
}
|