Drawings SDK Developer Guide > Working with .dwg Files > Working with Other File Formats > Exporting to Other Formats > Exporting to a PDF File > Export to PDF File Parameters and Flags > Export to PDF using Watermarks
Export to PDF using Watermarks

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:

  • The text of a watermark and its attributes (font name, font size, font color, opacity). Available font names are represented with the 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%
              
            
  • Position on the page that is defined with the WatermarkPosition enumeration data type (the following pictures and code fragment illustrate how a watermark looks in each position):
    • The watermark is located from left to right in the page's center (Figure a).
    • The watermark is located in the upper-left corner of the page (Figure b).
    • The watermark is located in the upper-right corner of the page (Figure c).
    • The watermark is located in the lower-right corner of the page (Figure d).
    • The watermark is located in the lower-left corner of the page (Figure e).
    • The watermark is located from the upper-left corner to the lower-right corner of the page (Figure f).
    • The watermark is located from the lower-left corner to the upper-right corner of the page (Figure g).

              
    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).

  • Figure a) illustrates a watermark fit to the page in its center.
  • Figure b) illustrates a watermark fit to the page in its upper corner (left or right).
  • Figure c) illustrates a watermark fit to the page in its lower corner (left or right).
  • Figure d) illustrates a watermark fit to the page in its lower-left to upper-right corner.

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.

See Also

Export to PDF Parameters and Flags

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.