이 문서에서는 자세한 구성 단계 및 실행 가능한 샘플 코드와 함께 Python을 사용하여 HTML로 PowerPoint 슬라이드를 만드는 방법을 설명합니다. 새 presentation를 생성하고 HTML로 내보내거나 기존 프레젠테이션을 로드하여 브라우저에 표시하기 위해 HTML로 변환할 수 있습니다. Python 지원 환경에서 MS PowerPoint 또는 다른 타사 도구에 의존하지 않고 Python으로 HTML 프레젠테이션을 만들 수 있습니다.
Python을 사용하여 HTML로 PowerPoint 슬라이드를 만드는 단계
- 애플리케이션에서 .NET을 통한 Python용 Aspose.Slides을(를) 사용할 환경 설정
- Python 파일에서 aspose.slides 및 aspose.pydrawing 가져오기
- Presentation 클래스 개체를 사용하여 빈 PowerPoint 프레젠테이션을 만들고 HTML 파일로 저장
- 새로 만든 프레젠테이션의 기본 첫 번째 기본 슬라이드에 액세스
- 모양 및 텍스트 속성 설정과 함께 직사각형 유형의 Autoshape 삽입
- 생성된 프레젠테이션을 HTML 파일로 저장
위의 간단한 단계는 몇 가지 API 호출만으로 Python을 사용하여 HTML 프레젠테이션 슬라이드를 만드는 방법을 안내합니다. 새 프레젠테이션을 만들거나 기존 프레젠테이션을 로드하여 HTML로 변환할 수 있습니다. 이 예에서는 프레젠테이션을 만들고 출력 HTML 페이지에 내용을 표시하기 위해 모양 및 텍스트 속성 설정과 함께 직사각형 유형의 자동 모양을 추가하는 데 중점을 두었습니다.
Python을 사용하여 HTML 프레젠테이션을 만드는 코드
import aspose.pydrawing as drawing | |
import aspose.slides as slides | |
# Applying the linence for Aspose.Slides | |
slidesLicense = slides.License() | |
slidesLicense.set_license("Aspose.Total.lic") | |
# Generate an empty presentation using Presentation class object | |
with slides.Presentation() as htmlPresentationObj: | |
# Access the first slide inside presentation slides collection | |
slide = htmlPresentationObj.slides[0] | |
# Insert an Autoshape of Rectangle type inside the slide | |
recAutoShape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 150, 150, 300, 200) | |
# Fill the added auto shape with color | |
recAutoShape.fill_format.fill_type = slides.FillType.SOLID | |
recAutoShape.fill_format.solid_fill_color.color = drawing.Color.green; | |
# Insert a text frame and add text inside the shape | |
shapeTextFrame = recAutoShape.add_text_frame("Testing presentation to HTML") | |
# Applying different text related properties | |
portFormat = shapeTextFrame.paragraphs[0].portions[0].portion_format | |
portFormat.fill_format.fill_type = slides.FillType.SOLID | |
portFormat.fill_format.solid_fill_color.color= drawing.Color.red | |
portFormat.font_bold = slides.NullableBool.TRUE | |
portFormat.font_italic = slides.NullableBool.TRUE | |
portFormat.font_height = 14 | |
# Save the generated HTML on the disk | |
htmlPresentationObj.save("GeneratedHtml.html", slides.export.SaveFormat.HTML) |
Python을 사용하여 HTML로 PowerPoint 슬라이드를 렌더링하는 이 코드는 직사각형 자동 모양을 만들었습니다. 하이퍼링크, 텍스트 단락, 글머리 기호, 번호 매기기 목록, 미디어 파일, 차트, SmartArt 및 WordArt 등을 추가하여 모양과 텍스트를 추가로 사용자 지정할 수 있습니다. 마찬가지로 HTML로 내보내는 동안 렌더링할 슬라이드를 선택할 수도 있습니다. HTML과 메모리 스트림에 저장하는 옵션도 있습니다.
이 주제에서는 Python을 사용하여 프레젠테이션을 HTML로 변환하는 방법을 배웠습니다. 슬라이드를 이미지로 변환하는 방법에 대해 알아보려면 Python을 사용하여 PowerPoint 슬라이드 이미지를 만드는 방법에 대한 문서를 참조하세요.