Aplicar Protección a la Presentación

Composición de una Diapositiva

Una diapositiva PPTX se compone de varios componentes como formas automáticas, tablas, objetos OLE, formas agrupadas, marcos de imágenes, marcos de video, conectores y otros diversos elementos disponibles para construir una presentación. En Aspose.Slides para PHP a través de 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 PHP a través de Java para PPTX.

  • AutoShapeLock bloquea formas automáticas.
  • ConnectorLock bloquea formas de conector.
  • GraphicalObjectLock bloquea objetos gráficos.
  • GroupshapeLock bloquea formas de grupo.
  • PictureFrameLock bloquea marcos de imágenes. Cualquier acción realizada en todos los objetos Shape en un objeto Presentación se aplica a toda la presentación.

Aplicando y Eliminando 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.

Aplicando Protección a Formas PPTX

Aspose.Slides para PHP a través de 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 no pueden 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) {
}

Eliminando Protección

La protección aplicada utilizando Aspose.Slides para .NET/Java solo puede ser eliminada con Aspose.Slides para .NET/Java. Para desbloquear una forma, establezca 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