Python의 PowerPoint 파일에서 텍스트 추출

다양한 시나리오에서 텍스트 분석, 분류 등과 같은 추가 처리를 위해 문서에서 텍스트가 추출됩니다. PDF 및 Word와 같은 다른 문서 중에서 PowerPoint 파일도 텍스트 추출에 사용됩니다. 따라서 이 기사에서는 Python에서 PowerPoint 파일에서 텍스트를 추출하는 방법을 보여 주는 것을 목표로 합니다. 특정 슬라이드 또는 전체 프레젠테이션에서 텍스트를 추출하는 방법을 다룹니다.

PowerPoint 파일에서 텍스트를 추출하는 Python 라이브러리

PowerPoint 파일에서 텍스트를 추출하려면 .NET을 통한 Python용 Aspose.Slides를 사용합니다. PowerPoint 프레젠테이션을 만들고 업데이트할 수 있는 기능이 풍부한 Python 라이브러리입니다. 또한 프레젠테이션을 원활하게 조작하고 변환할 수 있습니다. 다음 pip 명령을 사용하여 PyPI에서 이 라이브러리를 설치할 수 있습니다.

> pip install aspose.slides 

Python의 PowerPoint 파일에서 텍스트 추출

시나리오에 따라 전체 PowerPoint 프레젠테이션이나 일부 특정 슬라이드에서 텍스트를 추출해야 할 수도 있습니다. 다음 섹션에서는 위에서 언급한 두 경우 모두에서 텍스트 추출을 수행하는 방법을 보여줍니다. 계속 진행하겠습니다.

특정 슬라이드에서 텍스트 추출

다음은 Python에서 PPT의 특정 슬라이드에서 텍스트를 추출하는 단계입니다.

  • 먼저 PresentationFactory().get_presentation\text(string, TextExtractionArrangingMode) 메서드를 사용하여 프레젠테이션에서 모든 유형의 텍스트를 가져옵니다.

  • 그런 다음 인덱스를 사용하여 슬라이드\텍스트 배열에서 특정 슬라이드의 텍스트를 추출합니다.

  • 추출할 수 있는 텍스트 유형은 다음과 같습니다.

    • 슬라이드의 텍스트

    • 메모

    • 슬라이드 레이아웃 텍스트

    • 슬라이드 마스터 텍스트

다음 코드 샘플은 Python의 특정 PPT 슬라이드에서 텍스트를 추출하는 방법을 보여줍니다.

import aspose.slides as slides

# Get all the text from presentation
text = slides.PresentationFactory().get_presentation_text("presentation.pptx", slides.TextExtractionArrangingMode.UNARRANGED)

# Print text of the desired slide using its index
print(text.slides_text[0].text)
print(text.slides_text[0].layout_text)
print(text.slides_text[0].master_text)
print(text.slides_text[0].notes_text)

Python의 전체 PowerPoint 파일에서 텍스트 추출

다음 단계는 PowerPoint 프레젠테이션의 모든 슬라이드에서 텍스트를 추출하는 방법을 보여줍니다.

다음 코드 샘플은 Python의 PPTX(또는 PPT) 파일에서 텍스트를 추출하는 방법을 보여줍니다.

import aspose.slides as slides

# Get all the text from presentation
text = slides.PresentationFactory().get_presentation_text("presentation.pptx", slides.TextExtractionArrangingMode.UNARRANGED)

# Load the presentation to get slide count
with slides.Presentation("presentation.pptx") as ppt:

    # Loop through slides in the presentation
    for index in range(ppt.slides.length):

        # Print text of desired sections such as slide's text, layout text, notes, etc.
        print(text.slides_text[index].text)
        print(text.slides_text[index].layout_text)
        print(text.slides_text[index].master_text)
        print(text.slides_text[index].notes_text)

무료 라이선스 받기

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

결론

이 기사에서는 Python에서 PowerPoint 파일에서 텍스트를 추출하는 방법을 배웠습니다. PowerPoint 프레젠테이션의 특정 슬라이드 또는 모든 슬라이드에서 텍스트를 추출하는 방법을 살펴보았습니다. 또한 문서를 사용하여 Python용 Aspose.Slides의 다른 기능을 탐색할 수 있습니다. 또한 포럼을 통해 질문을 공유할 수 있습니다.

또한보십시오