Created
October 21, 2020 20:42
-
-
Save aspose-com-gists/da4488531d68cbaad746340b8dd19dfa to your computer and use it in GitHub Desktop.
Add, Insert, Delete or Remove Text/Image Watermark in Word (DOC/DOCX) 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
// Load input word document | |
auto doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); | |
// Initialize and set properties for image watermark | |
auto options = System::MakeObject<ImageWatermarkOptions>(); | |
options->set_Scale(5); | |
options->set_IsWashout(false); | |
// Load image by specifying path | |
doc->get_Watermark()->SetImage(System::Drawing::Image::FromFile(inputDataDir + u"Watermark.png"), options); | |
// Save output word document | |
auto outputPath = outputDataDir + u"AddImageWatermark.docx"; | |
doc->Save(outputPath); |
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
// Load input word document | |
auto doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); | |
// Set different properties for text watermark | |
auto options = System::MakeObject<TextWatermarkOptions>(); | |
options->set_FontFamily(u"Arial"); | |
options->set_FontSize(36); | |
options->set_Color(System::Drawing::Color::get_Black()); | |
options->set_Layout(WatermarkLayout::Horizontal); | |
options->set_IsSemitrasparent(false); | |
// Set text for the watermark | |
doc->get_Watermark()->SetText(u"Test", options); | |
auto outputPath = outputDataDir + u"AddTextWatermark.docx"; | |
doc->Save(outputPath); |
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
// Load input word document | |
auto doc = System::MakeObject<Document>(inputDataDir + u"TextWatermark.docx"); | |
// Iterate through text watermark | |
if (doc->get_Watermark()->get_Type() == WatermarkType::Text) | |
{ | |
// Remove the watermark | |
doc->get_Watermark()->Remove(); | |
} | |
// Save output word document | |
auto outputPath = outputDataDir + u"RemoveWatermark.docx"; | |
doc->Save(outputPath); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment