You can add watermarks in an exported PDF document and set different options for these watermarks.
Any object of the PDFExportParams
class can contain an array of Watermark
instances,
can add new watermarks to the array, and can remove all watermarks from the array.
To manage watermarks, the PDFExportParams
class provides the following interface:
addWatermark()
— Adds a new watermark object to the array of watermarks.
watermarks()
— Retrieves all previously added watermarks.
clearWatermarks()
— Removes all watermarks from the object.
Watermark parameters are represented with the Watermark
structure which stores watermark properties:
WatermarkFonts
enumeration.
Watermark watermark;
watermark.text = L"ODA Platform";
watermark.font = Watermark::kTimesRoman; //default value - Times Roman
watermark.color = ODRGB(255, 0, 0); //default value – black
watermark.fontSize = 24; //default value – 48
watermark.opacity = 75; //default value - 50%
WatermarkPosition
enumeration data type
(the following pictures and code fragment illustrate how a watermark looks in each position):
watermark.position = Watermark:: kUpperLeftToLowerRight;
The position of the code fragment is represented in Figure f.
A watermark can also be fit to the page size by setting the corresponding flag in the Watermark
structure.
The picture below shows how the watermark looks when it is fit to the page (depending on the position).
The following code fragment shows how a watermark can be fit to the page as in Figure d:
watermark.color = ODRGB(255, 0, 0);
watermark.opacity = 75;
watermark.text = L"ODA Platform";
watermark.position = Watermark:: kUpperLeftToLowerRight;
and set the scaling option: Font size in this case will be calculated automatically.
watermark.scaleToPage = true;
Note that you can add several watermarks to the PDFExportParams
object as the following code fragment illustrates:
PDFExportParams params;
Watermark watermark;
watermark.font = Watermark::kTimesRoman; //default value - Times Roman
watermark.color = ODRGB(255, 0, 0); //default value – black
watermark.fontSize = 24; //default value – 48
watermark.opacity = 75; //default value - 50%
Set watermark text:
watermark.text = L"Watermark example 1";
watermark.position = Watermark::kUpperRight; //default - left to right in the page center
//Add the first watermark
params.addWatermark(watermark);
//Change the options of the watermark
watermark.color = ODRGB(0, 0, 255);
watermark.opacity = 50;
watermark.text = L"Scaled watermark example";
watermark.position = Watermark:: kUpperLeftToLowerRight;
//set the scaling option: Font size in this case will be calculated automatically.
watermark.scaleToPage = true;
//Add the second watermark:
params.addWatermark(watermark);
The resulting PDF file is shown in the picture below:
In the OdaMfcApp sample application, you can specify watermark options for PDF export using the Export to PDF dialog:
Click Custom Properties to open the additional Export Options dialog:
In the Watermark
section, specify the watermark text, text font, font size, text color, watermark position, and opacity.
Export to PDF Parameters and Flags
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|