Adding Watermarks and Backgrounds
The doc object’s addWatermarkFromText and addWatermarkFromFile methods create watermarks within a document, and place them in optional content groups (OCGs).The addWatermarkFromFile method adds a page as a watermark to the specified
pages in the document. The example below adds the first page of watermark.pdf as a watermark to the center of all pages within the current document: this.addWatermarkFromFile(“/C/watermark.pdf”); In the next example, the addWatermarkFromFile method is used to add the second page of watermark.pdf as a watermark to the first 10 pages of the current document. It is
rotated counterclockwise by 45 degrees, and positioned one inch down and two inches over from the top left corner of each page:
this.addWatermarkFromFile({
cDIPath: "/C/watermark.pdf",
nSourcePage: 1,
nEnd: 9,
nHorizAlign: 0,
nVertAlign: 0,
nHorizValue: 144,
nVertValue: -72,
nRotation: 45
});
It is also possible to use the addWatermarkFromText method to create watermarks. In this next example, the word Confidential is placed in the center of all the pages of the document, and its font helps it stand out:
this.addWatermarkFromText(
"Confidential",
0,
font.Helv,
24,
color.red
);