.NET에서 프레젠테이션 텍스트 형식 지정

개요

이 문서는 Aspose.Slides for .NET을 사용하여 PowerPoint 및 OpenDocument 프레젠테이션에서 텍스트를 서식 지정하는 방법을 보여줍니다. 배경 색, 투명도, 문자 간격, 글꼴 속성, 회전, 단락 간격, 자동 맞춤 동작, 텍스트 앵커링, 탭 정지 및 언어 설정을 다룹니다.

특별히 명시되지 않는 한, 예제에서는 sample.pptx를 사용합니다. 첫 번째 슬라이드의 첫 번째 도형은 텍스트 상자이며, 첫 번째 단락에 아래에 표시된 텍스트가 포함됩니다. 슬라이드와 도형 인덱스는 0부터 시작합니다. 굵은 부분을 선택하는 예제는 효과적인 서식(상속된 굵은 서식 포함)을 사용합니다:

샘플 텍스트

텍스트 검색 및 바꾸기에 대한 자세한 내용은 텍스트 검색 및 바꾸기를 참조하세요.

텍스트 배경 색 설정

IParagraphFormat.DefaultPortionFormat을 사용하여 단락의 기본 강조 색을 설정하거나, 개별 텍스트 부분에 대해서는 IBasePortionFormat.HighlightColor를 사용할 수 있습니다.

다음 예제는 첫 번째 단락에 연한 회색 강조를 기본값으로 설정합니다. 개별 부분에 지정된 강조 색이 이 기본값보다 우선합니다:

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

// 전체 단락에 대한 강조 색상을 설정합니다.
paragraph.ParagraphFormat.DefaultPortionFormat.HighlightColor.Color = Color.LightGray;

presentation.Save("gray_paragraph.pptx", SaveFormat.Pptx);

결과:

회색 단락

다음 코드 예제는 굵은 글꼴이 적용된 텍스트 부분에 대한 배경 색을 설정하는 방법을 보여 줍니다:

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

foreach (var portion in paragraph.Portions)
{
    if (portion.PortionFormat.GetEffective().FontBold)
    {
        // 텍스트 부분에 대한 강조 색상을 설정합니다.
        portion.PortionFormat.HighlightColor.Color = Color.LightGray;
    }
}

presentation.Save("gray_text_portions.pptx", SaveFormat.Pptx);

결과:

회색 텍스트 부분

텍스트 단락 정렬

IParagraphFormat.Alignment을 사용하여 텍스트 프레임 내에서 단락 정렬을 설정합니다. 값은 중앙 정렬, 왼쪽 정렬, 오른쪽 정렬, 양쪽 정렬 등일 수 있습니다.

다음 코드 예제는 단락을 가운데에 정렬하는 방법을 보여 줍니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

// 단락의 정렬을 가운데로 설정합니다.
paragraph.ParagraphFormat.Alignment = TextAlignment.Center;

presentation.Save("aligned_paragraph.pptx", SaveFormat.Pptx);

결과:

정렬된 단락

라인 내 글꼴 정렬

IParagraphFormat.FontAlignment을 사용하여 한 줄 내에서 서로 다른 글꼴 크기의 텍스트 부분을 수직 정렬합니다. 이 설정은 전체 단락에 적용되며 각 줄 내에서 정렬을 제어합니다.

다음 자체 포함 예제는 하나의 슬라이드에 네 개의 레이블이 있는 텍스트 상자를 만들며, 각 단락은 18, 36, 54 포인트의 동일한 텍스트를 서로 다른 글꼴 정렬과 함께 포함합니다. Arial을 사용하고 자동 맞춤 및 줄바꿈을 비활성화했으며, 텍스트 프레임을 한 줄에 맞게 충분히 크게 유지합니다.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var alignments = new[] { FontAlignment.Baseline, FontAlignment.Top, FontAlignment.Center, FontAlignment.Bottom };
var fontSizes = new[] { 18f, 36f, 54f };

