Add watermark to a PDF programmatically

This article guides developers on programmatically adding watermarks to PDFs, useful for labeling and protecting documents. Watermarks can be applied individually to specific pages or ranges and can be added using the user interface, C++ code, or JavaScript APIs.

Add a watermark using C++

There are two APIs that the Acrobat SDK offers for adding a watermark using C++.

  • void PDDocAddWatermarkFromText ()

    This API adds a text-based watermark to a page range in the given document.

    API syntax:

                void PDDocAddWatermarkFromText (

                        PDDoc pdDoc,
                        PDDocWatermarkTextParamsRec* pTextParams,
                        PDDocAddWatermarkParamsRec* pParams
                        );

    Parameter details:

    •  PdDoc is the document onto which the watermark will be added.
    • TextParams is the structure describing the text-based watermark to be added.
    • pParams is the structure specifying how the watermark should be added to the document.

     

  • void PDDocAddWatermarkFromPDPage ()

    This API adds pdPage as a watermark to a page range in the document.

    API syntax :

    void PDDocAddWatermarkFromPDPage (
                        PDDoc pdDoc,
                        PDPage pdPage,
                        PDDocAddWatermarkParamsRec* pParams
                );

    Parameter details:

    •  pdDoc is the document onto which the watermark will be added.
    • pdPage is the page to be added as a watermark.
    • pParams is the structure specifying how the watermark should be added to the document.

Add a watermark using JavaScript

  • addWatermarkFromText()

    This API adds the given text as a watermark to the specified pages in the document. For example, the code below adds “Confidential” as a watermark to the center of all pages of the current document.

    this.addWatermarkFromText(“Confidential”, 0, font.Helv, 24, color.red);

     

  • addWatermarkFromFile()

    This API adds a page as a watermark to the specified pages in the document. For example, the following code adds the first page of 'watermark.pdf' as a watermark to the center of all pages of the current document.

    this.addWatermarkFromFile(“/C/temp/watermark.pdf”);

    For a detailed explanation of all parameters, view the API References available within the documentation folder of the Acrobat SDK.

More like this

Obțineți ajutor mai rapid și mai ușor

Utilizator nou?