소개

이 가이드는 PowerPoint 프레젠테이션을 Python에서 Aspose.Slides FOSS를 사용하여 프로그래밍 방식으로 생성, 수정 및 저장하는 방법을 보여줍니다. 이 라이브러리를 사용하면 슬라이드를 처음부터 만들고, 슬라이드를 추가 및 재정렬하며, 도형, 표 및 서식이 적용된 텍스트로 채우고, 결과를 PPTX로 저장할 수 있습니다. 모든 처리는 순수 Python에서 수행되며 Microsoft Office나 외부 바이너리에 대한 의존성이 없습니다.

이 라이브러리는 PyPI에서 aspose-slides-foss 이름으로 MIT 라이선스 하에 제공됩니다. pip으로 설치하고, 가져온 뒤 몇 줄의 코드로 프레젠테이션 구축을 시작하세요. 보고서 생성 자동화, 슬라이드 덱 파이프라인 구축, 웹 애플리케이션에 프레젠테이션 출력 삽입 등 어떤 경우든 API은 전체 기능을 포괄합니다: 슬라이드 컬렉션, 마스터/레이아웃 슬라이드, 도형 컬렉션, 텍스트 프레임, 채우기 형식, 그리고 내보내기 옵션.

이 글에서는 핵심 프레젠테이션 관리 기능을 살펴봅니다 — Python에서 슬라이드를 다룰 때 가장 많이 사용할 클래스와 메서드들.


포함된 내용

프레젠테이션 수명 주기

Presentation 클래스는 진입점입니다. 새 데크를 생성하고, 내용을 조작한 뒤 PPTX로 저장합니다. Presentation을 with와 함께 컨텍스트 매니저로 사용하면 파일 핸들을 자동으로 해제할 수 있습니다.

import io
from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat

with Presentation() as pres:
    # A new presentation starts with one blank slide
    print("Slides:", len(pres.slides))  # 1

    # Save to a file
    pres.save("output.pptx", SaveFormat.PPTX)

    # Or save to a stream
    buf = io.BytesIO()
    pres.save(buf, SaveFormat.PPTX)

슬라이드 컬렉션 작업

SlideCollection은 슬라이드를 추가, 삽입, 복제, 제거 및 순서를 다시 정렬할 수 있게 해줍니다. len(pres.slides)은 각 변경 후 현재 개수를 반영합니다.

from aspose.slides_foss import Presentation, ShapeType

with Presentation() as pres:
    layout = pres.layout_slides[0]

    # Add a blank slide using the first layout
    pres.slides.add_empty_slide(layout)

    # Insert at a specific position
    pres.slides.insert_empty_slide(1, layout)

    # Clone an existing slide (shapes are copied)
    pres.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 200, 100)
    pres.slides.add_clone(pres.slides[0])

    print("Total slides:", len(pres.slides))  # 4

    # Remove by index
    pres.slides.remove_at(3)

도형 및 AutoShapes

ShapeCollection.add_auto_shape()을 통해 모든 슬라이드에 사각형, 타원, 삼각형 및 기타 기하학적 도형을 추가합니다. 각 도형은 위치, 크기, 회전 및 채우기 속성을 제공하며 저장/재로드 주기 동안 지속됩니다.

from aspose.slides_foss import Presentation, ShapeType

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    rect = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    rect.rotation = 15

    ellipse = slide.shapes.add_auto_shape(ShapeType.ELLIPSE, 400, 50, 200, 200)

    # Reorder z-index
    slide.shapes.reorder(0, ellipse)
    print("Front shape:", slide.shapes[0].shape_type)  # ELLIPSE

표

ShapeCollection.add_table()을 사용하여 데이터 표를 생성하고, TextFrame을 통해 셀 텍스트를 설정하며, 셀을 병합하고 테두리 서식을 적용합니다. 행 높이와 열 너비는 생성자에 전달한 값과 일치합니다.

