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 {
|
||||
width?: number;
|
||||
height?: number;
|
||||
orientation?: string;
|
||||
}
|
||||
|
||||
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
|
||||
protected xmlKeys = {
|
||||
width: "w:w",
|
||||
height: "w:h",
|
||||
orientation: "w:orient",
|
||||
};
|
||||
}
|
||||
|
@ -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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -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));
|
||||
|
Reference in New Issue
Block a user