ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Python/python-pptx 사용자 가이드 - 5. 슬라이드
    코딩/Python 2024. 6. 5. 17:03
    728x90

    https://python-pptx.readthedocs.io/en/latest/user/slides.html

    Working with Slides

    Every slide in a presentation is based on a slide layout. Not surprising then that you have to specify which slide layout to use when you create a new slide. Let’s take a minute to understand a few things about slide layouts that we’ll need so the slide we add looks the way we want it to.

    프레젠테이션의 모든 슬라이드는 슬라이드 레이아웃을 기반으로 한다. 새 슬라이드를 만들 때 사용할 슬라이드 레이아웃을 지정해야 한다는 것은 놀라운 일이 아니다. 추가한 슬라이드가 원하는 대로 보이도록 하기 위해 필요한 슬라이드 레이아웃에 대한 몇 가지 사항을 잠시 이해해 본다.

    Slide layout basics

    A slide layout is like a template for a slide. Whatever is on the slide layout “shows through” on a slide created with it and formatting choices made on the slide layout are inherited by the slide. This is an important feature for getting a professional-looking presentation deck, where all the slides are formatted consistently. Each slide layout is based on the slide master in a similar way, so you can make presentation-wide formatting decisions on the slide master and layout-specific decisions on the slide layouts. There can actually be multiple slide masters, but I’ll pretend for now there’s only one. Usually there is.

    The presentation themes that come with PowerPoint have about nine slide layouts, with names like Title, Title and Content, Title Only, and Blank. Each has zero or more placeholders (mostly not zero), preformatted areas into which you can place a title, multi-level bullets, an image, etc. More on those later.

    The slide layouts in a standard PowerPoint theme always occur in the same sequence. This allows content from one deck to be pasted into another and be connected with the right new slide layout:

    슬라이드 레이아웃은 슬라이드의 템플릿과 같다. 슬라이드 레이아웃에 있는 모든 항목은 생성된 슬라이드에 "보여지며" 슬라이드 레이아웃에서 선택한 서식 선택 사항이 슬라이드에 상속된다. 이는 모든 슬라이드의 형식이 일관되게 유지되는 전문적인 프레젠테이션 데크를 만드는 데 중요한 기능이다. 각 슬라이드 레이아웃은 비슷한 방식으로 슬라이드 마스터를 기반으로 하므로 슬라이드 마스터에서 프레젠테이션 전체의 서식을 결정하고 슬라이드 레이아웃에서 레이아웃별 결정을 내릴 수 있다. 실제로 슬라이드 마스터가 여러 개 있을 수 있지만 지금은 하나만 있는 것으로 가정한다.

    PowerPoint와 함께 제공되는 프레젠테이션 테마에는 제목, 제목 및 내용, 제목만, 공백 등의 이름이 포함된 약 9개의 슬라이드 레이아웃이 있다. 각각에는 0개 이상의 자리 표시자(대부분 0이 아님), 제목, 다단계 글머리 기호, 이미지 등을 배치할 수 있는 미리 형식화된 영역이 있다. 이에 대해서는 나중에 자세히 설명한다.

    표준 PowerPoint 테마의 슬라이드 레이아웃은 항상 동일한 순서로 발생한다. 이를 통해 한 데크의 콘텐츠를 다른 데크에 붙여넣고 올바른 새 슬라이드 레이아웃과 연결할 수 있다.

    • Title (presentation title slide)
    • Title and Content
    • Section Header (sometimes called Segue)
    • Two Content (side by side bullet textboxes)
    • Comparison (same but additional title for each side by side content box)
    • Title Only
    • Blank
    • Content with Caption
    • Picture with Caption
    • 제목(프레젠테이션 제목 슬라이드)
    • 제목과 내용
    • 섹션 헤더(Segue라고도 함)
    • 두 개의 콘텐츠(나란한 글머리 기호 텍스트 상자)
    • 비교(동일하지만 나란히 있는 콘텐츠 상자마다 제목이 추가됨)
    • 제목만
    • 공백
    • 캡션이 있는 콘텐츠
    • 캡션이 있는 사진

    In python-pptx, these are prs.slide_layouts[0] through prs.slide_layouts[8]. However, there’s no rule they have to appear in this order, it’s just a convention followed by the themes provided with PowerPoint. If the deck you’re using as your template has different slide layouts or has them in a different order, you’ll have to work out the slide layout indices for yourself. It’s pretty easy. Just open it up in Slide Master view in PowerPoint and count down from the top, starting at zero.

    Now we can get to creating a new slide.

    python-pptx에서는 prs.slide_layouts[0]부터 prs.slide_layouts[8]까지이다. 하지만 꼭 이 순서대로 나타나야 한다는 규칙은 없으며, 파워포인트에서 제공하는 테마를 따르는 관례일 뿐이다. 템플릿으로 사용 중인 데크의 슬라이드 레이아웃이 다르거나 순서가 다른 경우 슬라이드 레이아웃 색인을 직접 계산해야 한다. 꽤 쉽다. PowerPoint의 슬라이드 마스터 보기에서 열고 위에서부터 0부터 카운트다운한다.

    이제 새 슬라이드를 만들 수 있다.

    Adding a slide

    Let’s use the Title and Content slide layout; a lot of slides do:

    제목 및 콘텐츠 슬라이드 레이아웃을 사용해 본다. 많은 슬라이드에서 다음과 같은 작업을 수행한다.

    SLD_LAYOUT_TITLE_AND_CONTENT = 1
    
    prs = Presentation()
    slide_layout = prs.slide_layouts[SLD_LAYOUT_TITLE_AND_CONTENT]
    slide = prs.slides.add_slide(slide_layout)

    A few things to note:

    • Using a “constant” value like SLD_LAYOUT_TITLE_AND_CONTENT is up to you. If you’re creating many slides it can be handy to have constants defined so a reader can more easily make sense of what you’re doing. There isn’t a set of these built into the package because they can’t be assured to be right for the starting deck you’re using.
    • prs.slide_layouts is the collection of slide layouts contained in the presentation and has list semantics, at least for item access which is about all you can do with that collection at the moment. Using prs for the Presentation instance is purely conventional, but I like it and use it consistently.
    • prs.slides is the collection of slides in the presentation, also has list semantics for item access, and len() works on it. Note that the method to add the slide is on the slide collection, not the presentation. The add_slide() method appends the new slide to the end of the collection. At the time of writing it’s the only way to add a slide, but sooner or later I expect someone will want to insert one in the middle, and when they post a feature request for that I expect I’ll add an insert_slide(idx, ...) method.

    참고할 몇 가지 사항:

    • SLD_LAYOUT_TITLE_AND_CONTENT와 같은 "상수" 값을 사용하는 것은 당신에게 달려 있다. 많은 슬라이드를 만드는 경우 독자가 진행 중인 작업을 더 쉽게 이해할 수 있도록 상수를 정의하는 것이 편리할 수 있다. 사용 중인 시작 데크에 적합하다고 확신할 수 없기 때문에 이러한 세트가 패키지에 내장되어 있지 않다.
    • prs.slide_layouts는 프리젠테이션에 포함된 슬라이드 레이아웃 모음이며 적어도 현재 해당 컬렉션으로 할 수 있는 모든 항목 액세스에 대한 목록 의미를 갖는다. Presentation 인스턴스에 prs를 사용하는 것은 순전히 전통적인 방식이지만 나는 그것을 좋아하고 일관되게 사용한다.
    • prs.slides는 프리젠테이션의 슬라이드 모음이며 항목 액세스를 위한 목록 의미 체계도 갖고 있으며 len()이 이에 대해 작동한다. 슬라이드를 추가하는 방법은 프레젠테이션이 아닌 슬라이드 컬렉션에 있다는 점에 유의한다. add_slide() 메서드는 새 슬라이드를 컬렉션 끝에 추가한다. 글을 쓰는 시점에는 이것이 슬라이드를 추가하는 유일한 방법이지만 조만간 누군가가 중간에 슬라이드를 삽입하고 싶어할 것으로 예상하고, 누군가 이 기능 요청을 게시하면 insert_slide(idx, ...)를 추가할 것이다.

    Doing other things with slides

    Right now, adding a slide is the only operation on the slide collection. On the backlog at the time of writing is deleting a slide and moving a slide to a different position in the list. Copying a slide from one presentation to another turns out to be pretty hard to get right in the general case, so that probably won’t come until more of the backlog is burned down.

    현재 슬라이드 추가는 슬라이드 컬렉션에 대한 유일한 작업이다. 작성 당시 백로그에는 슬라이드를 삭제하고 목록의 다른 위치로 슬라이드를 이동하는 작업이 있다. 한 프레젠테이션에서 다른 프레젠테이션으로 슬라이드를 복사하는 것은 일반적인 경우 제대로 수행하기가 매우 어렵기 때문에 더 많은 백로그가 소각될 때까지 복사되지 않을 것이다.

    Up next …

    Ok, now that we have a new slide, let’s talk about how to put something on it …

    이제 새 슬라이드가 생겼으니 슬라이드에 내용을 넣는 방법에 대해 이야기해 본다.

     

    Python/python-pptx 사용자 가이드

    728x90

    댓글

Designed by Tistory.