プレゼンテーションへの保護の適用
Aspose.Slidesの一般的な使用法は、Microsoft PowerPoint 2007 (PPTX) プレゼンテーションを自動化されたワークフローの一部として作成、更新、保存することです。この方法でAspose.Slidesを使用するアプリケーションのユーザーは、出力プレゼンテーションにアクセスできます。それらを編集から保護することは一般的な懸念です。自動生成されたプレゼンテーションが元のフォーマットと内容を保持することが重要です。
この記事では、プレゼンテーションとスライドの構成およびAspose.Slides for C++が保護を適用する方法、次にそれを取り除く方法について説明します。この機能はAspose.Slidesに特有のものであり、執筆時点ではMicrosoft PowerPointにはありません。これは、開発者に対してアプリケーションが作成するプレゼンテーションの使用方法を制御する手段を提供します。
スライドの構成
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); | |
まとめ
Aspose.Slidesは、プレゼンテーション内の形状に保護を適用するためのいくつかのオプションを提供します。特定の形状をロックしたり、プレゼンテーション内のすべての形状をループしてすべてをロックして、実質的にプレゼンテーションをロックすることが可能です。
保護を解除することができるのは、以前に保護をかけたプレゼンテーションには、Aspose.Slides for C++だけです。ロックの値をfalseに設定することで保護を解除します。
関連する記事
- ShapeExクラス。
- BaseShapeLockExクラス。