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

スライドの構成

PPTXスライドは、自動形状、表、OLEオブジェクト、グループ化された形状、画像フレーム、ビデオフレーム、コネクタ、およびプレゼンテーションを構築するために使用できるさまざまな他の要素のような多くのコンポーネントで構成されています。

Aspose.Slides for C++では、スライド上の各要素はShapeオブジェクトに変換されます。言い換えれば、スライド上の各要素はShapeオブジェクトであるか、Shapeオブジェクトから派生したオブジェクトです。

PPTXの構造は複雑であるため、すべての種類の形状に一般的なロックを使用できるPPTとは異なり、異なる形状タイプに異なるロックのタイプがあります。BaseShapeLockクラスは一般的なPPTXロッククラスです。Aspose.Slides for C++でサポートされているPPTXのロックの種類は以下の通りです。

  • AutoShapeLockは自動形状をロックします。
  • ConnectorLockはコネクタ形状をロックします。
  • GraphicalObjectLockはグラフィカルオブジェクトをロックします。
  • GroupshapeLockはグループ形状をロックします。
  • PictureFrameLockは画像フレームをロックします。

プレゼンテーションオブジェクト内のすべてのShapeオブジェクトに対して実行されるすべてのアクションは、プレゼンテーション全体に適用されます。

保護の適用と削除

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

PPTX形状への保護の適用

Aspose.Slides for C++は、スライド上の形状を処理するためのShapeクラスを提供します。

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

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

// The path to the documents directory.
const String templatePath = u"../templates/RectPicFrame.pptx";
const String outPath = u"../out/ProtectedSample.pptx";
//Instatiate Presentation class that represents a PPTX
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
//ISlide object for accessing the slides in the presentation
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
//IShape object for holding temporary shapes
SharedPtr<IShape> shape;
//Traversing through all the slides in the presentation
for (int slideCount = 0; slideCount < pres->get_Slides()->get_Count(); slideCount++)
{
slide = pres->get_Slides()->idx_get(slideCount);
//Travesing through all the shapes in the slides
for (int count = 0; count < slide->get_Shapes()->get_Count(); count++)
{
shape = slide->get_Shapes()->idx_get(count);
if (System::ObjectExt::Is<IAutoShape>(shape)) {
//Type casting to Auto shape and getting auto shape lock
SharedPtr<IAutoShape> aShp = DynamicCast<Aspose::Slides::IAutoShape>(shape);
SharedPtr<IAutoShapeLock> autoShapeLock = DynamicCast<Aspose::Slides::IAutoShapeLock>(aShp->get_ShapeLock());
//Applying shapes locks
autoShapeLock->set_PositionLocked(true);
autoShapeLock->set_SelectLocked(true);
autoShapeLock->set_SizeLocked(true);
}
//if shape is group shape
else if (System::ObjectExt::Is<IGroupShape>(shape)) {
//Type casting to group shape and getting group shape lock
SharedPtr<IGroupShape> group = DynamicCast<Aspose::Slides::IGroupShape>(shape);
SharedPtr<IGroupShapeLock> groupShapeLock = DynamicCast<Aspose::Slides::IGroupShapeLock>(group->get_ShapeLock());
//Applying shapes locks
groupShapeLock->set_GroupingLocked(true);
groupShapeLock->set_PositionLocked(true);
groupShapeLock->set_SelectLocked(true);
groupShapeLock->set_SizeLocked(true);
}
//if shape is a connector
else if (System::ObjectExt::Is<IConnector>(shape)) {
//Type casting to connector shape and getting connector shape lock
SharedPtr<IConnector> conn = DynamicCast<Aspose::Slides::IConnector>(shape);
SharedPtr<IConnectorLock> connLock = DynamicCast<Aspose::Slides::IConnectorLock>(conn->get_ShapeLock());
//Applying shapes locks
connLock->set_PositionMove(true);
connLock->set_SelectLocked(true);
connLock->set_SizeLocked(true);
}
//if shape is picture frame
else if (System::ObjectExt::Is<IPictureFrame>(shape)) {
//Type casting to pitcture frame shape and getting picture frame shape lock
SharedPtr<IPictureFrame> pic = DynamicCast<Aspose::Slides::IPictureFrame>(shape);
SharedPtr<IPictureFrameLock> picLock = DynamicCast<Aspose::Slides::IPictureFrameLock>(pic->get_ShapeLock());
//Applying shapes locks
picLock->set_PositionLocked(true);
picLock->set_SelectLocked(true);
picLock->set_SizeLocked(true);
}
}
}
//Saving the presentation file
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

