푸터 콘텐츠로 바로가기
PPT 도구

C#을 사용하여 PowerPoint 파일을 이미지로 변환하는 방법

소프트웨어 개발 분야에서 PowerPoint 프레젠테이션을 사진 형식으로 변환할 필요성이 자주 발생합니다. 많은 개발자들은 PowerPoint 파일을 프로그램적으로 사진으로 변환할 수 있는 기능이 미리보기 생성, 섬네일 생성, 시스템 통합에서 유용하다고 생각합니다. 이 글에서는 C# ppt를 이미지로 변환하여 이 작업을 수행하는 방법을 설명하고 도중에 도움을 줄 몇 가지 샘플 코드를 포함할 것입니다.

C#을 사용하여 PowerPoint를 이미지로 변환하는 방법

  1. PowerPoint 애플리케이션 인스턴스를 생성합니다.
  2. 인스턴스를 사용하여 프레젠테이션을 엽니다.
  3. 출력 폴더를 확인하고 생성합니다.
  4. 슬라이드를 반복하고 슬라이드를 이미지로 내보냅니다.
  5. 프레젠테이션을 닫고 애플리케이션을 종료합니다.

PowerPoint 프레젠테이션을 이미지 형식으로 변환할까요?

전문적인 사항에 들어가기 전에 PowerPoint 슬라이드를 사진으로 변환하는 것의 중요성을 빠르게 살펴봅시다. PowerPoint가 동적 프레젠테이션을 만드는 데 훌륭한 도구이지만, 이러한 파일을 원래 형식으로 공유하는 것은 항상 현실적이지는 않습니다. 때로는 프레젠테이션의 특정 슬라이드나 사진만 필요하고, 다른 경우에는 다양한 시스템과 설정에서 PowerPoint 파일의 직접 렌더링을 허용하지 않을 수 있습니다. PowerPoint 프레젠테이션을 사진으로 바꾸는 것은 다양한 장치와 애플리케이션에서 쉽게 공유하고 볼 수 있는 포괄적인 솔루션을 제공합니다.

PowerPoint Interop 라이브러리 사용

C#에서 PowerPoint 프레젠테이션을 사진으로 바꾸는 여러 방법이 있습니다. Microsoft.Office.Interop.PowerPoint 네임스페이스를 사용하여 PowerPoint 애플리케이션과 프로그램적으로 인터페이스할 수 있는 클래스와 메서드를 제공하는 것이 일반적인 접근 방법 중 하나입니다. 이는 PowerPoint 파일을 다루는 데 광범위한 기능을 제공합니다.

새로운 Visual Studio 프로젝트 생성하기

새로운 Visual Studio 프로젝트를 생성하려면 아래 단계를 따르세요:

Visual Studio IDE를 엽니다. 사용하기 전에 PC에 Visual Studio를 설치했는지 확인하세요.

새 프로젝트 시작:

파일을 선택하고 새로 만들기를 선택한 다음, 프로젝트를 선택하세요.

C#를 사용하여 PowerPoint를 이미지로 변환하는 방법: 그림 1 - Visual Studio 열기 및 파일 선택 - 새로 만들기 - 프로젝트.

