Python에서 PowerPoint PPT에 워터마크 추가

워터마크는 일반적으로 문서를 보호하거나 소유권을 지정하는 데 사용됩니다. 반면에 원고, 초안 등 문서의 상태를 표시하는 데 사용됩니다. 이 기사에서는 PowerPoint 프레젠테이션에 워터마크를 삽입하는 방법을 보여줍니다. Python에서 PowerPoint PPT 슬라이드에 텍스트 또는 이미지 워터마크를 추가하는 방법을 배웁니다.

PowerPoint 슬라이드에 워터마크를 추가하는 Python 라이브러리

PPT 슬라이드에 워터마크를 추가하거나 제거하기 위해 Aspose.Slides for Python via .NET을 사용합니다. 라이브러리를 사용하면 Python 응용 프로그램 내에서 PowerPoint 프레젠테이션을 원활하게 만들고 조작할 수 있습니다. 다음 pip 명령을 사용하여 PyPI에서 라이브러리를 설치합니다.

> pip install aspose.slides

Python에서 PowerPoint PPT 슬라이드에 워터마크 추가

PowerPoint 슬라이드에 추가할 수 있는 워터마크에는 이미지와 텍스트의 두 가지 유형이 있습니다. 이미지 기반 워터마킹에서는 PPT 슬라이드에 이미지가 추가됩니다. 반면, 텍스트 기반 워터마킹의 경우 텍스트 조각이 슬라이드에 배치됩니다. 다음 섹션에서는 두 가지 유형의 워터마크를 명시적으로 다룹니다.

Python에서 PowerPoint 슬라이드에 텍스트 워터마크 추가

다음은 Python에서 PPT 슬라이드에 텍스트 워터마크를 추가하는 단계입니다.

  • 먼저 Presentation 클래스를 사용하여 PowerPoint PPT/PPTX를 로드합니다.
  • 워터마크를 추가하려는 슬라이드의 참조를 가져옵니다.
  • 워터마크의 위치를 계산합니다.
  • add\auto\shape() 메서드를 사용하여 워터마크에 대한 새 자동 모양을 추가합니다.
  • add\text\frame() 메서드를 사용하여 모양에 텍스트 프레임을 추가합니다.
  • 워터마크의 글꼴 크기, 색상, 순서 및 회전 각도를 설정합니다.
  • 제거 또는 수정을 방지하기 위해 워터마크를 잠급니다.
  • 마지막으로 Presentation.save(string, SaveFormat) 메서드를 사용하여 업데이트된 PowerPoint 파일을 저장합니다.

다음 코드 샘플은 PowerPoint 슬라이드에 텍스트 워터마크를 추가하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# load presentation
with slides.Presentation("presentation.pptx") as presentation:
    # select slide
    slide = presentation.slides[0]

    # set watermark position
    center = drawing.PointF(presentation.slide_size.size.width / 2, presentation.slide_size.size.height / 2)
    width = 300
    height = 300
    x = center.x - width / 2
    y = center.y - height / 2

    # add watermark
    watermarkShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, x, y, height, width)
    watermarkShape.name = "watermark"
    watermarkShape.fill_format.fill_type = slides.FillType.NO_FILL
    watermarkShape.line_format.fill_format.fill_type = slides.FillType.NO_FILL

    # set watermark text, font and color
    watermarkTextFrame = watermarkShape.add_text_frame("Watermark")
    watermarkPortion = watermarkTextFrame.paragraphs[0].portions[0]
    watermarkPortion.portion_format.font_height = 52        
    watermarkPortion.portion_format.fill_format.fill_type = slides.FillType.SOLID
    watermarkPortion.portion_format.fill_format.solid_fill_color.color = drawing.Color.red

    # lock watermark to avoid modification
    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 rotation
    watermarkShape.rotation = -45

    # send to back
    slide.shapes.reorder(0, watermarkShape)

    # save presentation
    presentation.save("text-watermark-slide.pptx", slides.export.SaveFormat.PPTX)

모든 슬라이드에 워터마크를 추가하려면 다음 코드 샘플과 같이 슬라이드를 반복하거나 마스터 슬라이드에 워터마크를 추가할 수 있습니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# load presentation
with slides.Presentation("presentation.pptx") as presentation:
    # select slide
    master = presentation.masters[0]

    # set watermark position
    center = drawing.PointF(presentation.slide_size.size.width / 2, presentation.slide_size.size.height / 2)
    width = 300
    height = 300
    x = center.x - width / 2
    y = center.y - height / 2

    # add watermark
    watermarkShape = master.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, x, y, height, width)
    watermarkShape.name = "watermark"
    watermarkShape.fill_format.fill_type = slides.FillType.NO_FILL
    watermarkShape.line_format.fill_format.fill_type = slides.FillType.NO_FILL

    # set watermark text, font and color
    watermarkTextFrame = watermarkShape.add_text_frame("Watermark")
    watermarkPortion = watermarkTextFrame.paragraphs[0].portions[0]
    watermarkPortion.portion_format.font_height = 52        
    watermarkPortion.portion_format.fill_format.fill_type = slides.FillType.SOLID
    watermarkPortion.portion_format.fill_format.solid_fill_color.color = drawing.Color.red

    # lock watermark to avoid modification
    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

    # send to back
    master.shapes.reorder(0, watermarkShape)

    # set rotation
    watermarkShape.rotation = -45

    # save presentation
    presentation.save("text-watermark-ppt.pptx", slides.export.SaveFormat.PPTX)

