Main Content

mlreportgen.dom.Watermark Class

Namespace: mlreportgen.dom

Add watermark to pages in sections of PDF reports

Description

Creates a watermark object that you can add to a section of a PDF report. A watermark is an image that appears in the background of a page, such as the word Draft or Confidential. It runs behind the text on each page you apply it to. You can use any of these file types:

  • .emf

  • .gif

  • .jpg

  • .pdf

  • .png

  • .svg

  • .tiff

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

Creation

Description

wm = Watermark(image) creates a Watermark object based on the specified image, and returns a Watermark object.

example

Input Arguments

expand all

Image to use as the watermark, specified as the image path name. Use any of these file types:

  • .emf

  • .gif

  • .jpg

  • .pdf

  • .png

  • .svg

  • .tiff

Properties

expand all

Path of image file, specified as a character vector or string scalar.

Attributes:

SetAccess
private
NonCopyable
true
Transient
true

Data Types: char | string

Watermark height in the form valueUnits, specified as a character vector or a string scalar. Use any of these values for units:

  • "px" — pixels

  • "cm" — centimeters

  • "in" — inches

  • "mm" — millimeters

  • "pc" — picas

  • "pt" — points

Alternatively, You can specify the height using the Watermark.Style property. For example:

Watermark.Style = {Height('4in')};

Attributes:

NonCopyable
true

Data Types: char | string

Watermark width, specified as a character vector or string scalar in the form valueUnits. Use any of these values for units:

  • "px" — pixels

  • "cm" — centimeters

  • "in" — inches

  • "mm" — millimeters

  • "pc" — picas

  • "pt" — points

Alternatively, you can specify the width using the Watermark.Style property. For example:

Watermark.Style = {Width('4in')};

Attributes:

NonCopyable
true

Data Types: char | string

Format specification for this document element object, specified as an array of DOM format objects. The formats specified by this property override corresponding formats specified by the StyleName property of this element. Formats that do not apply to this document element object are ignored.

Attributes:

NonCopyable
true

Custom attributes of this document element, specified as an array of mlreportgen.dom.CustomAttribute objects. The custom attributes must be supported by the output format of the document element to which this object is appended.

Attributes:

NonCopyable
true

Tag for the mlreportgen.dom.Watermark 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

Object identifier for the mlreportgen.dom.Watermark 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

collapse all

This example shows how to create a watermark programmatically and then apply it to the current layout. Creating the watermark programmatically simplifies files management, because you do not need to store the image file and keep track of its location.

Using MATLAB® commands, create an image file programmatically. Using an SVG image file maintains the resolution as the image scales. After you write the image to a file, you can delete the figure.

 wmname = 'wm';
 wmtype =  'svg';
 wmfilename = [wmname '.' wmtype];

 subplot('Position',[0, 0, 1, 1]);
 axis('off');
 text(0.25, 0.25,'Draft', ...
   'Rotation', 45, ...
   'Color', [0.85, 0.85, 0.85], ...
   'FontSize',72);

  print(wmfilename, ['-d' wmtype]);
  delete(gcf);

Create the watermark object wm and apply it to the current page layout. After you generate the report, you can delete the image file specified by the variable wmfilename.

import mlreportgen.dom.*;

d = Document('myreport','pdf');
open(d);

wm = Watermark(wmfilename);
wm.Width = '12in';
wm.Height = [];

d.CurrentPageLayout.Watermark = wm;

append(d,'Hello');
append(d, PageBreak);
append(d,'World');

close(d);
rptview(d.OutputPath);
delete(wmfilename);

Version History

Introduced in R2016b

expand all