保護の削除

Aspose.Slides for C++を使用して適用された保護は、Aspose.Slides for C++でのみ削除できます。形状のロックを解除するには、適用されたロックの値をfalseに設定します。次に示すコードサンプルは、ロックされたプレゼンテーション内の形状をロック解除する方法を示しています。

// The path to the documents directory.
const String templatePath = u"../templates/ProtectedSample.pptx";
const String outPath = u"../out/RemoveProtectionSample.pptx";
//Instatiate Presentation class that represents a PPTX
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
//ISlide object for accessing the slides in the presentation
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
//IShape object for holding temporary shapes
SharedPtr<IShape> shape;
//Traversing through all the slides in the presentation
for (int slideCount = 0; slideCount < pres->get_Slides()->get_Count(); slideCount++)
{
slide = pres->get_Slides()->idx_get(slideCount);
//Travesing through all the shapes in the slides
for (int count = 0; count < slide->get_Shapes()->get_Count(); count++)
{
shape = slide->get_Shapes()->idx_get(count);
if (System::ObjectExt::Is<IAutoShape>(shape)) {
//Type casting to Auto shape and getting auto shape lock
SharedPtr<IAutoShape> aShp = DynamicCast<Aspose::Slides::IAutoShape>(shape);
SharedPtr<IAutoShapeLock> autoShapeLock = DynamicCast<Aspose::Slides::IAutoShapeLock>(aShp->get_ShapeLock());
//Applying shapes locks
autoShapeLock->set_PositionLocked(false);
autoShapeLock->set_SelectLocked(false);
autoShapeLock->set_SizeLocked(false);
}
//if shape is group shape
else if (System::ObjectExt::Is<IGroupShape>(shape)) {
//Type casting to group shape and getting group shape lock
SharedPtr<IGroupShape> group = DynamicCast<Aspose::Slides::IGroupShape>(shape);
SharedPtr<IGroupShapeLock> groupShapeLock = DynamicCast<Aspose::Slides::IGroupShapeLock>(group->get_ShapeLock());
//Applying shapes locks
groupShapeLock->set_GroupingLocked(false);
groupShapeLock->set_PositionLocked(false);
groupShapeLock->set_SelectLocked(false);
groupShapeLock->set_SizeLocked(false);
}
//if shape is a connector
else if (System::ObjectExt::Is<IConnector>(shape)) {
//Type casting to connector shape and getting connector shape lock
SharedPtr<IConnector> conn = DynamicCast<Aspose::Slides::IConnector>(shape);
SharedPtr<IConnectorLock> connLock = DynamicCast<Aspose::Slides::IConnectorLock>(conn->get_ShapeLock());
//Applying shapes locks
connLock->set_PositionMove(false);
connLock->set_SelectLocked(false);
connLock->set_SizeLocked(false);
}
//if shape is picture frame
else if (System::ObjectExt::Is<IPictureFrame>(shape)) {
//Type casting to pitcture frame shape and getting picture frame shape lock
SharedPtr<IPictureFrame> pic = DynamicCast<Aspose::Slides::IPictureFrame>(shape);
SharedPtr<IPictureFrameLock> picLock = DynamicCast<Aspose::Slides::IPictureFrameLock>(pic->get_ShapeLock());
//Applying shapes locks
picLock->set_PositionLocked(false);
picLock->set_SelectLocked(false);
picLock->set_SizeLocked(false);
}
}
}
//Saving the presentation file
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

まとめ

関連する記事