Remove Watermark from PDF via C++

Delete watermark from PDF document using Aspose.PDF for C++ Library

Delete Watermark from PDF File Using C++ Library

In order to delete 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

Remove 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

Delete 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();

    // If first artifact is a watermark, remove it
    artifact = artifacts->idx_get(1);
    if (artifact != nullptr && artifact->get_Subtype() == Aspose::Pdf::Artifact::ArtifactSubtype::Watermark)
        artifacts->Delete(artifact);

    // save result pdf to file
    doc->Save(u"remove_watermark.pdf", SaveFormat::Pdf);