客户在使用Microsoft PowerPoint软件时最常用的是创建、编辑和保存PPT文件,开发人员使用
Aspose.Slides控件也可以实现Microsoft PowerPoint可以实现的很多功能,一般PPT文件都是由图形、表格、OLE对象、图片、音频视频、文本等元素组成,对于
Aspose.Slides控件来说PPT文件内的每一个元素都可以转换或者变成Shape对象,那么如何保护PPT文档中的图形对象不被选择、移动、调整大小等操作呢,通过控件提供的API,开发人员可以轻松实现该功能,具体可以参考下面的代码:
//Instatiate Presentation class that represents a PPTX file
Presentation pTemplate = new Presentation(path + "RectPicFrame.pptx");//Instatiate Presentation class that represents a PPTX file
Presentation pTemplate = new Presentation("RectPicFrame.pptx");
//ISlide object for accessing the slides in the presentation
ISlide slide = pTemplate.Slides[0];
//IShape object for holding temporary shapes
IShape shape;
//Traversing through all the slides in the presentation
for (int slideCount = 0; slideCount < pTemplate.Slides.Count; slideCount++)
{
slide = pTemplate.Slides[slideCount];
//Travesing through all the shapes in the slides
for (int count = 0; count < slide.Shapes.Count; count++)
{
shape = slide.Shapes[count];
//if shape is autoshape
if (shape is IAutoShape)
{
//Type casting to Auto shape and getting auto shape lock
IAutoShape Ashp = shape as IAutoShape;
IAutoShapeLock AutoShapeLock = Ashp.ShapeLock;
//Applying shapes locks
AutoShapeLock.PositionLocked = true;
AutoShapeLock.SelectLocked = true;
AutoShapeLock.SizeLocked = true;
}
//if shape is group shape
else if (shape is IGroupShape)
{
//Type casting to group shape and getting group shape lock
IGroupShape Group = shape as IGroupShape;
IGroupShapeLock groupShapeLock = Group.ShapeLock;
//Applying shapes locks
groupShapeLock.GroupingLocked = true;
groupShapeLock.PositionLocked = true;
groupShapeLock.SelectLocked = true;
groupShapeLock.SizeLocked = true;
}
//if shape is a connector
else if (shape is IConnector)
{
//Type casting to connector shape and getting connector shape lock
IConnector Conn = shape as IConnector;
IConnectorLock ConnLock = Conn.ShapeLock;
//Applying shapes locks
ConnLock.PositionMove = true;
ConnLock.SelectLocked = true;
ConnLock.SizeLocked = true;
}
//if shape is picture frame
else if (shape is IPictureFrame)
{
//Type casting to pitcture frame shape and getting picture frame shape lock
IPictureFrame Pic = shape as IPictureFrame;
IPictureFrameLock PicLock = Pic.ShapeLock;
//Applying shapes locks
PicLock.PositionLocked = true;
PicLock.SelectLocked = true;
PicLock.SizeLocked = true;
}
}
}
//Saving the presentation file
pTemplate.Save("ProtectedSample.pptx",
Aspose.Slides.Export.SaveFormat.Pptx);