for (var i = 0; i < alignments.Length; i++)
{
    var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 20 + i * 130, 660, 120);
    shape.FillFormat.FillType = FillType.NoFill;
    shape.LineFormat.FillFormat.FillType = FillType.NoFill;

    var textFrame = shape.TextFrame;
    textFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
    textFrame.TextFrameFormat.AutofitType = TextAutofitType.None;
    textFrame.TextFrameFormat.WrapText = NullableBool.False;

    var label = textFrame.Paragraphs[0];
    label.Text = alignments[i].ToString();
    label.ParagraphFormat.Alignment = TextAlignment.Left;
    label.ParagraphFormat.DefaultPortionFormat.FontHeight = 14;
    label.ParagraphFormat.DefaultPortionFormat.LatinFont = new FontData("Arial");
    label.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
    label.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;

    var paragraph = new Paragraph();
    paragraph.ParagraphFormat.FontAlignment = alignments[i];
    paragraph.ParagraphFormat.Alignment = TextAlignment.Left;
    paragraph.ParagraphFormat.DefaultPortionFormat.LatinFont = new FontData("Arial");
    paragraph.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
    paragraph.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;

    foreach (var fontSize in fontSizes)
    {
        var portion = new Portion("Ag ");
        portion.PortionFormat.FontHeight = fontSize;
        paragraph.Portions.Add(portion);
    }

    textFrame.Paragraphs.Add(paragraph);
}

presentation.Save("font_alignment.pptx", SaveFormat.Pptx);

결과:

혼합 글꼴 크기의 기준선, 위쪽, 가운데, 아래쪽 글꼴 정렬 비교

글꼴 정렬은 글꼴 메트릭을 사용하므로 개별 문자 가장자리들이 정확히 일치하지 않을 수 있습니다. 예제에는 대문자와 디센더가 모두 포함되어 기준선과 아래쪽 정렬 차이를 보여 줍니다. 글꼴 가용성 및 대체, 사용된 문자 및 글꼴 크기 차이가 결과에 영향을 줍니다. 프레임 크기, 여백, 줄 간격, 줄바꿈 및 자동 맞춤도 레이아웃에 영향을 미치므로 모드를 비교할 때는 동일한 글꼴 및 레이아웃 설정을 사용하십시오.

이 설정은 수평 단락 정렬을 제어하는 IParagraphFormat.Alignment 및 텍스트 블록을 도형 내부에서 수직 위치시키는 ITextFrameFormat.AnchoringType와 다릅니다. IBasePortionFormat.Escapement를 통한 위첨자·아래첨자 서식은 개별 부분을 기준선에 상대적으로 이동시키며, 단락 줄에 대한 글꼴 정렬을 설정하지는 않습니다.

텍스트 투명도 설정

텍스트 투명도는 IBasePortionFormat.FillFormat에 할당된 색상의 알파 구성 요소를 통해 제어됩니다. 아래 예제에서는 alpha = 50이 0–255 범위의 ARGB 알파 채널 값이며, 투명도 퍼센트가 아님을 유의하십시오.

다음 코드 예제는 전체 단락에 투명도를 적용하는 방법을 보여 줍니다:

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

var alpha = 50;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

// 텍스트에 반투명 검정 채우기를 설정합니다.
paragraph.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
paragraph.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.FromArgb(alpha, Color.Black);

presentation.Save("transparent_paragraph.pptx", SaveFormat.Pptx);

결과:

투명한 단락

다음 코드 예제는 굵은 글꼴이 적용된 텍스트 부분에 투명도를 적용하는 방법을 보여 줍니다:

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

var alpha = 50;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

foreach (var portion in paragraph.Portions)
{
    if (portion.PortionFormat.GetEffective().FontBold)
    {
        // 텍스트 부분의 투명도를 설정합니다.
        portion.PortionFormat.FillFormat.FillType = FillType.Solid;
        portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.FromArgb(alpha, Color.Black);
    }
}

presentation.Save("transparent_text_portions.pptx", SaveFormat.Pptx);

결과:

투명한 텍스트 부분

텍스트 문자 간격 설정

IBasePortionFormat.Spacing을 사용하여 텍스트 상자 내 문자 간격을 넓히거나 좁힐 수 있습니다. 아래 예제는 3포인트 간격을 추가하며, 음수 값은 텍스트를 압축합니다.

다음 C# 코드는 전체 단락의 문자 간격을 확장하는 방법을 보여 줍니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

// 참고: 문자 간격을 압축하려면 음수 값을 사용하세요.
paragraph.ParagraphFormat.DefaultPortionFormat.Spacing = 3;  // 문자 간격을 확장합니다.

presentation.Save("character_spacing_in_paragraph.pptx", SaveFormat.Pptx);

결과:

단락의 문자 간격

다음 코드 예제는 굵은 글꼴이 적용된 텍스트 부분의 문자 간격을 확장하는 방법을 보여 줍니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

