In this tutorial, we will explore how to add Draft Watermark in PPTX using C++. You can insert a confidential watermark in PowerPoint presentation by using easy API interface in C++. You are not restricted to availability of Microsoft PowerPoint or Interop to use this feature and can run this code seamlessly on Windows and Linux platforms.
Steps to Add Draft Watermark in PPTX using C++
- Install Aspose.Slides for C++ from NuGet package Manager tool
- Add reference to Aspose::Slides namespace
- Load PPTX for adding watermark using Presentation Class instance
- Add AutoShape in all Master Slides for adding watermark
- Lock the added watermark shape for protection
- Save watermarked PPTX presentation file
You can easily add confidential watermark in PowerPoint using C++ in few lines of code. This example can also be used for legacy PPT for adding confidential watermark PowerPoint.
Code to Insert Draft Watermark in PPTX using C++
#pragma once | |
#include <iostream> | |
#include <DOM/Presentation.h> | |
#include <DOM/IMasterSlideCollection.h> | |
#include <DOM/IMasterSlide.h> | |
#include <DOM/IShapeCollection.h> | |
#include <DOM/IAutoShape.h> | |
#include <DOM/ShapeType.h> | |
#include <DOM/SlideSizeScaleType.h> | |
#include <DOM/SlideSize.h> | |
#include <DOM/ISlideSize.h> | |
#include <DOM/IFillFormat.h> | |
#include <DOM/IPictureFillFormat.h> | |
#include <DOM/PictureFillMode.h> | |
#include <DOM/ITextFrame.h> | |
#include <DOM/IPortionFormat.h> | |
#include <DOM/IParagraphCollection.h> | |
#include <DOM/IParagraph.h> | |
#include <DOM/IPortionCollection.h> | |
#include <DOM/IPortion.h> | |
#include <DOM/FillType.h> | |
#include <DOM/NullableBool.h> | |
#include <DOM/IColorFormat.h> | |
#include <DOM/AutoShapeLock.h> | |
#include <Export/SaveFormat.h> | |
#include <DOM/IPPImage.h> | |
#include <DOM/IImageCollection.h> | |
#include <DOM/IPictureFrame.h> | |
#include <drawing/Color.h> | |
#include <drawing/Size.h> | |
#include <drawing/size_f.h> | |
#include <system/io/file_mode.h> | |
#include <system/io/file_stream.h> | |
using namespace Aspose::Slides; | |
using namespace System; | |
using namespace System::Drawing; | |
using namespace System::IO; | |
class AddWatermarkEx | |
{ | |
public: | |
static void InsertDraftWatermark() | |
{ | |
// Load the presentation for adding watermark | |
SharedPtr<Presentation> WatermarkPresentation = MakeObject<Presentation>(u"input.pptx"); | |
// Accessing the master slides for adding watermark | |
for (SharedPtr <IMasterSlide> masterSlide : WatermarkPresentation->get_Masters()) | |
{ | |
// Adding a Pptx watermark shape | |
SharedPtr <IAutoShape> PptxWatermark = masterSlide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, | |
WatermarkPresentation->get_SlideSize()->get_Size().get_Width() / 2 - 50, | |
WatermarkPresentation->get_SlideSize()->get_Size().get_Height() / 2 - 50, | |
200, 50); | |
// Set the fille type and rotation angle of the shape | |
PptxWatermark->set_Rotation(325); | |
PptxWatermark->get_FillFormat()->set_FillType(FillType::NoFill); | |
// Adding Textframe with watermark text | |
SharedPtr <ITextFrame> WatermarkText = PptxWatermark->AddTextFrame(u"Confidential Draft"); | |
// Setting text properties of the watermark text | |
SharedPtr <IPortionFormat> WatermarkTextFormat = WatermarkText->get_Paragraphs()->idx_get(0) | |
->get_Portions()->idx_get(0)->get_PortionFormat(); | |
WatermarkTextFormat->set_FontBold(NullableBool::True); | |
WatermarkTextFormat->set_FontItalic(NullableBool::True); | |
WatermarkTextFormat->set_FontHeight(20); | |
WatermarkTextFormat->get_FillFormat()->set_FillType(FillType::Solid); | |
WatermarkTextFormat->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Red()); | |
//Locking Pptx watermarked shape to be uneditable in PowerPoint | |
PptxWatermark->get_AutoShapeLock()->set_TextLocked(true); | |
PptxWatermark->get_AutoShapeLock()->set_SelectLocked(true); | |
PptxWatermark->get_AutoShapeLock()->set_PositionLocked(true); | |
} | |
// Save watermarked PPTX to Disc | |
WatermarkPresentation->Save(u"WatermarkedPresentation.pptx", Export::SaveFormat::Pptx); | |
} | |
}; |
Earlier, we learnt How to Save Slide as SVG in C++. This topic focus on how to insert draft watermark PowerPoint using C++.