from aspose.slides_foss import Presentation, FillType
from aspose.slides_foss.drawing import Color

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    table = slide.shapes.add_table(50, 50, [150, 150, 150], [40, 40, 40])

    # Merge two cells in the second row
    table.merge_cells(table.rows[1][0], table.rows[1][1], False)

    # Style the header row with a bottom border
    for col_idx in range(len(table.columns)):
        fmt = table.rows[0][col_idx].cell_format
        fmt.border_bottom.fill_format.fill_type = FillType.SOLID
        fmt.border_bottom.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 0, 0)
        fmt.border_bottom.width = 2

마스터 및 레이아웃 슬라이드

모든 프레젠테이션에는 마스터 슬라이드와 레이아웃 슬라이드의 계층 구조가 있습니다. Presentation.masters 및 Presentation.layout_slides을 통해 이를 접근하여 데크 전체에 일관된 서식을 적용합니다.

from aspose.slides_foss import Presentation

with Presentation() as pres:
    master = pres.masters[0]
    print("Master layouts:", len(master.layout_slides))

    # Pick a layout by type
    from aspose.slides_foss import SlideLayoutType
    title_layout = pres.layout_slides.get_by_type(SlideLayoutType.TITLE)
    if title_layout:
        pres.slides.add_empty_slide(title_layout)

문서 속성

제목, 저자, 주제와 같은 기본 메타데이터를 DocumentProperties 객체를 통해 읽고 쓸 수 있습니다. save()을 호출하기 전에 이러한 속성 중 하나라도 설정하세요 — 이들은 PPTX 메타데이터에 내장되며 다운스트림 도구에서 읽을 수 있습니다:

from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat

with Presentation() as pres:
    props = pres.document_properties
    props.title = "Quarterly Report"
    props.author = "Engineering"
    props.subject = "Q1 2026 Results"

    pres.save("report.pptx", SaveFormat.PPTX)

빠른 시작

다음 pip 명령을 실행하여 PyPI에서 Python용 Aspose.Slides FOSS을 설치하세요:

pip install aspose-slides-foss

다음 예제는 제목 도형, 데이터 테이블 및 채우기가 포함된 프레젠테이션을 만든 후 PPTX로 저장합니다:

from aspose.slides_foss import Presentation, ShapeType, FillType, NullableBool
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    # Add a title shape
    title = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 30, 860, 80)
    tf = title.add_text_frame("Quarterly Report")
    tf.paragraphs[0].portions[0].portion_format.font_bold = NullableBool.TRUE
    tf.paragraphs[0].portions[0].portion_format.font_height = 28

    # Add a data table
    table = slide.shapes.add_table(50, 150, [200, 200, 200], [40, 40, 40])
    headers = ["Region", "Revenue", "Growth"]
    for i, h in enumerate(headers):
        table.rows[0][i].text_frame.text = h

    # Fill the title shape background
    title.fill_format.fill_type = FillType.SOLID
    title.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 51, 102)

    # Save as PPTX
    pres.save("report.pptx", SaveFormat.PPTX)

지원되는 형식

형식확장자읽기쓰기
PPTX.pptx✓✓
PPT.ppt—Planned
PPSX.ppsx—Planned
PPTM.pptm—Planned
POTX.potx—Planned
ODP.odp—Planned
PDF.pdf—Planned
HTML.html—Planned
HTML5.html—Planned
TIFF.tiff—Planned
GIF.gif—Planned
XPS.xps—Planned
FODP.fodp—Planned
MD.md—Planned

참고: PPTX 읽기 및 쓰기가 완전히 구현되었습니다. 기타 SaveFormat 값(PPT, ODP, PDF 등)은 향후 릴리스에서 계획되어 있으며; 이를 save() 현재는 PPTX 출력이 생성됩니다.


오픈 소스 및 라이선스

Aspose.Slides FOSS for Python은 MIT 라이선스로 배포됩니다. 개인, 학술, 상업 프로젝트에서 제한 없이 사용할 수 있습니다. 소스 코드는 GitHub에서 확인할 수 있으며, 패키지는 PyPI에 게시되어 있습니다.


시작하기

관련 리소스