foreach (var portion in paragraph.Portions)
{
    if (portion.PortionFormat.GetEffective().FontBold)
    {
        // 참고: 문자 간격을 압축하려면 음수 값을 사용하세요.
        portion.PortionFormat.Spacing = 3;  // 문자 간격을 확장합니다.
    }
}

presentation.Save("character_spacing_in_text_portions.pptx", SaveFormat.Pptx);

결과:

텍스트 부분의 문자 간격

특정 글꼴에 대한 커닝 비활성화

일부 경우 Aspose.Slides가 렌더링한 텍스트가 PowerPoint에서 표시되는 텍스트보다 약간 더 조밀하게 보일 수 있습니다. 이는 PowerPoint가 특정 글꼴에 대해 커닝 데이터를 무시하기 때문일 수 있습니다(글꼴에 유효한 커닝 정보가 있고 PowerPoint 설정에서 커닝이 활성화된 경우에도).

이러한 경우 PowerPoint와 더 가깝게 렌더링하려면 해당 글꼴을 사용하는 텍스트 부분에 대해 커닝을 비활성화할 수 있습니다. IBasePortionFormat.KerningMinimalSize를 실제 글꼴 크기보다 큰 값으로 설정하십시오. 이 예제는 첫 번째 슬라이드의 첫 번째 도형에 텍스트 상자가 있는 "presentation.pptx"가 필요합니다. 효과적인 글꼴 이름(상속된 글꼴 포함)을 검사하고, Roboto를 사용하는 부분에 대해 100포인트 임계값을 설정합니다. 이를 통해 100포인트 미만의 글꼴 크기를 가진 해당 부분의 커닝이 비활성화됩니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("presentation.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var targetFont = "Roboto";

foreach (var paragraph in autoShape.TextFrame.Paragraphs)
{
    foreach (var portion in paragraph.Portions)
    {
        var textFormat = portion.PortionFormat.GetEffective();
        
        var usesTargetFont = textFormat.LatinFont?.FontName == targetFont || 
            textFormat.EastAsianFont?.FontName == targetFont || 
            textFormat.ComplexScriptFont?.FontName == targetFont;

        if (usesTargetFont)
        {
            portion.PortionFormat.KerningMinimalSize = 100;
        }
    }
}

presentation.Save("output.pptx", SaveFormat.Pptx);

임계값 이하의 일치 텍스트에 대해 이 설정은 커닝을 방지하고, PowerPoint의 특정 동작으로 영향을 받는 글꼴에 대해 Aspose.Slides 렌더링을 PowerPoint 시각 출력과 맞추는 데 도움이 될 수 있습니다.

텍스트 글꼴 속성 관리

글꼴 속성은 IParagraphFormat.DefaultPortionFormat을 통해 단락 수준에서 설정하거나, 개별 부분에 대해서는 IPortionFormat을 통해 설정할 수 있습니다.

다음 예제는 첫 번째 단락의 기본 글꼴을 12포인트 Times New Roman으로 설정하고 굵게, 기울임꼴, 점선 밑줄 서식을 적용합니다. 개별 부분에 대한 명시적 서식이 이러한 기본값보다 우선합니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

// 단락의 글꼴 속성을 설정합니다.
var portionFormat = paragraph.ParagraphFormat.DefaultPortionFormat;
portionFormat.FontHeight = 12;
portionFormat.FontBold = NullableBool.True;
portionFormat.FontItalic = NullableBool.True;
portionFormat.FontUnderline = TextUnderlineType.Dotted;
portionFormat.LatinFont = new FontData("Times New Roman");

presentation.Save("font_properties_for_paragraph.pptx", SaveFormat.Pptx);

결과:

단락의 글꼴 속성

다음 예제는 효과적인 서식이 굵게인 부분에 13포인트 Times New Roman, 기울임꼴 및 점선 밑줄을 적용합니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

foreach (var portion in paragraph.Portions)
{
    if (portion.PortionFormat.GetEffective().FontBold)
    {
        // 텍스트 부분에 대한 글꼴 속성을 설정합니다.
        portion.PortionFormat.FontHeight = 13;
        portion.PortionFormat.FontItalic = NullableBool.True;
        portion.PortionFormat.FontUnderline = TextUnderlineType.Dotted;
        portion.PortionFormat.LatinFont = new FontData("Times New Roman");
    }
}

presentation.Save("font_properties_for_text_portions.pptx", SaveFormat.Pptx);

결과:

텍스트 부분의 글꼴 속성

텍스트 높이 정규화 제어

템플릿 타이포그래피를 재현하거나 문자 높이 차이를 조사할 때 IBasePortionFormat.NormaliseHeight를 사용합니다. PowerPoint에서 정규화를 활성화하면 개별 문자를 수직으로 늘이거나 압축하여 텍스트 부분 내에서 고르게 보이는 높이를 만들지만, 서로 다른 글꼴 간에 동일한 텍스트 높이를 보장하지는 않습니다.

속성을 NullableBool.True 또는 False로 설정하여 정규화를 명시적으로 활성화하거나 비활성화할 수 있습니다. NullableBool.NotDefined는 로컬 설정을 하지 않아 부분이 단락의 DefaultPortionFormat 등에서 값을 상속하도록 합니다. 이는 False와 동일한 의미가 아닙니다. 해결된 Boolean 값을 얻으려면 IPortionFormat.GetEffective를 사용하고 IBasePortionFormatEffectiveData.NormaliseHeight를 읽으세요.

다음 자체 포함 예제는 Arial이 설치되어 있어야 합니다. 54포인트에서 동일한 대문자, 소문자, 디센더 및 악센트 문자를 포함하는 두 개의 텍스트 블록을 만들며, 두 단락 모두 기본적으로 정규화를 활성화합니다. 상단 부분은 명시적으로 비활성화하고, 하단 부분은 상속받습니다. 프레임 크기, 여백 및 단락 간격은 동일하고, 줄바꿈 및 자동 맞춤을 비활성화하여 비교를 일관되게 유지합니다. 예제는 False: False와 NotDefined: True를 출력한 뒤 “text_height_normalization.pptx"를 저장합니다.

using System;
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var settings = new[] { NullableBool.False, NullableBool.NotDefined };

for (var i = 0; i < settings.Length; i++)
{
    var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 60 + i * 200, 660, 150);
    shape.FillFormat.FillType = FillType.NoFill;
    shape.LineFormat.FillFormat.FillType = FillType.NoFill;

    var textFrame = shape.TextFrame;
    textFrame.Text = "Hxgjpq ÅÉ 0123";
    textFrame.TextFrameFormat.AutofitType = TextAutofitType.None;
    textFrame.TextFrameFormat.WrapText = NullableBool.False;
    textFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
    textFrame.TextFrameFormat.MarginTop = 0;
    textFrame.TextFrameFormat.MarginLeft = 0;

    var paragraph = textFrame.Paragraphs[0];
    paragraph.ParagraphFormat.Alignment = TextAlignment.Left;
    paragraph.ParagraphFormat.SpaceBefore = 0;
    paragraph.ParagraphFormat.SpaceAfter = 0;
    paragraph.ParagraphFormat.SpaceWithin = 100;
    paragraph.ParagraphFormat.DefaultPortionFormat.NormaliseHeight = NullableBool.True;

    var portion = paragraph.Portions[0];
    portion.PortionFormat.LatinFont = new FontData("Arial");
    portion.PortionFormat.FontHeight = 54;
    portion.PortionFormat.FillFormat.FillType = FillType.Solid;
    portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
    portion.PortionFormat.NormaliseHeight = settings[i];

    Console.WriteLine($"{settings[i]}: {portion.PortionFormat.GetEffective().NormaliseHeight}");
}

