Landscape mode

This commit is contained in:
Dolan
2018-01-25 01:47:47 +00:00
parent 4339f8cfc0
commit 355e97cb5e
4 changed files with 24 additions and 4 deletions

14
demo/demo7.js Normal file
View File

@ -0,0 +1,14 @@
const docx = require("../build");
var doc = new docx.File(undefined, {
orientation: "landscape",
});
var paragraph = new docx.Paragraph("Hello World");
doc.addParagraph(paragraph);
var exporter = new docx.LocalPacker(doc);
exporter.pack("My Document");
console.log("Document created succesfully at project root!");

View File

@ -3,11 +3,13 @@ import { XmlAttributeComponent } from "file/xml-components";
export interface IPageSizeAttributes {
width?: number;
height?: number;
orientation?: string;
}
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
protected xmlKeys = {
width: "w:w",
height: "w:h",
orientation: "w:orient",
};
}

View File

@ -2,13 +2,16 @@ import { XmlComponent } from "file/xml-components";
import { PageSizeAttributes } from "./page-size-attributes";
export class PageSize extends XmlComponent {
constructor(width: number, height: number) {
constructor(width: number, height: number, orientation: string) {
super("w:pgSz");
const flip = orientation === "landscape";
this.root.push(
new PageSizeAttributes({
width: width,
height: height,
width: flip ? height : width,
height: flip ? width : height,
orientation: orientation,
}),
);
}

View File

@ -27,6 +27,7 @@ export class SectionProperties extends XmlComponent {
gutter: 0,
space: 708,
linePitch: 360,
orientation: "portrait",
};
const mergedOptions = {
@ -34,7 +35,7 @@ export class SectionProperties extends XmlComponent {
...options,
};
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height));
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
this.root.push(new PageMargin(mergedOptions.top, mergedOptions.right, mergedOptions.bottom, mergedOptions.left, mergedOptions.header, mergedOptions.footer, mergedOptions.gutter));
this.root.push(new Columns(mergedOptions.space));
this.root.push(new DocumentGrid(mergedOptions.linePitch));