mlreportgen.dom.Document class
Package: mlreportgen.dom
Document container
Description
Use an object of the mlreportgen.dom.Document
class to represent a
Document Object Model (DOM) document. Use Document
object properties to specify:
Whether to generate an HTML, Microsoft® Word, or PDF document
Where and how to store the generated document
The template to use to format the document
The mlreportgen.dom.Document
class is a handle
class.
Class Attributes
ConstructOnLoad | true |
HandleCompatible | true |
For information on class attributes, see Class Attributes.
Creation
Description
creates a documentObj
= mlreportgen.dom.Document()Document
object with default property values, which
specify an output file named Untitled.htmx
in the current
folder, using the default HTML template.
specifies the path and name of the output file and sets the documentObj
= mlreportgen.dom.Document(outputPath
)OutputPath
property to outputPath
.
also specifies the output type and sets the documentObj
= mlreportgen.dom.Document(outputPath
,type
)Type
property to
type
.
also specifies the path and name of the template file and sets the documentObj
= mlreportgen.dom.Document(outputPath
,type
,templatePath
)TemplatePath
property to
templatePath
.
Properties
OutputPath
— Path and name of output file or folder for this document
string scalar | character vector
Path and name of the output file or folder for this document, specified as a string scalar or character vector. You can specify an absolute path or a path relative to the current folder. You can set this property only before opening the document.
The default value is the path of a file or folder named
untitled
in the current folder. If
OutputPath
specifies a file and you do not specify
the file extension, the DOM API adds an extension based on the Type
property.
Whether OutputPath
specifies the path of a file or
folder depends on the value of the PackageType
property, as shown in the table.
PackageType | OutputPath Value |
---|---|
"zipped" or
"single-file" | Path and name of ZIP file or single file |
"unzipped" | Folder for the unzipped files |
"both" | Path and name of ZIP file and folder for the unzipped files |
Note
Generating a PDF report on a cloud drive, such as MATLAB® Drive™, can result in an error that is caused by file contention between the report generation software and the cloud drive synchronization software. To avoid this error, generate reports on a local drive that does not synchronize with the cloud. Consider writing a script that generates a report on a local drive and then copies the report to the cloud drive.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
PackageType
— Packaging for generated files
"zipped"
| "unzipped"
| "both"
| "single-file"
Packaging used for the generated files, specified as one of the values in the table. You can
specify PackageType
as a string scalar or character
vector.
Value | Supported Report Types | Description |
---|---|---|
|
| Generates the report as a ZIP file at the location
specified by the |
"unzipped" |
| Generates the report as separate files in a folder that has
the file name of the |
"both" |
| Generates zipped and unzipped outputs. |
"single-file" |
| Generates the report as a single file. |
To generate an HTML report that you can open without unzipping, set Type
to "html"
and PackageType
to
"unzipped"
or "both"
. In the folder that
contains the generated files, open the root.html
file.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
ForceOverwrite
— Whether to overwrite existing output file
true
(default) | false
Whether to overwrite an existing output file, specified as
true
or false
. Set this property
to true
to overwrite an existing output file with the
same name. If this property is false
and a writable file
with the same name exists, closing this document causes an error. If the
existing file is read-only, closing this document causes an error regardless
of this property setting.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
StreamOutput
— Option to stream output to disk
false
(default) | true
Option to stream the output to disk, specified as true
or
false
. By default, document elements are stored in memory until
the document is closed. Set this property to true
to write the
document elements to disk as the elements are appended to the document.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
TitleBarText
— Text for HTML browser title bar
string scalar | character vector
Text for the HTML browser title bar, specified as a string scalar or character vector. For HTML documents, this property specifies the text that appears in the title bar of the browser used to display this document. Word and PDF documents ignore this property.
Set this property before opening the document.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
HTMLHeadExt
— Custom content for HTML header
string scalar | character vector
Custom content for the HTML header, specified as a string scalar or
character vector. The value of this property is appended to the
<head>
element of this document after the
content specified by the head section of the document template. Set this
property only before opening the document.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
TemplatePath
— Path of template to use
string scalar | character vector
Full path of the template to use, specified as a string scalar or character vector.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Type
— Type of output
"html"
(default) | "docx"
| "pdf"
| "html-file"
Type of output, specified as one of these string scalars or character vectors:
"html"
— HTML output packaged as a zipped or unzipped folder that contains the HTML document text, image, style sheet, and JavaScript® files"docx"
— Word output"pdf"
— PDF output"html-file"
— A single HTML file that contains the text, style sheets, JavaScript, and images for the report
If you specify a template using the TemplatePath
property, the template must be consistent with the Type
argument. You must specify a template with a Word template extension
(.dotx
) for Word output, an HTML template package
extension (.htmtx
) for HTML output, a PDF template
package extension (.pdftx
) for PDF output, and a
single-file HTML template extension (.htmt
) for
html-file
output.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
CurrentHoleId
— ID of current hole in document
character vector
ID of the current hole in the document, specified as a character vector.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
CurrentHoleType
— Type of current hole
'Inline'
| 'Block'
Type of the current template hole, specified as 'Inline'
or 'Block'
.
An inline hole is for document elements that a paragraph element can contain:
Text
,Image
,LinkTarget
,ExternalLink
,InternalLink
,CharEntity
, orAutoNumber
.A block hole can contain a
Paragraph
,Table
,OrderedList
,UnorderedList
,DocumentPart
, orGroup
element.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
CurrentPageLayout
— Current page layout of this document
mlreportgen.dom.DOCXPageLayout
object | mlreportgen.dom.PDFPageLayout
object | []
Current page layout of this document, specified as an
mlreportgen.dom.DOCXPageLayout
object,
mlreportgen.dom.PDFPageLayout
object, or []
. This
property applies to Word and PDF documents. For Word documents, the value is a
DOCXPageLayout
object that specifies the current page layout. For
PDF documents, the value is a PDFPageLayout
object if the document
currently specifies a page layout. For HTML documents, the value is always
[]
.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
OpenStatus
— Open status of document
'unopened'
(default) | 'open'
| 'closed'
Open status of this document, specified as 'unopened'
,
'open'
, or 'closed'
.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
Parent
— Parent of this DOM API object
DOM API object
Parent of this DOM API object, specified as a DOM API object.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
Children
— Children of this DOM API object
array of DOM API objects
Children of this DOM API object, specified as an array of DOM API objects.
Attributes:
GetAccess | public |
SetAccess | private |
Transient | true |
NonCopyable | true |
Tag
— Tag for this DOM API object
character vector | string scalar
Tag for this DOM API object, 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.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Id
— ID for this DOM API object
character vector | string scalar
ID for this DOM API object, 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.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Methods
Public Methods
addHTML | Append HTML string to document |
addHTMLFile | Append HTML file contents to document |
append | Append DOM or MATLAB object to document |
close | Close document |
createAutoNumberStream | Create numbering stream |
mlreportgen.dom.Document.createTemplate | Create DOM template file |
fill | Fill document holes with generated content |
getAutoNumberStream | Return numbering stream |
mlreportgen.dom.Document.getCoreProperties | Get document or template core properties |
mlreportgen.dom.Document.getImageDirectory | Get image folder of document |
mlreportgen.dom.Document.getImagePrefix | Get generated image name prefix |
getMainPartPath | Return path of main part of document output package |
mlreportgen.dom.Document.getOPCMainPart | Return main part of document, document part, or template |
moveToNextHole | Move document append point to next template hole |
open | Open document |
package | Add OPC part files to document package |
mlreportgen.dom.Document.setCoreProperties | Set OPC core properties of output document or template |
Examples
Create a Word Document
Create a Word document, add content, and view the report in Word.
import mlreportgen.dom.*; d = Document("mydoc","docx"); append(d,"Hello World"); close(d); rptview(d);
Create an HTML Document as a Single File
Create an HTML document as a single HTML file that includes
an image. The example assumes that there is a MyImage.jpg
file and a myHTMLTemplate.htmt
HTML template file.
Create a document whose output is a single HTML file and uses the template
myHTMLTemplate
. Add text and an image to the report.
Close and view the document.
import mlreportgen.dom.*; d = Document("mydoc","html-file","myHTMLTemplate.htmt"); open(d); append(d,"Hello world"); append(d,Image("C:/images/LocalSystem/MyImage.jpg")); close(d); rptview(d);
Version History
Introduced in R2014b
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)