presentation.Save("text_height_normalization.pptx", SaveFormat.Pptx);

아래 비교는 저장된 프레젠테이션에서 내보낸 것입니다. 상단 행은 정규화가 비활성화된(False) 상태이며, 하단 행은 활성화된 설정을 상속받습니다(NotDefined → True). 이 모습을 재현하려면 Arial이 설치되어 있어야 합니다.

Arial 54포인트 텍스트(위는 정규화 비활성화, 아래는 상속된 정규화 활성화)

정규화는 할당된 FontHeight 값(포인트 단위)을 변경하지 않고 문자 높이를 변경합니다. 단락의 SpaceWithin은 줄 간격을 제어하고, 텍스트 프레임의 AutofitType은 텍스트 또는 컨테이너가 맞추도록 조정되는 방식을 제어합니다. 이러한 설정은 서로 다른 목적을 가지며 전체 레이아웃에 독립적으로 영향을 줄 수 있습니다. 단락 서식 및 상속에 대한 자세한 내용은 Manage Paragraph를 참조하세요.

취소선 적용 및 제거

텍스트 부분에 IBasePortionFormat.StrikethroughType을 사용하면 원본 텍스트를 삭제하지 않고 수정, 취소된 용어 또는 이전 가격을 표시할 수 있습니다. 텍스트에 하나 또는 두 개의 선을 그으려면 각각 TextStrikethroughType.Single 또는 Double을 설정합니다.

