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 格式保存结果