"새 프로젝트 만들기" 박스에서 왼쪽에서 선호하는 프로그래밍 언어(C# 등)를 선택합니다.

다음으로 사용 가능한 프로젝트 템플릿 목록에서 "콘솔 앱" 또는 "콘솔 앱(.NET Core)" 템플릿을 선택합니다.

프로젝트에 이름을 부여하기 위해 "이름" 섹션을 완료하세요.

How to Use C# to Convert PowerPoint to Image: Figure 2 - From the Create New Project box, select the C# programming language and Console App. Configure the Project name and location, then click on the Next button.

프로젝트의 저장 위치를 선택하세요.

새 콘솔 애플리케이션 프로젝트 작업을 시작하려면 "만들기"를 클릭하세요.

How to Use C# to Convert PowerPoint to Image: Figure 3 - Select the appropriate .NET Framework and click on the Create button.

Convert PowerPoint Slides to Images in C#

Microsoft.Office.Interop.PowerPoint 네임스페이스를 사용하여 PowerPoint 슬라이드를 이미지로 변환하는 방법을 살펴보겠습니다. 먼저 필요한 어셈블리가 설치되어 있고 C# 프로젝트에 참조로 추가되어 있는지 확인하세요. 이 어셈블리는 일반적으로 InterOp 어셈블리를 직접 참조하거나 Microsoft Office Primary Interop Assemblies(PIA)를 설치하여 찾을 수 있습니다.

코드 예제

using System.IO; // Import System.IO namespace for file handling
using Microsoft.Office.Interop.PowerPoint; // Import Interop PowerPoint namespace

class Program
{
    static void Main(string[] args)
    {
        string pptFilePath = "demo.pptx"; // Path to your PowerPoint file
        string outputFolder = "output_images"; // Output folder path where images will be saved

        ConvertPptToImages(pptFilePath, outputFolder); // Convert PowerPoint slides to images
    }

    static void ConvertPptToImages(string pptFilePath, string outputFolder)
    {
        Application pptApplication = new Application(); // Create a new PowerPoint application instance
        Presentation pptPresentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); // Open the PowerPoint presentation

        if (!Directory.Exists(outputFolder)) // Check if the output folder exists
            Directory.CreateDirectory(outputFolder); // Create the output folder if it doesn't exist

        int slidesCount = pptPresentation.Slides.Count; // Get the number of slides in the presentation

        for (int i = 1; i <= slidesCount; i++) // Iterate through all slides
        {
            string outputPath = Path.Combine(outputFolder, $"Slide{i}.png"); // Set the output path for the current slide
            pptPresentation.Slides[i].Export(outputPath, "png", 1024, 768); // Export slide to PNG format
        }

        pptPresentation.Close(); // Close the PowerPoint presentation
        pptApplication.Quit(); // Quit the PowerPoint application
    }
}
using System.IO; // Import System.IO namespace for file handling
using Microsoft.Office.Interop.PowerPoint; // Import Interop PowerPoint namespace

class Program
{
    static void Main(string[] args)
    {
        string pptFilePath = "demo.pptx"; // Path to your PowerPoint file
        string outputFolder = "output_images"; // Output folder path where images will be saved

        ConvertPptToImages(pptFilePath, outputFolder); // Convert PowerPoint slides to images
    }

    static void ConvertPptToImages(string pptFilePath, string outputFolder)
    {
        Application pptApplication = new Application(); // Create a new PowerPoint application instance
        Presentation pptPresentation = pptApplication.Presentations.Open(pptFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); // Open the PowerPoint presentation

        if (!Directory.Exists(outputFolder)) // Check if the output folder exists
            Directory.CreateDirectory(outputFolder); // Create the output folder if it doesn't exist

        int slidesCount = pptPresentation.Slides.Count; // Get the number of slides in the presentation

        for (int i = 1; i <= slidesCount; i++) // Iterate through all slides
        {
            string outputPath = Path.Combine(outputFolder, $"Slide{i}.png"); // Set the output path for the current slide
            pptPresentation.Slides[i].Export(outputPath, "png", 1024, 768); // Export slide to PNG format
        }

        pptPresentation.Close(); // Close the PowerPoint presentation
        pptApplication.Quit(); // Quit the PowerPoint application
    }
}
$vbLabelText   $csharpLabel

PowerPoint 앱과 함께 작업하기 위해 필요한 C# 네임스페이스는 Microsoft.Office.Interop.PowerPoint; 선언을 사용하여 가져옵니다. 프로그램의 진입점은 Main 메서드입니다. 결과 폴더(outputFolder)와 생성된 사진이 저장될 장소, PowerPoint 파일의 경로(pptFilePath)를 지정합니다. PowerPoint 프레젠테이션을 사진으로 실제로 변환하는 것은 이 메서드가 처리합니다.