취소선을 제거하려면 TextStrikethroughType.None을 할당하십시오. 이는 주변 서식이 취소선을 지정하더라도 효과를 명시적으로 비활성화합니다. 반대로 TextStrikethroughType.NotDefined는 로컬 설정을 정의하지 않아 부분이 예를 들어 단락에서 서식을 상속하도록 합니다. 이는 취소선이 반드시 제거된다는 것을 보장하지 않습니다. 결과 서식(상속된 값 포함)을 읽으려면 IPortionFormat.GetEffective를 사용하십시오.

다음 자체 포함 예제는 세 개의 가격 비교를 생성합니다. 각 단락은 레이블, 이전 가격, 현재 가격을 위한 별도 부분을 가지고 있어 이전 가격에만 영향을 줍니다. 첫 번째 행은 취소선을 적용했다가 제거하고, 다른 행들은 각각 하나와 두 개의 취소선을 유지합니다. 이 속성을 변경해도 텍스트와 다른 서식(예: 굵은 이전 가격)은 보존됩니다.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 620, 220);
shape.FillFormat.FillType = FillType.NoFill;
shape.LineFormat.FillFormat.FillType = FillType.NoFill;
shape.TextFrame.Paragraphs.Clear();

var labels = new[] { "None: ", "Single: ", "Double: " };

foreach (var label in labels)
{
    var paragraph = new Paragraph();
    paragraph.ParagraphFormat.Alignment = TextAlignment.Left;
    paragraph.ParagraphFormat.SpaceAfter = 20;

    var format = paragraph.ParagraphFormat.DefaultPortionFormat;
    format.FontHeight = 28;
    format.LatinFont = new FontData("Arial");
    format.FillFormat.FillType = FillType.Solid;
    format.FillFormat.SolidFillColor.Color = Color.Black;

    paragraph.Portions.Add(new Portion(label));

    var previousPrice = new Portion("$100");
    previousPrice.PortionFormat.FontBold = NullableBool.True;
    paragraph.Portions.Add(previousPrice);
    paragraph.Portions.Add(new Portion(" → $80"));
    
    shape.TextFrame.Paragraphs.Add(paragraph);
}

var paragraphs = shape.TextFrame.Paragraphs;

// 취소선을 적용한 후 첫 번째 이전 가격에서 명시적으로 제거합니다.
paragraphs[0].Portions[1].PortionFormat.StrikethroughType = TextStrikethroughType.Single;
paragraphs[0].Portions[1].PortionFormat.StrikethroughType = TextStrikethroughType.None;

paragraphs[1].Portions[1].PortionFormat.StrikethroughType = TextStrikethroughType.Single;
paragraphs[2].Portions[1].PortionFormat.StrikethroughType = TextStrikethroughType.Double;

presentation.Save("strikethrough.pptx", SaveFormat.Pptx);

결과(위에서 아래 순서): 취소선 없음, 하나의 취소선, 두 개의 취소선.

취소선 없는 이전 가격, 하나의 취소선, 두 개의 취소선

텍스트 회전 설정

ITextFrameFormat.TextVerticalType을 사용하여 도형 내에서 미리 정의된 텍스트 방향을 설정합니다.

다음 코드 예제는 도형의 텍스트 방향을 TextVerticalType.Vertical270으로 설정합니다. 이는 텍스트를 시계 반대 방향으로 90도 회전시킵니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
autoShape.TextFrame.TextFrameFormat.TextVerticalType = TextVerticalType.Vertical270;

presentation.Save("text_rotation.pptx", SaveFormat.Pptx);

결과:

텍스트 회전

텍스트 프레임 사용자 정의 회전 설정

ITextFrameFormat.RotationAngle을 사용하여 ITextFrame에 대한 사용자 정의 회전 각도를 설정합니다.

다음 코드 예제는 도형 내에서 텍스트 프레임을 시계 방향으로 3도 회전시킵니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
autoShape.TextFrame.TextFrameFormat.RotationAngle = 3;

presentation.Save("custom_text_rotation.pptx", SaveFormat.Pptx);

결과:

사용자 정의 텍스트 회전

단락 줄 간격 설정

