Python を使用して PPTX にドラフト透かしを挿入する方法

この段階的なチュートリアルでは、MS PowerPoint に依存せずに **Python を使用して PPTX に下書き透かしを挿入する方法について詳しく説明します。このアプリケーションを使用して、Windows、Linux、または macOS 内の .NET Core および Python がサポートされている環境で、Python を使用して PowerPoint に下書きの透かしを追加することができます。

Python で PowerPoint に機密透かしを追加する手順

  1. プレゼンテーションに透かしテキストを挿入するための .NET 経由の Python 用 Aspose.Slides をインストールする環境をセットアップします
  2. Presentation クラス オブジェクトを使用して透かしを挿入するには、新しいプレゼンテーションを作成するか、既存のプレゼンテーションを読み込みます
  3. プレゼンテーション内のプレゼンテーション Master Slide/s を繰り返します
  4. マスター スライド コレクション内のすべてのスライドに、秘密の透かしテキストを含むオートシェイプを追加します
  5. 図形とテキストのプロパティをフォーマットし、図形にロックを適用して透かしを保護します
  6. 透かし入りのプレゼンテーションをディスクに保存する

前述の手順に従うと、Python を使用して PPTX 内に秘密の透かしを挿入できます。これにより、Presentation クラスのインスタンスを使用して、既存のプレゼンテーションを読み込むか、新しいプレゼンテーションを作成することからプロセスが開始されます。次に、マスター スライド コレクション内のすべてのスライドを繰り返し処理し、下書きの透かしテキスト シェイプをその中に追加します。最後に、auto_shape_lock クラス インスタンスによって公開されるさまざまなロックで形状を保護し、透かし入りのプレゼンテーションをディスクに保存します。

相互運用機能なしで Python を使用して PowerPoint に下書き透かしを追加するコード

from os import system
import aspose.pydrawing as drawing
import aspose.slides as slides
filepath = "C://Slides//"
#Apply the licence for Aspose.Slides
slidesTextWatermarkLicense = slides.License()
slidesTextWatermarkLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic")
# Generate an empty presentation using Presentation class object
with slides.Presentation() as textWatermarkPptxPresentation:
#Iterate through the master slide collection for adding a watermark text
for masterSlide in textWatermarkPptxPresentation.masters:
#Adding a shape to hold the watermark
pptxTextWatermark = masterSlide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE,
textWatermarkPptxPresentation.slide_size.size.width / 2 - 50,
textWatermarkPptxPresentation.slide_size.size.height / 2 - 50,
200, 50)
#Setting the rotation angle and fill type of the shape
pptxTextWatermark.rotation = 325
pptxTextWatermark.fill_format.fill_type = slides.FillType.NO_FILL
#Add the Text frame with watermark text
watermarkTextFrame = pptxTextWatermark.add_text_frame("Confidential Draft")
#set the textual properties of the watermark text
watermarkTextFormat = watermarkTextFrame.paragraphs[0].portions[0].portion_format
watermarkTextFormat.font_bold = slides.NullableBool.TRUE
watermarkTextFormat.font_italic = slides.NullableBool.TRUE
watermarkTextFormat.font_height = 20
watermarkTextFormat.fill_format.fill_type = slides.FillType.SOLID
watermarkTextFormat.fill_format.solid_fill_color.color = drawing.Color.red
#Lock the Pptx watermark shape and make it uneditable in PowerPoint
pptxTextWatermark.auto_shape_lock.text_locked=True
pptxTextWatermark.auto_shape_lock.select_locked = True
pptxTextWatermark.auto_shape_lock.position_locked = True
#Save the presentations with a text watermark on the disk
textWatermarkPptxPresentation.save(filepath + "PresentationWithWatermarkText.pptx", slides.export.SaveFormat.PPTX)
print("Finished")

この例は、PPT および ODP プレゼンテーション形式にも使用でき、単純な API 呼び出しを使用して、Python で PowerPoint に秘密の透かしを追加できます。シェイプ ロック機能は API によって提供される独自の機能であり、MS PowerPoint では使用できません。ロック機能を実装して透かしの形状を保護し、PowerPoint 内であってもそれを変更または削除できないようにすることで、プレゼンテーションの知的財産権を保護できます。

このトピックでは、Python で下書きの透かしを PowerPoint に追加 し、プレゼンテーションを保護する方法を学びました。プレゼンテーション内に HTML コンテンツを追加する方法に興味がある場合は、Python を使用して HTML を PowerPoint に挿入する方法 の記事を参照してください。

 日本語