Main Content

mlreportgen.dom.Watermark class

Package: mlreportgen.dom
Superclasses:

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: .bmp, .jpg, .png, .svg, and .tiff.

Construction

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

Input Arguments

expand all

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

  • .bmp

  • .jpg

  • .pdf (for PDF output types only)

  • .png

  • .svg

  • .tiff

Properties

expand all

Character vector in the form valueUnits. Use any of these values for units:

  • px — pixels (default)

  • 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')};

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.

Path of image file, specified as a character vector.

Format objects that specify the format of a document element.

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.

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

  • px — pixels (default)

  • 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')};

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);
Introduced in R2016b