.NET에서 프레젠테이션 로드 방법
Aspose.Slides FOSS for .NET lets you open any .pptx 파일을 검사하고 내용을 확인한 뒤 PPTX로 다시 저장하거나 데이터를 추출합니다. 이 가이드는 파일 열기, 슬라이드 순회, 도형 텍스트 읽기, 그리고 저장을 라운드 트립하는 방법을 다룹니다.
단계별 가이드
단계 1: 패키지 설치
dotnet add package Aspose.Slides.Foss단계 2: 기존 프레젠테이션 열기
파일 경로를 전달합니다 new Presentation(). 사용합니다 using 정리를 보장하는 구문.
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation("input.pptx");
Console.WriteLine($"Slide count: {prs.Slides.Count}");
prs.Save("output.pptx", SaveFormat.Pptx);소스 파일의 알 수 없는 XML 파트는 그대로 보존됩니다: 라이브러리는 아직 이해하지 못하는 내용을 절대 제거하지 않습니다.
단계 3: 슬라이드 검사
모든 슬라이드를 순회하면서 인덱스를 출력합니다:
using Aspose.Slides.Foss;
using var prs = new Presentation("deck.pptx");
for (int i = 0; i < prs.Slides.Count; i++)
{
var slide = prs.Slides[i];
int shapeCount = slide.Shapes.Count;
Console.WriteLine($"Slide {i}: {shapeCount} shapes");
}단계 4: 도형 텍스트 읽기
도형을 순회하고 a가 있는 도형에서 텍스트를 읽습니다. TextFrame:
using Aspose.Slides.Foss;
using var prs = new Presentation("deck.pptx");
foreach (var slide in prs.Slides)
{
foreach (var shape in slide.Shapes)
{
if (shape is IAutoShape autoShape && autoShape.TextFrame != null)
{
string text = autoShape.TextFrame.Text;
if (!string.IsNullOrWhiteSpace(text))
Console.WriteLine($" Shape text: {text}");
}
}
}단계 5: 문서 속성 읽기
에서 핵심 문서 속성에 접근합니다. prs.DocumentProperties:
using Aspose.Slides.Foss;
using var prs = new Presentation("deck.pptx");
var props = prs.DocumentProperties;
Console.WriteLine($"Title: {props.Title}");
Console.WriteLine($"Author: {props.Author}");
Console.WriteLine($"Subject: {props.Subject}");단계 6: 라운드 트립 저장
프레젠테이션을 검사하거나 수정한 후, PPTX로 다시 저장합니다:
prs.Save("output.pptx", SaveFormat.Pptx);다른 경로에 저장하면 새 파일이 생성됩니다. 같은 경로에 저장하면 원본이 덮어쓰기됩니다.
일반적인 문제 및 해결책
FileNotFoundException
경로가 올바른지 확인합니다. .pptx 파일이 작업 디렉터리를 기준으로 올바른지 확인합니다. 사용합니다. Path.Combine 강력한 경로 구성을 위해:
string path = Path.Combine(AppContext.BaseDirectory, "assets", "deck.pptx");
using var prs = new Presentation(path);Exception: File format is not supported
라이브러리는 지원합니다. .pptx (Office Open XML)만 지원합니다. 레거시 .ppt (binary PowerPoint 97-2003) 파일은 지원되지 않습니다.
도형에는 TextFrame 속성이 없습니다
일부 도형 (Connector, PictureFrame)는 a가 없습니다. TextFrame. 로 캐스팅합니다. IAutoShape 텍스트에 접근하기 전에 null인지 확인합니다.
자주 묻는 질문
로드 시 원본 콘텐츠가 모두 보존됩니까?
예. 알 수 없는 XML 파트는 라운드트립 저장 시 그대로 보존됩니다. 라이브러리는 아직 인식하지 못하는 XML 내용을 제거하지 않습니다.
암호로 보호된 PPTX를 로드할 수 있나요?
암호로 보호된(암호화된) 프레젠테이션은 이 버전에서 지원되지 않습니다.
내장된 이미지를 추출할 수 있나요?
이미지 컬렉션에 접근합니다: prs.Images 반환합니다 ImageCollection. 각 이미지에는 원시 이미지 데이터를 읽을 수 있는 속성이 있습니다.
MemoryStream에서 로드하는 것이 지원되나요?
예. The Presentation 생성자는 a를 받아들입니다 Stream:
using var stream = new MemoryStream(pptxBytes);
using var prs = new Presentation(stream);
Console.WriteLine($"Slides: {prs.Slides.Count}");