Aplicar Protección a Presentaciones

Composición de una Diapositiva

Una diapositiva PPTX está compuesta por varios componentes como autoadhesivos, tablas, objetos OLE, formas agrupadas, marcos de imagen, marcos de video, conectores y otros elementos disponibles para construir una presentación. En Aspose.Slides para Java, cada elemento en una diapositiva se convierte en un objeto Shape. En otras palabras, cada elemento en la diapositiva es un objeto Shape o un objeto derivado del objeto Shape. La estructura de PPTX es compleja, por lo que a diferencia de PPT, donde se puede usar un bloqueo genérico para todos los tipos de formas, hay diferentes tipos de bloqueos para diferentes tipos de formas. La clase BaseShapeLock es la clase de bloqueo genérico de PPTX. Los siguientes tipos de bloqueos son compatibles en Aspose.Slides para Java para PPTX.

  • AutoShapeLock bloquea autoadhesivos.
  • ConnectorLock bloquea formas conectores.
  • GraphicalObjectLock bloquea objetos gráficos.
  • GroupshapeLock bloquea formas agrupadas.
  • PictureFrameLock bloquea marcos de imagen. Cualquier acción realizada en todos los objetos Shape en un objeto Presentation se aplica a toda la presentación.

Aplicar y Eliminar Protección

Aplicar protección asegura que una presentación no pueda ser editada. Es una técnica útil para proteger el contenido de una presentación.

Aplicar Protección a Formas PPTX

Aspose.Slides para Java proporciona la clase Shape para manejar una forma en la diapositiva.

Como se mencionó anteriormente, cada clase de forma tiene una clase de bloqueo de forma asociada para protección. Este artículo se centra en los bloqueos NoSelect, NoMove y NoResize. Estos bloqueos aseguran que las formas no puedan ser seleccionadas (a través de clics del mouse u otros métodos de selección), y que no puedan ser movidas o redimensionadas.

Los ejemplos de código que siguen aplican protección a todos los tipos de formas en una presentación.

try {
//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.getSlides().get_Item(0);
//IShape object for holding temporary shapes
IShape shape;
//Traversing through all the slides in the presentation
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++)
{
slide = pTemplate.getSlides().get_Item(slideCount);
//Travesing through all the shapes in the slides
for (int count = 0; count < slide.getShapes().size(); count++)
{
shape = slide.getShapes().get_Item(count);
//if shape is autoshape
if (shape instanceof IAutoShape)
{
//Type casting to Auto shape and getting auto shape lock
IAutoShape Ashp = (IAutoShape)shape;
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock();
//Applying shapes locks
AutoShapeLock.setPositionLocked(true);
AutoShapeLock.setSelectLocked(true);
AutoShapeLock.setSizeLocked(true);
}
//if shape is group shape
else if (shape instanceof IGroupShape)
{
//Type casting to group shape and getting group shape lock
IGroupShape Group = (IGroupShape)shape;
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock();
//Applying shapes locks
groupShapeLock.setGroupingLocked(true);
groupShapeLock.setPositionLocked(true);
groupShapeLock.setSelectLocked(true);
groupShapeLock.setSizeLocked(true);
}
//if shape is a connector
else if (shape instanceof IConnector)
{
//Type casting to connector shape and getting connector shape lock
IConnector Conn = (IConnector)shape;
IConnectorLock ConnLock = Conn.getShapeLock();
//Applying shapes locks
ConnLock.setPositionMove(true);
ConnLock.setSelectLocked(true);
ConnLock.setSizeLocked(true);
}
//if shape is picture frame
else if (shape instanceof IPictureFrame)
{
//Type casting to pitcture frame shape and getting picture frame shape lock
IPictureFrame Pic = (IPictureFrame)shape;
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock();
//Applying shapes locks
PicLock.setPositionLocked(true);
PicLock.setSelectLocked(true);
PicLock.setSizeLocked(true);
}
}
}
//Saving the presentation file
pTemplate.save("ProtectedSample.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}

Eliminar Protección

La protección aplicada usando Aspose.Slides para .NET/Java solo se puede eliminar con Aspose.Slides para .NET/Java. Para desbloquear una forma, establece el valor del bloqueo aplicado en falso. El ejemplo de código que sigue muestra cómo desbloquear formas en una presentación bloqueada.

try {
//Instatiate Presentation class that represents a PPTX file
Presentation pTemplate = new Presentation("ProtectedSample.pptx");
//ISlide object for accessing the slides in the presentation
ISlide slide = pTemplate.getSlides().get_Item(0);
//IShape object for holding temporary shapes
IShape shape;
//Traversing through all the slides in the presentation
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++)
{
slide = pTemplate.getSlides().get_Item(slideCount);
//Travesing through all the shapes in the slides
for (int count = 0; count < slide.getShapes().size(); count++)
{
shape = slide.getShapes().get_Item(count);
//if shape is autoshape
if (shape instanceof IAutoShape)
{
//Type casting to Auto shape and getting auto shape lock
IAutoShape Ashp = (IAutoShape)shape;
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock();
//Applying shapes locks
AutoShapeLock.setPositionLocked(false);
AutoShapeLock.setSelectLocked(false);
AutoShapeLock.setSizeLocked(false);
}
//if shape is group shape
else if (shape instanceof IGroupShape)
{
//Type casting to group shape and getting group shape lock
IGroupShape Group = (IGroupShape)shape;
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock();
//Applying shapes locks
groupShapeLock.setGroupingLocked(false);
groupShapeLock.setPositionLocked(false);
groupShapeLock.setSelectLocked(false);
groupShapeLock.setSizeLocked(false);
}
//if shape is a connector
else if (shape instanceof IConnector)
{
//Type casting to connector shape and getting connector shape lock
IConnector Conn = (IConnector)shape;
IConnectorLock ConnLock = Conn.getShapeLock();
//Applying shapes locks
ConnLock.setPositionMove(false);
ConnLock.setSelectLocked(false);
ConnLock.setSizeLocked(false);
}
//if shape is picture frame
else if (shape instanceof IPictureFrame)
{
//Type casting to pitcture frame shape and getting picture frame shape lock
IPictureFrame Pic = (IPictureFrame)shape;
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock();
//Applying shapes locks
PicLock.setPositionLocked(false);
PicLock.setSelectLocked(false);
PicLock.setSizeLocked(false);
}
}
}
//Saving the presentation file
pTemplate.save("RemoveProtectionSample.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}

Resumen