Working with slide backgrounds
Leave feedback
On this page
The API allows you to extract information about all slide backgrounds, remove a particular background, and add watermark to all background images.
This sample iterates slides and prints size and byte-length details for each background image.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.presentation as gwc_ppt
load_options = gw.PresentationLoadOptions()
with gw.Watermarker("presentation.pptx", load_options) as watermarker:
content = watermarker.get_content(gwc_ppt.PresentationContent)
for slide in content.slides:
if slide.image_fill_format.background_image is not None:
print(slide.image_fill_format.background_image.width)
print(slide.image_fill_format.background_image.height)
print(len(slide.image_fill_format.background_image.get_bytes()))
This sample clears the background image for a specific slide and saves the updated presentation.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.presentation as gwc_ppt
load_options = gw.PresentationLoadOptions()
with gw.Watermarker("presentation.pptx", load_options) as watermarker:
content = watermarker.get_content(gwc_ppt.PresentationContent)
content.slides[0].image_fill_format.background_image = None
watermarker.save("presentation.pptx")
This sample applies a centered, rotated text watermark to every slide background image in the deck.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.presentation as gwc_ppt
import groupdocs.watermark.watermarks as gww
import groupdocs.watermark.common as gwc
load_options = gw.PresentationLoadOptions()
with gw.Watermarker("presentation.pptx", load_options) as watermarker:
watermark = gww.TextWatermark("Protected image", gww.Font("Arial", 8.0))
watermark.horizontal_alignment = gwc.HorizontalAlignment.CENTER
watermark.vertical_alignment = gwc.VerticalAlignment.CENTER
watermark.rotate_angle = 45
watermark.sizing_type = gww.SizingType.SCALE_TO_PARENT_DIMENSIONS
watermark.scale_factor = 1.0
content = watermarker.get_content(gwc_ppt.PresentationContent)
for slide in content.slides:
if slide.image_fill_format.background_image is not None:
slide.image_fill_format.background_image.add(watermark)
watermarker.save("presentation.pptx")
This sample sets a custom background image and adjusts tiling and transparency options for a specific slide.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.presentation as gwc_ppt
load_options = gw.PresentationLoadOptions()
with gw.Watermarker("presentation.pptx", load_options) as watermarker:
content = watermarker.get_content(gwc_ppt.PresentationContent)
slide = content.slides[0]
with open("background.png", "rb") as f:
slide.image_fill_format.background_image = gwc_ppt.PresentationWatermarkableImage(f.read())
slide.image_fill_format.tile_as_texture = True
slide.image_fill_format.transparency = 0.5
watermarker.save("presentation.pptx")
This sample assigns a background image to a chart and configures its transparency and tiling behavior.
import groupdocs.watermark as gw
import groupdocs.watermark.contents.presentation as gwc_ppt
load_options = gw.PresentationLoadOptions()
with gw.Watermarker("presentation.pptx", load_options) as watermarker:
content = watermarker.get_content(gwc_ppt.PresentationContent)
with open("test.png", "rb") as f:
content.slides[0].charts[0].image_fill_format.background_image = \
gwc_ppt.PresentationWatermarkableImage(f.read())
content.slides[0].charts[0].image_fill_format.transparency = 0.5
content.slides[0].charts[0].image_fill_format.tile_as_texture = True
watermarker.save("presentation.pptx")
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.