Aspose.Slides는 IParagraphFormat.SpaceAfter, IParagraphFormat.SpaceBefore, 그리고 IParagraphFormat.SpaceWithin을 제공하여 단락 간격을 제어합니다. 사용 방법은 다음과 같습니다:

  • 양의 값을 사용하면 줄 간격을 줄 높이의 백분율로 지정합니다.
  • 음의 값을 사용하면 줄 간격을 포인트 단위로 지정합니다.

다음 예제는 첫 번째 단락의 내부 간격을 줄 높이의 200%(두 배 간격)로 설정합니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];

paragraph.ParagraphFormat.SpaceWithin = 200;

presentation.Save("line_spacing.pptx", SaveFormat.Pptx);

결과:

단락 내 줄 간격

줄 바꿈 제어

줄 바꿈 규칙은 좁은 텍스트 블록이나 라틴어와 동아시아 텍스트가 혼합된 프레젠테이션에서 유용합니다. 아래 속성들은 IParagraphFormat에 속하므로 전체 단락에 적용됩니다:

  • LatinLineBreak은 라틴어 줄 바꿈 규칙을 제어합니다. 혼합 텍스트에서는 인접한 동아시아 텍스트 및 구두점의 줄 바꿈 위치도 변경될 수 있습니다.
  • EastAsianLineBreak은 동아시아 줄 바꿈 규칙을 제어하며, 줄 시작 및 끝에 허용되지 않는 문자에 대한 제한을 포함합니다.

이 규칙들은 ITextFrameFormat.WrapText을 대체하지 않으며, 자동 줄바꿈을 활성화합니다. 규칙은 줄바꿈이 발생할 때 레이아웃에 영향을 미치지만 줄바꿈 문자를 삽입하지는 않습니다. 명시적 줄바꿈은 가용 폭과 무관하게 단락 내에서 새로운 줄을 강제합니다.

다음 자체 포함 예제는 중국어와 라틴어 텍스트가 포함된 좁은 텍스트 블록을 만들고 두 줄 바꿈 속성을 명시적으로 설정한 뒤 “line_breaking.pptx"로 저장합니다. 어느 규칙을 실험하려면 다른 속성 값을 변경하고 나머지는 고정하세요. 예제는 24포인트 Arial 및 SimSun을 사용하고 프레임 너비 160포인트, 수평 마진 0으로 설정합니다. ITextFrameFormat.AutofitType은 TextAutofitType.None으로 설정하여 텍스트 크기와 프레임 크기가 고정됩니다.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 160, 300);
shape.FillFormat.FillType = FillType.NoFill;

var textFrame = shape.TextFrame;
textFrame.TextFrameFormat.WrapText = NullableBool.True;
textFrame.TextFrameFormat.AutofitType = TextAutofitType.None;
textFrame.TextFrameFormat.MarginLeft = 0;
textFrame.TextFrameFormat.MarginRight = 0;

var paragraph = textFrame.Paragraphs[0];
paragraph.Text = "中文排版测试,PowerPoint 中文演示。";

var format = paragraph.ParagraphFormat;
format.Alignment = TextAlignment.Left;
format.DefaultPortionFormat.FontHeight = 24;
format.DefaultPortionFormat.LatinFont = new FontData("Arial");
format.DefaultPortionFormat.EastAsianFont = new FontData("SimSun");
format.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
format.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
format.LatinLineBreak = NullableBool.False;
format.EastAsianLineBreak = NullableBool.True;

presentation.Save("line_breaking.pptx", SaveFormat.Pptx);

행 말 부호 매달기 제어

IParagraphFormat.HangingPunctuation을 사용하면 해당 구두점이 텍스트 라인의 오른쪽 가장자리를 넘어 확장될 수 있어 다음 줄을 차지하지 않게 합니다. 이는 전체 단락에 적용되며, 매달린 들여쓰기와는 다릅니다.

다음 자체 포함 예제는 100포인트 너비 텍스트 프레임에서 행 말 부호 매달기를 활성화하고 “hanging_punctuation.pptx"로 저장합니다. 24포인트 Arial과 수평 마진 0을 사용하면 마지막 마침표가 “sentence” 뒤에 남으며 오른쪽 텍스트 가장자를 넘어 확장됩니다. 비교를 위해 속성을 NullableBool.False로 설정하면 마침표가 별도 줄에 표시됩니다. 폭을 고정하기 위해 줄바꿈을 활성화하고 자동 맞춤을 비활성화했습니다.

using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
var slide = presentation.Slides[0];

var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 50, 50, 100, 200);
shape.FillFormat.FillType = FillType.NoFill;