PowerPoint 프레젠테이션 파일

C#를 사용하여 PowerPoint를 이미지로 변환하는 방법: 그림 4 - 코드 예제에 사용된 PowerPoint ppt.

Application pptApplication = new Application();은 PowerPoint 프로그램의 새 인스턴스를 시작하는 데 사용됩니다. 이는 PowerPoint와의 프로그램적 상호작용을 가능하게 합니다. pptApplication.Presentations를 사용하여 pptFilePath.Open() 기능으로 표시된 PowerPoint 프레젠테이션 파일을 엽니다. 이 함수는 열린 프레젠테이션을 나타내는 Presentation 객체를 반환합니다. 출력 폴더 'outputFolder'이 존재하는지 확인합니다. 존재하지 않는 경우, Directory.CreateDirectory() 메서드를 사용하여 생성합니다.

콘솔 출력

C#를 사용하여 PowerPoint를 이미지로 변환하는 방법: 그림 5 - 콘솔 출력.

프레젠테이션의 각 슬라이드를 반복하기 위해 for 루프를 사용합니다. pptPresentation은 총 슬라이드 수를 Slides.Count 속성을 사용하여 제공합니다. 우리는 각 슬라이드 사진의 출력 경로를 만들기 위해 출력 폴더 경로와 슬라이드 인덱스를 사용합니다 (예: Slide{i}.png). 다음으로, 우리는 pptPresentation를 사용하여 PowerPoint 슬라이드를 사진으로 내보냅니다 (이 예에서는 PNG 이미지 형식으로) Export() 기능을 사용하여. 매개변수는 그림 형식("png" 형식)과 크기(너비: 1024, 높이: 768)입니다. 마지막으로, pptPresentation.Close()를 사용하여 프레젠테이션을 종료하고 pptApplication.Quit()를 사용하여 PowerPoint 세션을 종료합니다. 시스템 리소스를 적절히 해제하기 위해 Quit()을 사용합니다.

출력 - PowerPoint를 PNG 이미지로 변환

C#를 사용하여 PowerPoint를 이미지로 변환하는 방법: 그림 6 - PNG 이미지 출력으로 내보낸 PowerPoint 슬라이드.

IronPPT

IronPPT는 C# 또는 VB.NET을 사용하여 PowerPoint (PPT/PPTX) 파일을 작업하기 위한 Iron Software의 전 for .NET 라이브러리입니다—Microsoft Office 또는 Office Interop 구성 요소 없이.

주요 특징

  • 오피스가 필요 없는 PowerPoint 처리: 모든 .NET 플랫폼(Windows, macOS, Linux, Docker, Azure)에서 PowerPoint가 설치되어 있지 않아도 .pptx( 및 .ppt) 파일을 로드, 편집 또는 생성할 수 있습니다.
  • 슬라이드 유형 및 레이아웃 크기, 방향, 배경 및 마스터 레이아웃 포함 제어.
  • 풍부한 콘텐츠 지원: 텍스트 추가 및 스타일 지정(글꼴, 크기, 색상, 정렬), 도형 그리기, 이미지 삽입, 차트 또는 표 구성—모두 유연한 API와 함께.
  • 고품질 이미지 내보내기:Slide는 사용자 정의 해상도로 PNG 또는 JPEG 형식으로 Save() 또는 Export() 메서드를 사용하여 저장할 수 있습니다 (예: presentation.Save("Slide1.png", width:1200, height:800)).
  • 다양한 .NET 버전 지원: .NET Framework 4.6.2+, .NET Core 3.1, .NET 5–9, 그리고 Azure 또는 컨테이너 환경의 .NET 6/7/8.
  • 서버 안전 및 스레드 친화적: 백그라운드 서비스, 웹 API, 또는 CI/CD 워크로드에 이상적입니다.

IronPPT 설치

프로젝트에 NuGet 패키지를 다음 중 하나를 사용하여 추가합니다:

