プレゼンテーションへの保護の適用

スライドの構成

PPTXスライドは、自動図形、表、OLEオブジェクト、グループ化された図形、画像フレーム、ビデオフレーム、コネクタ、およびプレゼンテーションを構築するために使用できるさまざまな要素など、多くのコンポーネントで構成されています。Aspose.Slides for Javaでは、スライド上の各要素はShapeオブジェクトに変換されます。言い換えれば、スライド上の各要素はShapeオブジェクトまたはShapeオブジェクトから派生したオブジェクトです。PPTXの構造は複雑であるため、すべての種類の図形に対して一般的なロックを使用できるPPTとは異なり、さまざまな種類の図形タイプに対して異なる種類のロックがあります。BaseShapeLockクラスは、一般的なPPTXロッキングクラスです。Aspose.Slides for JavaでサポートされているPPTXのロックタイプは以下の通りです。

  • AutoShapeLockは自動図形をロックします。
  • ConnectorLockはコネクター図形をロックします。
  • GraphicalObjectLockはグラフィカルオブジェクトをロックします。
  • GroupshapeLockはグループ図形をロックします。
  • PictureFrameLockは画像フレームをロックします。 プレゼンテーションオブジェクト内のすべてのShapeオブジェクトに対して実行されるアクションは、プレゼンテーション全体に適用されます。

保護の適用と解除

保護を適用することにより、プレゼンテーションが編集できなくなります。これは、プレゼンテーションの内容を保護するための便利な手法です。

PPTX図形への保護の適用

Aspose.Slides for Javaは、スライド上の図形を扱うためにShapeクラスを提供します。

前述のように、各図形クラスには保護のための関連する図形ロッククラスがあります。この記事では、NoSelect、NoMove、およびNoResizeロックに焦点を当てています。これらのロックは、図形が選択できない(マウスクリックまたは他の選択方法を通じて)、移動したりサイズを変更したりできないことを保証します。

続くコードサンプルは、プレゼンテーション内のすべての図形タイプに保護を適用します。

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

保護の解除

Aspose.Slides for .NET/Javaを使用して適用された保護は、Aspose.Slides for .NET/Javaを使わなければ解除できません。図形のロックを解除するには、適用されたロックの値をfalseに設定します。以下のコードサンプルは、ロックされたプレゼンテーション内の図形のロックを解除する方法を示しています。

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

まとめ