C# Slide Element Tutorial – IronPPT

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPPT는 .NET C# 개발자가 PowerPoint 프레젠테이션을 만들고, 읽고, 편집하는 기능을 애플리케이션에 원활하게 통합할 수 있도록 설계된 강력한 PowerPoint 라이브러리입니다. 파워포인트 프레젠테이션에서 슬라이드는 콘텐츠를 구성하고 정리하는 데 있어 가장 기본적인 요소입니다.

빠른 시작: 새 슬라이드 또는 기존 슬라이드에 텍스트 삽입

이 예시는 IronPPT를 사용하여 슬라이드에 텍스트를 얼마나 쉽게 추가할 수 있는지 보여줍니다. 단 몇 줄의 코드로, 첫 번째 슬라이드가 있으면 삽입하고, 없으면 새로 만들어서 저장하면 됩니다. 빠르고 간편하게 설정할 수 있습니다.

  1. NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPPT 설치하기

    PM > Install-Package IronPPT
  2. 다음 코드 조각을 복사하여 실행하세요.

    var doc = new IronPPT.PresentationDocument();
    var text = doc.Slides.Count > 0 ? doc.Slides[0].AddText("Quick Option") : doc.Slides.Add(new IronPPT.Models.Slide()).AddText("Quick Option");
    doc.Save("quick.pptx");
  3. 실제 운영 환경에서 테스트할 수 있도록 배포하세요.

    무료 체험판으로 오늘 프로젝트에서 IronPPT 사용 시작하기

    arrow pointer

목차

텍스트 추가

텍스트 내용

새로운 프레젠테이션을 만들거나 기존 프레젠테이션을 편집할 때, 텍스트 관리 도구를 사용하면 텍스트 배치와 서식을 완벽하게 제어할 수 있으므로 메시지를 명확하고 전문적으로 전달하는 슬라이드를 디자인할 수 있습니다.

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-text.cs
using IronPPT;
using IronPPT.Models;

// Create a new PowerPoint presentation
var document = new PresentationDocument();

// Ensure there is at least one slide to work with
if (document.Slides.Count == 0)
{
    document.Slides.Add(new Slide());
}

// Add text to the first slide
var text = document.Slides[0].AddText("Hello");

// Append text to the existing text on the slide
text.Content += " There!";

// Check if there is any text element to remove from the first slide
if (document.Slides[0].Texts.Count > 0)
{
    document.Slides[0].Texts[0].Remove();
}

// Export the PowerPoint presentation with the specified file name
document.Save("addText.pptx");
$vbLabelText   $csharpLabel

스타일링 설정

텍스트 스타일링을 사용하면 글꼴 크기, 색상, 스타일, 취소선, 밑줄과 같은 속성을 정의하여 텍스트의 시각적 모양을 사용자 지정할 수 있습니다. 이러한 스타일을 적용하면 텍스트의 표현이 향상되고 문서의 전체적인 모양이 개선됩니다.

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-text-style.cs
using IronPPT;
using IronPPT.Models; // Ensure the library is available

// Create a new presentation document
var document = new PresentationDocument();

// Define and customize the text style
var textStyle = new TextStyle
{
    IsBold = true,                      // Text is bold
    IsItalic = true,                    // Text is italic
    Color = Color.Blue,                 // Text color is blue
    Strike = StrikeValue.SingleStrike,  // Text is single struck-off
    Outline = true,                     // Text has an outline
    NoProof = true,                     // Disables proofing for the text
    Spacing = 10.0,                     // Text spacing is set to 10
    Underline = new Underline 
    {
        LineValue = UnderlineValues.Single,   // Single underline
        Color = Color.Red                     // Underline color is red
    },
    Languages = "en-US",               // Text language is set to U.S. English
    SpecVanish = false,                // Text does not vanish when special formatting is applied
};

// Create text content and apply the defined style
var text = new Text("Hello World");   // Instantiate text with a string
text.TextStyle = textStyle;           // Apply the defined style to the text

// Add a new slide if none exist
if (document.Slides.Count == 0)
{
    document.Slides.Add(new Slide());   // Add a new slide to the document
}

// Add the styled text to the first slide
document.Slides[0].AddText(text);      // Add the newly created text object to the first slide

// Save the presentation document to a file
document.Save("textStyle.pptx");        // Save the document with the filename "textStyle.pptx"
$vbLabelText   $csharpLabel

이미지 추가

최적의 화면 표시를 위해 이미지 설정을 조정하십시오. 적절한 설정을 통해 이미지가 시각적으로 매력적이고 맥락에 적합하게 보이도록 할 수 있습니다.

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-image.cs
using IronPPT;
using IronPPT.Models;
using System.Drawing;

// This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
// An image is added to the presentation, its properties are modified, and then the presentation is saved.

// Create a new PowerPoint presentation
var document = new PresentationDocument();

// Create a new Image object and load an image file.
var image = new Image();
image.LoadFromFile("sample.png");

// Add the image to the first slide (index 0) of the presentation.
var newImage = document.AddImage(image, 0);

// Set the properties of the added image.
// Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = new Point(200, 200); // Set image position on the slide
newImage.Angle = 45; // Set the rotation angle of the image
newImage.Name = "new image"; // Assign a descriptive name to the image
newImage.Width = 150; // Set the width of the image in pixels
newImage.Height = 150; // Set the height of the image in pixels

// Export the PowerPoint presentation to a file named "addImage.pptx"
document.Save("addImage.pptx");
$vbLabelText   $csharpLabel

도형 추가

프레젠테이션에 도형을 쉽게 추가하고 사용자 지정하려면 도형의 유형, 크기(너비 및 높이), 채우기 및 윤곽선 색상, 슬라이드에서의 위치를 ​​정의하세요.

:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-shape.cs
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;

// Load a PowerPoint presentation.
// The PresentationDocument is assumed to represent an entire PPTX file loaded from disk.
var document = new PresentationDocument("output.pptx");

// Configure a new shape.
// Shape is assumed to be a model object representing drawable elements on a slide.
Shape shape = new Shape
{
    Name = "triangle",
    Type = ShapeType.Triangle,
    Width = 100,
    FillColor = new Color("#444444"),
    OutlineColor = Color.Black,

    // Position is set via assumed X and Y positioning properties.
    // It's important that these properties are set to valid coordinates for display on the slide.
    XPosition = 200,
    YPosition = 200
};

// Add the shape to the first slide in the presentation.
// Slides[0] refers to the first slide in the collection. Ensure a slide exists at this index.
document.Slides[0].AddShape(shape);

// Export the modified PowerPoint presentation.
// Saves the changes to a new file, ensuring the original presentation is not overwritten.
document.Save("addShape.pptx");
$vbLabelText   $csharpLabel
커티스 차우
기술 문서 작성자

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

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

시작할 준비 되셨나요?
Nuget 다운로드 4,319 | 버전: 2026.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronPPT
샘플을 실행하세요 PDF 파일이 편집 가능한 텍스트로 바뀌는 것을 확인하세요.