var textFrame = shape.TextFrame;
textFrame.TextFrameFormat.WrapText = NullableBool.True;
textFrame.TextFrameFormat.AutofitType = TextAutofitType.None;
textFrame.TextFrameFormat.MarginLeft = 0;
textFrame.TextFrameFormat.MarginRight = 0;

var paragraph = textFrame.Paragraphs[0];
paragraph.Text = "Simple text, next sentence.";

var format = paragraph.ParagraphFormat;
format.Alignment = TextAlignment.Left;
format.DefaultPortionFormat.FontHeight = 24;
format.DefaultPortionFormat.LatinFont = new FontData("Arial");
format.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
format.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
format.HangingPunctuation = NullableBool.True;

presentation.Save("hanging_punctuation.pptx", SaveFormat.Pptx);

모든 구두점이 매달릴 수 있는 것은 아닙니다. 위의 줄 바꿈 섹션에서 설명한 글꼴 및 레이아웃 조건도 이 비교에 적용됩니다. 글꼴, 가용 폭, 여백 또는 자동 맞춤 설정을 변경하면 눈에 보이는 차이가 사라질 수 있습니다.

텍스트 프레임 자동 맞춤 유형 설정

ITextFrameFormat.AutofitType은 텍스트가 컨테이너 경계를 초과할 때 텍스트가 어떻게 동작할지를 결정합니다. 텍스트를 축소하거나 넘치게 하거나 도형을 자동으로 크기 조정하도록 제어할 수 있습니다. 다음 예제는 텍스트에 맞게 도형을 자동으로 크기 조정하도록 구성하고 결과를 “autofit_type.pptx"에 저장합니다.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
autoShape.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Shape;

presentation.Save("autofit_type.pptx", SaveFormat.Pptx);

자동 줄바꿈 후 라인 수를 확인하고 텍스트 또는 도형 너비가 결과에 어떻게 영향을 미치는지 보려면 Count Rendered Lines를 참조하십시오. 라인 수만으로 텍스트가 컨테이너를 넘는지 여부를 판단할 수 없습니다.

텍스트 프레임 앵커 설정

ITextFrameFormat.AnchoringType은 텍스트가 도형 내부에서 수직으로 어떻게 배치되는지를 정의합니다(예: 상단, 중간, 하단). 다음 예제는 텍스트를 첫 번째 도형의 하단에 앵커하고 결과를 “text_anchor.pptx"에 저장합니다.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
autoShape.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Bottom;

presentation.Save("text_anchor.pptx", SaveFormat.Pptx);

텍스트 탭 설정

IParagraphFormat.DefaultTabSize 및 IParagraphFormat.Tabs을 사용하여 단락 내 탭 정지를 구성합니다. 다음 예제는 기본 탭 간격을 100포인트로 설정하고 30포인트에 왼쪽 정렬 탭 정지를 추가합니다. 이러한 설정은 탭 문자를 포함한 텍스트에 영향을 줍니다.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("sample.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];
paragraph.ParagraphFormat.DefaultTabSize = 100;
paragraph.ParagraphFormat.Tabs.Add(30, TabAlignment.Left);

presentation.Save("paragraph_tabs.pptx", SaveFormat.Pptx);

결과:

단락 탭

교정 언어 설정

Aspose.Slides는 IBasePortionFormat.LanguageId을 제공하여 텍스트 부분에 대한 교정 언어를 설정할 수 있습니다. 교정 언어는 PowerPoint에서 철자 및 문법 검사를 수행할 때 사용되는 언어를 결정합니다.

다음 예제는 첫 번째 슬라이드의 첫 번째 도형에 텍스트 상자가 있는 “presentation.pptx"가 필요합니다. 첫 번째 단락의 내용을 “1。“으로 교체하고 글꼴을 SimSun으로 설정한 뒤, 교정 언어를 간체 중국어(zh-CN)로 지정합니다. 결과를 “proofing_language.pptx"로 저장합니다:

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation("presentation.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var paragraph = autoShape.TextFrame.Paragraphs[0];
paragraph.Portions.Clear();

var font = new FontData("SimSun");

var textPortion = new Portion();
textPortion.PortionFormat.ComplexScriptFont = font;
textPortion.PortionFormat.EastAsianFont = font;
textPortion.PortionFormat.LatinFont = font;

// 교정 언어를 간체 중국어로 설정합니다.
textPortion.PortionFormat.LanguageId = "zh-CN";

textPortion.Text = "1。";
paragraph.Portions.Add(textPortion);

presentation.Save("proofing_language.pptx", SaveFormat.Pptx);

기본 언어 설정

LoadOptions.DefaultTextLanguage을 사용하여 프레젠테이션을 로드하거나 만들 때 생성되는 텍스트의 기본 언어를 정의합니다. 다음 예제는 기본 텍스트 언어를 미국 영어로 설정한 프레젠테이션을 만든 뒤 텍스트 상자를 추가하고 첫 번째 텍스트 부분에 대해 en-US를 출력합니다.

using System;
using Aspose.Slides;

var loadOptions = new LoadOptions();
loadOptions.DefaultTextLanguage = "en-US";

using var presentation = new Presentation(loadOptions);
var slide = presentation.Slides[0];

// 텍스트가 포함된 새 사각형 도형을 추가합니다.
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 150, 50);
shape.TextFrame.Text = "Sample text";

// 첫 번째 부분의 언어를 확인합니다.
var portion = shape.TextFrame.Paragraphs[0].Portions[0];
Console.WriteLine(portion.PortionFormat.LanguageId);

기본 텍스트 스타일 설정

프레젠테이션 수준에서 기본 텍스트 서식을 적용하려면 IPresentation.DefaultTextStyle을 사용합니다.

다음 예제는 새 프레젠테이션의 최상위 단락에 대해 14포인트 굵은 글꼴을 기본값으로 설정하고 “default_text_style.pptx"에 저장합니다. 텍스트는 더 구체적인 서식이 없을 경우 이러한 기본값을 상속받을 수 있습니다.

using Aspose.Slides;
using Aspose.Slides.Export;

using var presentation = new Presentation();
// 상위 수준 단락 형식을 가져옵니다.
var paragraphFormat = presentation.DefaultTextStyle.GetLevel(0);

if (paragraphFormat != null)
{
    paragraphFormat.DefaultPortionFormat.FontHeight = 14;
    paragraphFormat.DefaultPortionFormat.FontBold = NullableBool.True;
}

presentation.Save("default_text_style.pptx", SaveFormat.Pptx);

대문자 효과가 적용된 텍스트 추출

PowerPoint에서 All Caps 폰트 효과를 적용하면 원본이 소문자였더라도 슬라이드에서는 대문자로 표시됩니다. Aspose.Slides로 해당 텍스트 부분을 가져오면 라이브러리는 입력된 그대로의 텍스트를 반환합니다. 표시된 텍스트와 일치시키려면 TextCapType을 확인하고 값이 All인 경우 반환된 문자열을 대문자로 변환하세요.

이 예제는 첫 번째 슬라이드의 첫 번째 도형에 텍스트 상자가 있는 “sample2.pptx"가 필요합니다. 첫 번째 단락의 첫 번째 부분에 All Caps 효과가 적용된 “Hello, Aspose!“가 포함되어 있습니다(아래 그림 참조).

대문자 효과

다음 코드 예제는 All Caps 효과가 적용된 텍스트를 추출하는 방법을 보여 줍니다:

using System;
using Aspose.Slides;

using var presentation = new Presentation("sample2.pptx");
var slide = presentation.Slides[0];

var autoShape = (IAutoShape)slide.Shapes[0];
var textPortion = autoShape.TextFrame.Paragraphs[0].Portions[0];

Console.WriteLine($"Original text: {textPortion.Text}");

var textFormat = textPortion.PortionFormat.GetEffective();
if (textFormat.TextCapType == TextCapType.All)
{
    var text = textPortion.Text.ToUpper();
    Console.WriteLine($"All-Caps effect: {text}");
}

출력:

Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!

자주 묻는 질문

슬라이드의 표에서 텍스트를 수정하려면 어떻게 해야 합니까?

슬라이드의 표에서 텍스트를 수정하려면 ITable을 사용합니다. 셀을 순회하면서 각 셀을 ICell.TextFrame을 통해 업데이트하고, 단락 서식은 IParagraph.ParagraphFormat을 통해 지정합니다.

PowerPoint 슬라이드의 텍스트에 그라디언트 색을 적용하려면 어떻게 해야 합니까?

텍스트에 그라디언트 색을 적용하려면 IBasePortionFormat.FillFormat을 사용합니다. IFillFormat.FillType을 FillType.Gradient으로 설정하고 그라디언트 정지점, 방향 및 투명도를 구성합니다.

관련 기능: 텍스트 형식 지정.