Landscape mode
This commit is contained in:
14
demo/demo7.js
Normal file
14
demo/demo7.js
Normal 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!");
|
@ -3,11 +3,13 @@ import { XmlAttributeComponent } from "file/xml-components";
|
|||||||
export interface IPageSizeAttributes {
|
export interface IPageSizeAttributes {
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
|
orientation?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
||||||
protected xmlKeys = {
|
protected xmlKeys = {
|
||||||
width: "w:w",
|
width: "w:w",
|
||||||
height: "w:h",
|
height: "w:h",
|
||||||
|
orientation: "w:orient",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,16 @@ import { XmlComponent } from "file/xml-components";
|
|||||||
import { PageSizeAttributes } from "./page-size-attributes";
|
import { PageSizeAttributes } from "./page-size-attributes";
|
||||||
|
|
||||||
export class PageSize extends XmlComponent {
|
export class PageSize extends XmlComponent {
|
||||||
constructor(width: number, height: number) {
|
constructor(width: number, height: number, orientation: string) {
|
||||||
super("w:pgSz");
|
super("w:pgSz");
|
||||||
|
|
||||||
|
const flip = orientation === "landscape";
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new PageSizeAttributes({
|
new PageSizeAttributes({
|
||||||
width: width,
|
width: flip ? height : width,
|
||||||
height: height,
|
height: flip ? width : height,
|
||||||
|
orientation: orientation,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
gutter: 0,
|
gutter: 0,
|
||||||
space: 708,
|
space: 708,
|
||||||
linePitch: 360,
|
linePitch: 360,
|
||||||
|
orientation: "portrait",
|
||||||
};
|
};
|
||||||
|
|
||||||
const mergedOptions = {
|
const mergedOptions = {
|
||||||
@ -34,7 +35,7 @@ export class SectionProperties extends XmlComponent {
|
|||||||
...options,
|
...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 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 Columns(mergedOptions.space));
|
||||||
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
this.root.push(new DocumentGrid(mergedOptions.linePitch));
|
||||||
|
Reference in New Issue
Block a user