Last active
June 2, 2021 12:55
-
-
Save aspose-com-gists/5942aff54803299fd880ed7342db2ccf to your computer and use it in GitHub Desktop.
Insert or Delete Text/Image Watermark in a PDF File using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Insert or Delete Text/Image Watermark in a PDF File using C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open the source PDF document | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf"); | |
// Create an instance of the ImageStamp class | |
System::SharedPtr<ImageStamp> imageStamp = MakeObject<ImageStamp>(u"SourceDirectory\\aspose.png"); | |
// Set the position of the watermark | |
imageStamp->set_XIndent(150); | |
imageStamp->set_YIndent(350); | |
// Set other properties | |
imageStamp->set_Height(100); | |
imageStamp->set_Width(300); | |
imageStamp->set_RotateAngle(45); | |
imageStamp->set_Opacity(0.4); | |
imageStamp->setStampId(12345678); | |
// Add watermark to the PDF page | |
pdfDocument->get_Pages()->idx_get(1)->AddStamp(imageStamp); | |
// Save the PDF file | |
pdfDocument->Save(u"OutputDirectory\\Image-Watermark-Out.pdf", SaveFormat::Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open the source PDF document | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf"); | |
// Create an instance of the TextStamp class | |
System::SharedPtr<TextStamp> textStamp = MakeObject<TextStamp>(u"CONFIDENTIAL"); | |
// Set the position of the watermark | |
textStamp->set_XIndent(70); | |
textStamp->set_YIndent(300); | |
// Set text properties | |
textStamp->get_TextState()->set_Font(FontRepository::FindFont(u"Arial")); | |
textStamp->get_TextState()->set_FontSize(72.0F); | |
textStamp->get_TextState()->set_ForegroundColor(Aspose::Pdf::Color::get_Red()); | |
textStamp->set_Opacity(0.4); | |
textStamp->set_RotateAngle(45); | |
textStamp->setStampId(123456); | |
// Add watermark to the PDF page | |
pdfDocument->get_Pages()->idx_get(1)->AddStamp(textStamp); | |
// Save the PDF file | |
pdfDocument->Save(u"OutputDirectory\\Text-Watermark-Out.pdf", SaveFormat::Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of the PdfContentEditor class | |
System::SharedPtr<PdfContentEditor> contentEditor = MakeObject<PdfContentEditor>(); | |
// Open the PDF file containing the watermark | |
contentEditor->BindPdf(u"SourceDirectory\\SampleImageWatermark.pdf"); | |
// Delete watermark by id | |
contentEditor->DeleteStampById(12345678); | |
// Save the PDF file | |
pdfDocument->Save(u"OutputDirectory\\Remove-Watermark-Out.pdf", SaveFormat::Pdf); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment