Anwendung von Schutz auf Präsentationen

Zusammensetzung einer Folie

Eine PPTX-Folie setzt sich aus einer Anzahl von Komponenten zusammen, wie Autoshapes, Tabellen, OLE-Objekten, gruppierten Formen, Bildrahmen, Videorahmen, Verbindern und den verschiedenen anderen Elementen, die zum Aufbau einer Präsentation verfügbar sind. In Aspose.Slides für PHP über Java wird jedes Element auf einer Folie in ein Shape-Objekt umgewandelt. Mit anderen Worten, jedes Element auf der Folie ist entweder ein Shape-Objekt oder ein Objekt, das von dem Shape-Objekt abgeleitet ist. Die Struktur von PPTX ist komplex, sodass im Gegensatz zu PPT, wo ein generischer Sperrcode für alle Arten von Formen verwendet werden kann, unterschiedliche Arten von Sperren für unterschiedliche Formtypen existieren. Die BaseShapeLock-Klasse ist die generische PPTX-Sperrklasse. Die folgenden Sperrtypen werden in Aspose.Slides für PHP über Java für PPTX unterstützt.

  • AutoShapeLock sperrt Autoshapes.
  • ConnectorLock sperrt Verbindungsformen.
  • GraphicalObjectLock sperrt grafische Objekte.
  • GroupshapeLock sperrt Gruppenkörper.
  • PictureFrameLock sperrt Bildrahmen. Jede Aktion, die auf allen Shape-Objekten in einem Präsentationsobjekt durchgeführt wird, wird auf die gesamte Präsentation angewendet.

Anwenden und Entfernen von Schutz

Schutz zugewiesen确保确保 dass eine Präsentation nicht bearbeitet werden kann. Es ist eine nützliche Technik, um den Inhalt einer Präsentation zu schützen.

Anwendung von Schutz auf PPTX Formen

Aspose.Slides für PHP über Java bietet die Shape-Klasse, um eine Form auf der Folie zu handhaben.

Wie bereits erwähnt, hat jede Formklasse eine zugehörige Form-Sperrklasse zum Schutz. Dieser Artikel konzentriert sich auf die NoSelect-, NoMove- und NoResize-Sperren. Diese Sperren stellen sicher, dass Formen nicht ausgewählt werden können (durch Mausklicks oder andere Auswahlmethoden) und nicht bewegt oder skaliert werden können.

Die folgenden Codebeispiele wenden Schutz auf alle Formtypen in einer Präsentation an.

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) {
}

Entfernen des Schutzes

Der mit Aspose.Slides für .NET/Java angewandte Schutz kann nur mit Aspose.Slides für .NET/Java entfernt werden. Um eine Form zu entsperren, setzen Sie den Wert der angewandten Sperre auf falsch. Das folgende Codebeispiel zeigt, wie Sie Formen in einer gesperrten Präsentation entsperren können.

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) {
}

Zusammenfassung