mlreportgen.dom.PageSize Class
Namespace: 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
creates a PageSizeObj
= mlreportgen.dom.PageSizePageSize
object with properties that specify a height
of 11 inches, a width of 8.5 inches, and a portrait orientation.
creates a page size object that has the specified height and width and a
portrait orientation.PageSizeObj
= mlreportgen.dom.PageSize(height
,width
)
creates a page size object that has the specified height, width, and
orientation.PageSizeObj
= mlreportgen.dom.PageSize(height
,width
,orientation
)
Properties
Height
— Height of pages
"11in"
(default) | character vector | string scalar
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"cm"
— centimeters"in"
— inches"mm"
— millimeters"pc"
— picas"pt"
— points
Width
— Width of pages
"8.5in"
(default) | character vector | string scalar
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"cm"
— centimeters"in"
— inches"mm"
— millimeters"pc"
— picas"pt"
— points
Orientation
— Orientation of pages
"portrait"
(default) | "landscape"
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"
.
Attributes:
NonCopyable | true |
Data Types: char
| string
Tag
— Tag for mlreportgen.dom.PageSize
object
character vector | string scalar
Tag for the mlreportgen.dom.PageSize
object, specified as a character vector or
string scalar. The DOM API 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. Specify your own tag value to help
you identify where to look when an issue occurs during document generation.
Attributes:
NonCopyable | true |
Data Types: char
| string
Id
— Object identifier for mlreportgen.dom.PageSize
object
character vector | string scalar
Object identifier for the mlreportgen.dom.PageSize
object, specified as a
character vector or string scalar. The DOM API generates a session-unique identifier
when it creates the document element object. You can specify your own value for
Id
.
Attributes:
NonCopyable | true |
Data Types: char
| string
Examples
Specify Page Size and Orientation in a DOM Document
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);
Specify Page Size and Orientation in a Report API Report
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);
Version History
Introduced in R2016a
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)