Get Watermark from PDF via C++

Get watermark from PDF document. Use Aspose.PDF for C++ to modify PDF files programmatically

Get Watermark from PDF File Using C++ Library

In order to get Watermark from PDF File, we’ll use Aspose.PDF for C++ API, which is a feature-rich, powerful, and easy-to-use document manipulation API for the C++ platform. Open NuGet package manager, search for Aspose.PDF.Cpp and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Get Watermark via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Create an instance of WatermarkArtifact.
  3. Set properties of WatermarkArtifact object.
  4. Add watermark using method Add of Aspose.Pdf.Page.Artifacts collection class.
  5. Save PDF file

Get Watermark from PDF - C++


    // Read a PDF file
    doc = MakeObject<Document>(u"1.pdf");

    // Read artifacts from first page
    artifacts = doc->get_Pages()->idx_get(1)->get_Artifacts();

    // Check if there is a watermark
    artifact = artifacts->idx_get(1);
    if (artifact != nullptr && artifact->get_Subtype() == Aspose::Pdf::Artifact::ArtifactSubtype::Watermark)

    // Get image from watermark artifact
    fs = System::IO::File::OpenWrite(u"get_watermark.jpg");
    artifact->get_Image()->Save(fs);