Install-Package IronPPT

또는 Visual Studio의 NuGet 패키지 관리자 GUI를 통해 ("IronPPT"를 검색하세요). 설치 후 다음을 추가하여 가져옵니다:

using IronPPT;
using IronPPT;
$vbLabelText   $csharpLabel

모든 기능을 잠금 해제하려면 라이선스 키를 설정하거나 무료 30일 체험 키를 사용하세요:

IronPPT.License.LicenseKey = "YOUR_LICENSE_KEY";
IronPPT.License.LicenseKey = "YOUR_LICENSE_KEY";
$vbLabelText   $csharpLabel

IronPPT를 사용하여 PowerPoint 슬라이드를 이미지로 변환

IronPPT를 사용하면 슬라이드를 이미지로 변환하는 것이 간편하고 깔끔합니다. 다음은 C# 예제입니다:

using IronPPT;
using System.IO;

// Optional: apply the license key
// IronPPT.License.LicenseKey = "YOUR_LICENSE_KEY";

var presentation = PresentationDocument.Load("input.pptx");

if (!Directory.Exists("images"))
    Directory.CreateDirectory("images");

for (int i = 0; i < presentation.Slides.Count; i++)
{
    var slide = presentation.Slides[i];
    string filePath = Path.Combine("images", $"slide{i+1}.png");
    slide.SaveAsImage(filePath, width: 1024, height: 768);
}

presentation.Close();
using IronPPT;
using System.IO;

// Optional: apply the license key
// IronPPT.License.LicenseKey = "YOUR_LICENSE_KEY";

var presentation = PresentationDocument.Load("input.pptx");

if (!Directory.Exists("images"))
    Directory.CreateDirectory("images");

for (int i = 0; i < presentation.Slides.Count; i++)
{
    var slide = presentation.Slides[i];
    string filePath = Path.Combine("images", $"slide{i+1}.png");
    slide.SaveAsImage(filePath, width: 1024, height: 768);
}

presentation.Close();
$vbLabelText   $csharpLabel

이 접근 방식은 COM을 완전히 피합니다. IronPPT는 내부적으로 페이지 매김, 벡터 스케일링, 이미지 렌더링을 처리하여 이미지가 PowerPoint의 느낌과 일치하게 만듭니다.

더 고급 사용을 위해 슬라이드 순서를 제어하고, 템플릿을 재사용하고, 표나 차트를 추가하거나 사용자 정의 SVG/벡터 이미지를 삽입할 수 있습니다 (전체 클래스 및 메서드 분류는 상세 API 참조를 참조하십시오).

결론

많은 현대 .NET 응용 프로그램에서 PowerPoint 프레젠테이션을 이미지로 변환하는 것은 필수적입니다—문서 미리 보기, 자동 보고 또는 다운스트림 처리에. Microsoft Office Interop 구성 요소를 이 작업에 사용할 수 있지만 많은 제한 사항이 따라옵니다—Office 설치, 안정성 문제, 라이선스 문제 및 플랫폼 제약.

대신, IronPPT는 .pptx 파일을 이미지로 변환하는 데 완전한 기능을 갖춘, 고성능의, 플랫폼 간 API를 제공합니다. 데스크톱 클라이언트, 웹 API 또는 무인 서버 환경에서 작업하든 상관없이 IronPPT는 Office가 필요 없이 동일한 충실도와 제어를 제공합니다. Interop 기반 코드를 IronPPT로 대체하고 PowerPoint 미리 보기를 더 빠르고, 더 안정적으로, 그리고 완전한 .NET 제어로 생성하십시오.

IronPPT API Reference를 방문하거나 자세한 코드 예시(및 llms.txt 인덱스 포함)를 보려면 탐색할 수 있는 추가 기능을 확인하십시오. 무료 체험판을 제공합니다—한번 시도해 보시고 PowerPoint-이미지 변환을 오늘 .NET 도구 모음에 추가하세요!

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me