PPT
PPTX
ODP
POT
ppsx
PPTX
使用 Python 將水印添加到 PPTX 演示文稿
構建您自己的 Python 應用程序,以使用服務器端 API 將文本或圖像水印插入到 PPT、PPTX 或 ODP 演示文稿中。
通過 Python 為 PPTX 演示文稿添加水印
使用 Aspose.Slides for Python via .NET,您可以為 PPTX 演示文稿添加水印。水印是任何演示文稿的重要組成部分。它們用於保護演示文稿的內容不被複製或未經許可使用。水印是放置在演示文稿頂部的可見或不可見的圖像或文本。它可用於識別演示文稿的所有者並防止未經授權的使用。水印也可用於為演示文稿增添專業氣息並使其看起來更加精美。
使用 Python 將文本水印添加到 PPTX
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as pres:
master = pres.masters[0]
watermarkShape = master.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 0, 0, 100, 100)
watermarkTextFrame = watermarkShape.add_text_frame("Watermark")
# Lock Watermark from Editing
watermarkShape.shape_lock.select_locked = True
watermarkShape.shape_lock.size_locked = True
watermarkShape.shape_lock.text_locked = True
watermarkShape.shape_lock.position_locked = True
watermarkShape.shape_lock.grouping_locked = True
# Set Text Watermark Transparency
watermarkPortion = watermarkTextFrame.paragraphs[0].portions[0]
watermarkPortion.portion_format.fill_format.fill_type = slides.FillType.SOLID
watermarkPortion.portion_format.fill_format.solid_fill_color.color = draw.Color.from_argb(150, 200, 200, 200)
# Set Font Size of Text Watermark
watermarkPortion.portion_format.font_height = 16
pres.save("watermark.pptx", slides.export.SaveFormat.PPTX)
使用 Python 將圖像水印添加到 PPTX 演示文稿
import aspose.slides as slides
with slides.Presentation() as presentation:
with open("image1.png", "rb") as fs:
data = fs.read()
image = presentation.images.add_image(data)
master = presentation.masters[0]
watermarkShape = master.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 0, 0, image.width, image.height)
watermarkShape.fill_format.fill_type = slides.FillType.PICTURE
watermarkShape.fill_format.picture_fill_format.picture.image = image
watermarkShape.fill_format.picture_fill_format.picture_fill_mode = slides.PictureFillMode.STRETCH
presentation.save("watermark2.pptx", slides.export.SaveFormat.PPTX)
如何通過 Python 為 PPTX 添加水印
這些是將文本水印添加到 PPTX 文件的步驟。
使用 Presentation 實例加載 PPTX
選擇主演示文稿
使用 AddAutoShape 方法添加形狀類型
使用 AddTextFrame 方法添加水印文本
以 PPTX 格式保存結果