다음은 워터마크를 추가한 후의 PowerPoint 슬라이드의 스크린샷입니다.

Python에서 PowerPoint 슬라이드에 텍스트 워터마크 추가

Python에서 PowerPoint 슬라이드에 이미지 워터마크 추가

다음은 Python에서 PowerPoint 슬라이드에 이미지 워터마크를 추가하는 단계입니다.

  • 먼저 Presentation 클래스를 사용하여 PowerPoint 프레젠테이션을 로드합니다.
  • 워터마크를 추가하려는 슬라이드의 참조를 가져옵니다.
  • 워터마크의 위치를 계산합니다.
  • 파일에서 워터마크 이미지를 로드합니다.
  • add\auto\shape() 메서드를 사용하여 워터마크에 대한 새 모양을 추가하고 shape.fill\format.fill\type을 FillType.PICTURE로 설정합니다.
  • shape.fill\format.picture\fill\format.picture.image 속성을 사용하여 워터마크 이미지를 설정합니다.
  • 워터마크의 순서를 설정하고 수정하지 않도록 잠급니다.
  • 마지막으로 Presentation.save(string, SaveFormat) 메서드를 사용하여 업데이트된 PPT를 저장합니다.

다음 코드 샘플은 PowerPoint 슬라이드에 이미지 워터마크를 추가하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# load presentation
with slides.Presentation("presentation.pptx") as presentation:
    # select slide
    slide = presentation.slides[0]

    # set watermark position
    center = drawing.PointF(presentation.slide_size.size.width / 2, presentation.slide_size.size.height / 2)
    width = 100
    height = 100
    x = center.x - width / 2
    y = center.y - height / 2

    # load image
    with open("python-logo.png", "rb") as fs:
        data = fs.read()
        image = presentation.images.add_image(data)

        # add watermark
        watermarkShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, x, y, height, width)
        watermarkShape.name = "watermark"

        # set image for watermark
        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
        watermarkShape.line_format.fill_format.fill_type = slides.FillType.NO_FILL

        # send to back
        slide.shapes.reorder(0, watermarkShape)

        # lock watermark to avoid modification
        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

    # save presentation
    presentation.save("image-watermark-ppt.pptx", slides.export.SaveFormat.PPTX)

다음은 이미지 워터마크를 추가한 PPT 슬라이드의 스크린샷입니다.

Python에서 PowerPoint 슬라이드에 이미지 워터마크 추가

Python의 PPT 슬라이드에서 워터마크 제거

이전 섹션에서 워터마크 모양에 이름을 할당했음을 눈치채셨을 것입니다. 이 이름은 워터마크로 사용되는 도형을 필터링하는 데 사용됩니다. 따라서 워터마크 모양에 쉽게 액세스, 수정 또는 제거할 수 있습니다. 다음 코드 샘플은 Python에서 PPT 슬라이드에 추가한 워터마크를 제거하는 방법을 보여줍니다.

import aspose.slides as slides
import aspose.pydrawing as drawing

# load presentation
with slides.Presentation("text-watermark-slide.pptx") as presentation:
    # select slide
    slide = presentation.slides[0]

    shapesToRemove=[]

    # loop through all the shapes in slide
    for i in range(len(slide.shapes)):
        shape = slide.shapes[i]

        # if shape is watermark
        if shape.name == "watermark":                
            shapesToRemove.append(shape)

    # loop through all the shapes to be removed
    for i in range(len(shapesToRemove)):
        # remove shape
        slide.shapes.remove(shapesToRemove[i])

    # save presentation
    presentation.save("remove-watermark.pptx", slides.export.SaveFormat.PPTX)

무료 라이선스 받기

임시 라이선스를 요청하면 평가 제한 없이 .NET을 통해 Python용 Aspose.Slides를 사용할 수 있습니다.

결론

이 기사에서는 Python에서 PowerPoint 슬라이드에 워터마크를 추가하는 방법을 배웠습니다. PPT 슬라이드에 텍스트 및 이미지 워터마크를 추가하는 방법을 다루었습니다. 또한 프로그래밍 방식으로 PowerPoint PPT에서 워터마크를 제거하는 방법을 살펴보았습니다. 또한 문서를 읽고 Python용 Aspose.Slides의 다른 기능을 탐색할 수 있습니다. 또한 포럼에 질문을 게시할 수 있습니다.

또한보십시오

정보: Aspose.Slides에서 제공하는 무료 온라인 도구를 확인하여 PowerPoint 프레젠테이션에서 워터마크 추가워터마크 제거를 할 수 있습니다.