wood burning stoves 2.0*
The moose likes Blatant Advertising and the fly likes Applying Protection on a PPTX Presentation Using Aspose.Slides Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Other » Blatant Advertising
Bookmark "Applying Protection on a PPTX Presentation Using Aspose.Slides" Watch "Applying Protection on a PPTX Presentation Using Aspose.Slides" New topic
Author

Applying Protection on a PPTX Presentation Using Aspose.Slides

sherazam khan
Ranch Hand

Joined: Mar 10, 2010
Posts: 302
This technical tip shows how to apply protection on a presentation. Aspose.Slides for Java is supposed to create, update and write the PowerPoint 2007 (PPTX) Presentations in an automated way so that an end user will be receiving the auto-generated PowerPoint Presentations. Even MS PowerPoint does not provide such security features.
Aspose.Slides for Java provides the ShapeEx class to handle a shape on the slide. As discussed earlier that each shape class has associated shape lock class for protection. There are various types of locks associated with the shapes but in the article we have used NoSelect, NoMove and NoResize locks. That is, the shape cannot be selected through mouse click or any other type of user actions like moving or resizing cannot be performed on it. The following lines of code can be used to protect the all allowed shapes types in the presentation.

Applying protection on a Pptx presentation shapes

[Java]

//Open the desired presentation
PresentationEx pTemplate = new PresentationEx("D:\\pres.pptx");

//Slide object for holding temporary slides
SlideEx slide;

//Shape object for holding temporary shapes
ShapeEx shape;

//Traversing through all the slides in presentation
for(int slCount=0;slCount<pTemplate.getSlides().size();slCount++)
{
//Accessing the slide in the presentation
slide = pTemplate.getSlides().get(slCount);

//Traversing through all the shapes in the slides
for (int count = 0; count >< slide.getShapes().size(); count++)
{
shape = slide.getShapes().get(count);

//if shape is Autoshape
if (shape instanceof AutoShapeEx)
{
//Type casting to Auto shape and getting auto shape lock
AutoShapeEx Ashp = (AutoShapeEx)shape;
AutoShapeLockEx AutoShapeLock = Ashp.getShapeLock();

//Applying shapes locks
AutoShapeLock.setNoMove(true);
AutoShapeLock.setNoSelect(true);
AutoShapeLock.setNoResize(true);
}

//if shape is group shape
else if (shape instanceof GroupShapeEx)
{
//Type casting to group shape and getting group shape lock
GroupShapeEx Group = (GroupShapeEx)shape;
GroupShapeLockEx groupShapeLock = Group.getShapeLock();

//Applying shapes locks
groupShapeLock.setNoMove(true);
groupShapeLock.setNoSelect(true);
groupShapeLock.setNoResize(true);
}

//if shape is Connector shape
else if (shape instanceof ConnectorEx )
{
//Type casting to connector shape and getting connector shape lock
ConnectorEx Conn = (ConnectorEx)shape;
ConnectorLockEx ConnLock = Conn.getShapeLock();

//Applying shapes locks
ConnLock.setNoMove(true);
ConnLock.setNoSelect(true);
ConnLock.setNoResize(true);
}

//if shape is picture frame
else if (shape instanceof PictureFrameEx)
{
//Type casting to picture frame shape and getting picture frame shape lock
PictureFrameEx Pic = (PictureFrameEx)shape;
PictureFrameLockEx PicLock = Pic.getShapeLock();

//Applying shapes locks
PicLock.setNoMove(true);
PicLock.setNoSelect(true);
PicLock.setNoResize(true);
}
}
}

//Saving the presentation file
pTemplate.write("D:\\locked.pptx");


Removing protection on PPTX presentation shapes

Once any type of protection is applied on the presentation through Aspose.Slides for Java, it can only be removed through Aspose.Slides for Java because MS PowerPoint cannot remove this protection. For this purpose, we need to set the value of applied lock to false. The following code can be used to achieve

[Java]

//Open the desired presentation
PresentationEx pTemplate = new PresentationEx("D:\\locked.pptx");

//Slide object for holding temporary slides
SlideEx slide;

//Shape object for holding temporary shapes
ShapeEx shape;

//Traversing through all the slides in presentation
for(int slCount=0;slCount<pTemplate.getSlides().size();slCount++)
{
//Accessing the slide in the presentation
slide = pTemplate.getSlides().get(slCount);

//Traversing through all the shapes in the slides
for (int count = 0; count >< slide.getShapes().size(); count++)
{
shape = slide.getShapes().get(count);

//if shape is Autoshape
if (shape instanceof AutoShapeEx)
{
//Type casting to Auto shape and getting auto shape lock
AutoShapeEx Ashp = (AutoShapeEx)shape;
AutoShapeLockEx AutoShapeLock = Ashp.getShapeLock();

//Applying shapes locks
AutoShapeLock.setNoMove(false);
AutoShapeLock.setNoSelect(false);
AutoShapeLock.setNoResize(false);
}

//if shape is group shape
else if (shape instanceof GroupShapeEx)
{
//Type casting to group shape and getting group shape lock
GroupShapeEx Group = (GroupShapeEx)shape;
GroupShapeLockEx groupShapeLock = Group.getShapeLock();

//Applying shapes locks
groupShapeLock.setNoMove(false);
groupShapeLock.setNoSelect(false);
groupShapeLock.setNoResize(false);
}

//if shape is Connector shape
else if (shape instanceof ConnectorEx )
{
//Type casting to connector shape and getting connector shape lock
ConnectorEx Conn = (ConnectorEx)shape;
ConnectorLockEx ConnLock = Conn.getShapeLock();

//Applying shapes locks
ConnLock.setNoMove(false);
ConnLock.setNoSelect(false);
ConnLock.setNoResize(false);
}

//if shape is picture frame
else if (shape instanceof PictureFrameEx)
{
//Type casting to picture frame shape and getting picture frame shape lock
PictureFrameEx Pic = (PictureFrameEx)shape;
PictureFrameLockEx PicLock = Pic.getShapeLock();

//Applying shapes locks
PicLock.setNoMove(false);
PicLock.setNoSelect(false);
PicLock.setNoResize(false);
}
}
}

//Saving the presentation file
pTemplate.write("D:\\unlocked.pptx");


Overview: Aspose.Slides for Java

Aspose.Slides is a Java component to create, read, write and modify a PowerPoint document without using Microsoft PowerPoint. It supports PHP applications and provides all advanced features for managing presentations, slides, shapes, tables and supports PPT, POT, POS PowerPoint formats. Now you can add, access, copy, clone, edit and delete slides in your presentations. It also supports audio & video frames, adding pictures, text frames and saving presentations as streams or SVG format.

More about Aspose.Slides for Java

- Homepage of Aspose.Slides for Java: http://www.aspose.com/categories/java-components/aspose.slides-for-java/default.aspx

- Read more technical tips by Aspose.Slides for Java: http://www.aspose.com/documentation/java-components/aspose.slides-for-java/index.html

- Download Aspose.Slides for Java: http://www.aspose.com/community/files/72/java-components/aspose.slides-for-java/default.aspx

Contact Information
Aspose Pty Ltd,
Suite 163, 79 Longueville Road
Lane Cove, NSW, 2066
Australia
http://www.aspose.com/
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465l
 
 
subject: Applying Protection on a PPTX Presentation Using Aspose.Slides