この簡単なトピックでは、Python を使用して PowerPoint presentation をパスワードで保護する方法について説明します。プレゼンテーションは、透かしの適用、署名の追加、読み取り専用にするなど、さまざまな方法で保護できます。このステップバイステップ ガイドでは、MS PowerPoint に依存せずに、パスワードを使用して Python で PowerPoint プレゼンテーションをセキュリティで保護する方法を紹介します。
Python で PowerPoint プレゼンテーションを保護する手順
- プレゼンテーションを保護するために .NET 経由の Python 用 Aspose.Slides を使用するように環境を構成します
- プロジェクトに aspose.slides 名前空間への参照を追加して、Python でプレゼンテーションをパスワード保護します
- Presentation クラス インスタンスを開始して、既存のプレゼンテーションを読み込むか、新しいプレゼンテーションを作成します
- ProtectionManager クラスの Encrypt メソッドを使用して、プレゼンテーションをパスワードで保護します
- パスワードで保護されたプレゼンテーションをディスクに保存します
上記の単純化された手順により、数行の簡単に理解できるコードを使用して Python で PPTX を保護する ことが保証されます。このプロセスは、環境をセットアップすることから始まります。次に、ディスクからソース プレゼンテーションをロードするか、新しいプレゼンテーションを最初から作成します。プレゼンテーションは、パスワードで保護されたプレゼンテーションとしてディスクに保存する前に、ProtectionManager クラス インスタンスを使用してプレゼンテーションにパスワードを適用することで保護されます。
Python で PowerPoint プレゼンテーションを保護するコード
import aspose.slides as slides | |
srcFilepath = "C://Slides//" | |
# Applying the licence to secure the presentation | |
slidesLicense = slides.License() | |
slidesLicense.set_license(srcFilepath + "Conholdate.Total.Product.Family.lic") | |
# Generate an empty presentation using an instance of the Presentation class object | |
with slides.Presentation(srcFilepath +"NewPresentation.pptx") as presentationSecureObj: | |
#set the password that you want to use to secure the presentation | |
passwordForSecurity = "testpass"; | |
#Encrypt or secure the presentation with the password using the Encrypt method | |
#exposed by the ProtectionManager class | |
presentationSecureObj.protection_manager.encrypt(passwordForSecurity) | |
# Save the password protected presentation on the disk | |
presentationSecureObj.save(srcFilepath + "PasswordProtectedPres.pptx", slides.export.SaveFormat.PPTX) | |
print("Presentation Secured") | |
上記の単純なコードでは、Python を使用して PPTX をパスワードで保護する方法を学びました。この API はパスワード保護だけに限定されているわけではありませんが、簡単な API インターフェイスを使用して Python で PPTX ファイルのロックを解除してロックすることもできます。
このトピックでは、パスワードを適用して PPTX セキュリティを Python に実装することに焦点を当ててきました。プレゼンテーションに画像透かしを追加する方法に興味がある場合は、Pythonを使用してPPTXに画像透かしを追加する方法 の記事を参照してください。