Main Content

mlreportgen.dom.PageSize class

Package: mlreportgen.dom

Size and orientation of pages in Microsoft Word and PDF reports

Description

Use an object of the mlreportgen.dom.PageSize class to specify the height, width, and orientation of pages in a Microsoft® Word or PDF report.

The mlreportgen.dom.PageSize class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

PageSizeObj = mlreportgen.dom.PageSize() creates a PageSize object with properties that specify a height of 11 inches, a width of 8.5 inches, and a portrait orientation.

PageSizeObj = mlreportgen.dom.PageSize(height,width) creates a page size object that has the specified height and width and a portrait orientation.

example

PageSizeObj = mlreportgen.dom.PageSize(height,width,orientation) creates a page size object that has the specified height, width, and orientation.

Properties

expand all

Height of pages, specified as a character vector or string scalar that consists of a number followed by an abbreviation for a unit of measurement. For example, '11in' specifies 11 inches. Valid abbreviations are:

  • px — pixels (default)

  • cm — centimeters

  • in — inches

  • mm — millimeters

  • pc — picas

  • pt — points

Width of pages, specified as a character vector or string scalar that consists of a number followed by an abbreviation for a unit of measurement. For example, '8.5in' specifies 8.5 inches. Valid abbreviations are:

  • px — pixels (default)

  • cm — centimeters

  • in — inches

  • mm — millimeters

  • pc — picas

  • pt — points

Orientation of pages, specified as one of these character vectors or string scalars:

  • 'portrait' for vertical orientation

  • 'landscape' for horizontal orientation

The Height and Width properties determine the page orientation, regardless of the value of the Orientation property. However, it is a best practice to set the Orientation property to a value that is consistent with the page dimensions. If the height is greater than the width, set the Orientation to 'portrait'. If the width is greater than the height, set the Orientation to 'landscape'.

Tag for this document element, specified as a character vector or string scalar.

The DOM generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specifying your own tag value can help you to identify where an issue occurred during document generation.

ID for this document element, specified as a character vector or string scalar. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

Examples

collapse all

Use a PageSize object to specify the page size of a document. In the PageSize object, set the Orientation property to a value that is consistent with the Height and Width properties.

By default, a document has pages with an 11-inch height, 8.5-inch width, and portrait orientation. You can override the default page size by setting the Height and Width properties of the PageSize object used by the document layout object. For example, specify that the Height is "10in", the Width is "8in", and the Orientation is "portrait".

import mlreportgen.dom.*;
d = Document("myreport1","docx");
open(d);
 
pageLayoutObj = d.CurrentPageLayout;
pageLayoutObj.PageSize.Height = "10in";
pageLayoutObj.PageSize.Width = "8in";
pageLayoutObj.PageSize.Orientation  = "portrait";
append(d,"This document has portrait pages");

close(d);
rptview(d);

Specifying a height that is less than the width makes the orientation landscape, regardless of the value of the Orientation property. This example specifies a height of 8 inches and a width of 10 inches. The example sets the Orientation property to "landscape" to be consistent with the page size.

import mlreportgen.dom.*;
d = Document("myreport2","docx");
open(d);
 
pageLayoutObj = d.CurrentPageLayout;
pageLayoutObj.PageSize.Height = "8in";
pageLayoutObj.PageSize.Width = "10in";
pageLayoutObj.PageSize.Orientation  = "landscape";
append(d,"This document has landscape pages");

close(d);
rptview(d);

Instead of changing the page orientation by changing the height and width, you can use the rotate method of the layout object. The method switches the Height and Width property values and changes the Orientation property from portrait to landscape or landscape to portrait.

import mlreportgen.dom.*;
d = Document("myreport3","docx");
open(d);
 
pageLayoutObj = d.CurrentPageLayout;
pageLayoutObj.PageSize.Height = "10in";
pageLayoutObj.PageSize.Width = "8in";
pageLayoutObj.PageSize.Orientation  = "portrait";
rotate(pageLayoutObj);
append(d,"This document has landscape pages");

close(d);
rptview(d);

Use a PageSize object to specify the page size of a report or section of a report. In the PageSize object, set the Orientation property to a value that is consistent with the Height and Width properties.

By default, a report has pages with an 11-inch height and 8.5-inch width. To override the default page size for a report, create a PageSize object and assign it to the report layout object. To override the page size for a report section, create a create a PageSize object and assign it to the layout object used by the section reporter object. This example specifies a 10-inch height and 8-inch width for the report. The title page overrides the report page size and the rest of the report uses the page size of the report.

import mlreportgen.report.*;
import mlreportgen.dom.*;

rpt = Report("myreport1","docx");
open(rpt);

layoutObj = rpt.Layout;
layoutObj.PageSize = PageSize("10in","8in","portrait");

tp = TitlePage("Title","Title Page");
tplayoutObj = tp.Layout;
tplayoutObj.PageSize = PageSize("11in","9in","portrait");
append(rpt,tp);

toc = TableOfContents;
append(rpt,toc);

ch = Chapter("My Chapter");
para = Paragraph("This chapter uses the report page size");

close(rpt);
rptview(rpt);

The default page size of a report has a portrait orientation. To change the orientation of all pages of a report, use the Landscape property of the report layout object. This example specifies landscape orientation for all pages of the report.

import mlreportgen.report.*;
import mlreportgen.dom.*;

rpt = Report("myreport2","docx");
open(rpt);

layoutObj = rpt.Layout;
layoutObj.Landscape = true;

tp = TitlePage("Title","Title Page","SubTitle","With Page Size and Orientation of Report");
append(rpt,tp);

close(rpt);
rptview(rpt);

To change the orientation of the pages in a section with respect to the orientation of the report pages, use the Landscape property of the section layout object. In this example, the report has the default dimensions, 11-inch height and 8.5-inch width, which is portrait orientation. The example changes the orientation of the title page to landscape.

import mlreportgen.report.*;
import mlreportgen.dom.*;

rpt = Report("myreport3","docx");
open(rpt);
tp = TitlePage("Title","Title Page","SubTitle","With Landscape Orientation");
tplayoutObj = tp.Layout;
tplayoutObj.Landscape = true;
append(rpt,tp);

close(rpt);
rptview(rpt);
Introduced in R2016a