import { twipsMeasureValue } from "file/values";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
//
//
//
//
//
//
export enum PageOrientation {
PORTRAIT = "portrait",
LANDSCAPE = "landscape",
}
//
//
//
//
//
//
export interface IPageSizeAttributes {
readonly width?: number | string;
readonly height?: number | string;
readonly orientation?: PageOrientation;
}
export class PageSizeAttributes extends XmlAttributeComponent {
protected readonly xmlKeys = {
width: "w:w",
height: "w:h",
orientation: "w:orient",
};
}
export class PageSize extends XmlComponent {
constructor(width: number | string, height: number | string, orientation: PageOrientation) {
super("w:pgSz");
const flip = orientation === PageOrientation.LANDSCAPE;
const widthTwips = twipsMeasureValue(width);
const heightTwips = twipsMeasureValue(height);
this.root.push(
new PageSizeAttributes({
width: flip ? heightTwips : widthTwips,
height: flip ? widthTwips : heightTwips,
orientation: orientation,
}),
);
}
}