PPTX
DOCX
XLSX
PDF
ODP
PDF
Adding Watermark via C++
How to add watermark to PDF using C++
Add Watermark with C++ Library
In order to add Watermark to 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 Command
PM> Install-Package Aspose.PDF.Cpp
Add Watermark using C++
You need Aspose.PDF for C++ to try the code in your environment.
- Load the PDF with an instance of Document.
- Create an instance of WatermarkArtifact.
- Set properties of WatermarkArtifact object.
- Add watermark using method Add of Aspose.Pdf.Page.Artifacts collection class.
- Save PDF file
System Requirements
Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit, and Linux 64 bit.
- Development environment like Microsoft Visual Studio.
- Aspose.PDF for C++ DLL referenced in your project.
Add Watermark in PDF - C++.
void GettingWatermarks() {
String _dataDir("C:\\Samples\\");
String inputFileName("watermark.pdf");
String outputFileName("watermark_out.pdf");
auto document = MakeObject<Document>(_dataDir + inputFileName);
auto artifact = MakeObject<WatermarkArtifact>();
auto textState = MakeObject<TextState>();
textState->set_FontSize(72);
textState->set_ForegroundColor(Color::get_Blue());
textState->set_Font(FontRepository::FindFont(u"Courier"));
artifact->SetTextAndState(u"WATERMARK", textState);
artifact->set_ArtifactHorizontalAlignment (HorizontalAlignment::Center);
artifact->set_ArtifactVerticalAlignment (VerticalAlignment::Center);
artifact->set_Rotation(45);
artifact->set_Opacity(0.5);
artifact->set_IsBackground(true);
document->get_Pages()->idx_get(1)->get_Artifacts()->Add(artifact);
document->Save(_dataDir + outputFileName);
}