[python] python-pptx 슬라이드 회전하기
python-pptx는 Python에서 PowerPoint 파일을 조작하는 라이브러리입니다. 여기서는 python-pptx를 사용하여 슬라이드를 회전하는 방법을 알아보겠습니다.
슬라이드 객체 가져오기
먼저, 슬라이드를 회전시킬 PowerPoint 파일을 열고, 회전시킬 슬라이드 객체를 가져옵니다. 아래의 예제 코드를 참고하세요.
from pptx import Presentation
# PowerPoint 파일 열기
presentation = Presentation('파일명.pptx')
# 회전시킬 슬라이드 가져오기
slide = presentation.slides[0]
슬라이드 회전하기
스페이스 클래스를 사용하여 슬라이드를 회전할 수 있습니다. 스페이스 클래스는 슬라이드 오브젝트의 .create_spacer(element_id, left, top, width, height)
메소드를 사용하여 생성할 수 있습니다. 회전시킬 슬라이드의 크기와 동일한 크기의 스페이스를 생성하고, 슬라이드에 스페이스를 추가한 다음, 스페이스를 회전시킵니다.
아래의 예제 코드를 참고하세요.
from pptx.util import Inches
# 슬라이드 크기 가져오기
slide_width = presentation.slide_width
slide_height = presentation.slide_height
# 스페이스 생성
spacer = slide.shapes.create_spacer(Inches(0), Inches(0), slide_width, slide_height)
# 슬라이드에 스페이스 추가
slide.shapes._spTree.insert(2, spacer._element)
# 스페이스 회전
spacer.rotation = 45 # 회전 각도 입력
파일로 저장하기
최종적으로 슬라이드를 회전시킨 PowerPoint 파일을 저장할 수 있습니다. 아래의 예제 코드를 참고하세요.
# 파일로 저장
presentation.save('회전된파일명.pptx')