.NET에서 프레젠테이션 텍스트 서식 지정
개요
이 문서에서는 Aspose.Slides for .NET을 사용하여 PowerPoint 및 OpenDocument 프레젠테이션에서 텍스트를 형식화하는 방법을 보여줍니다. 배경 색상, 투명도, 문자 간격, 글꼴 속성, 회전, 단락 간격, 자동 맞춤 동작, 텍스트 고정, 탭 정지 및 언어 설정을 다룹니다.
다른 언급이 없는 한, 예제는 sample.pptx를 사용합니다. 첫 번째 슬라이드의 첫 번째 도형은 텍스트 상자이며, 첫 번째 단락에 아래에 표시된 텍스트가 포함되어 있습니다. 슬라이드와 도형 인덱스는 모두 0부터 시작합니다. 굵게 표시된 부분을 선택하는 예제는 효과적인 서식을 사용하며, 여기에는 상속된 굵은 서식도 포함됩니다:

텍스트 검색 및 교체를 보려면 Search and Replace Text를 참조하세요.
텍스트 배경 색상 설정
단락에 대한 기본 강조 색상을 설정하려면 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가 특정 글꼴에 대해 커닝 데이터를 무시할 때 발생할 수 있습니다.
이러한 경우를 위해 영향을 받는 글꼴을 사용하는 텍스트 부분에 대해 커닝을 비활성화할 수 있습니다. 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 렌더링과 맞출 수 있도록 도와줍니다.
텍스트 글꼴 속성 관리
글꼴 속성은 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와 동일하지 않습니다. IPortionFormat.GetEffective와 IBasePortionFormatEffectiveData.NormaliseHeight를 사용하여 최종 Boolean 값을 얻으세요.
다음 자체 포함 예제는 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이 설치되어 있어야 합니다.

정규화는 할당된 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);
결과:

교정 언어 설정
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);
언어 메타데이터 복사
템플릿에서 다국어 텍스트를 복사할 때 IBasePortionFormat.LanguageId와 IBasePortionFormat.AlternativeLanguageId를 모두 보존하십시오. 다음 자체 포함 예제는 소스 부분에 미국 영어를 기본 언어로, 프랑스어를 대체 언어로 설정하고 텍스트와 식별자를 새 프레젠테이션의 부분에 복사합니다:
using Aspose.Slides;
using Aspose.Slides.Export;
var source = new Portion("Hello! Bonjour!");
source.PortionFormat.LanguageId = "en-US";
source.PortionFormat.AlternativeLanguageId = "fr-FR";
using var presentation = new Presentation();
var slide = presentation.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 400, 80);
var paragraph = shape.TextFrame.Paragraphs[0];
paragraph.Portions.Clear();
var destination = new Portion();
destination.Text = source.Text;
destination.PortionFormat.LanguageId = source.PortionFormat.LanguageId;
// 소스에 대체 언어가 없으면 null이 대상 값을 지웁니다.
destination.PortionFormat.AlternativeLanguageId = source.PortionFormat.AlternativeLanguageId;
paragraph.Portions.Add(destination);
presentation.Save("copied_language_metadata.pptx", SaveFormat.Pptx);
대체 언어 없이 소스를 시도하려면 "fr-FR" 할당을 생략하십시오. 그러면 대체 식별자는 null이 되고, 복사 구문은 기존에 대체 언어가 있더라도 그 부재를 그대로 유지합니다.
이 식별자는 언어 메타데이터를 저장합니다. 이를 보존한다고 해서 PowerPoint가 맞춤법 또는 문법 검사에 사용할 사전이 결정되는 것은 아닙니다.
기본 언어 설정
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!
FAQ
슬라이드의 표에서 텍스트를 어떻게 수정합니까?
표의 텍스트를 수정하려면 ITable을 사용하십시오. 셀을 반복하면서 ICell.TextFrame을 통해 각 셀을 업데이트하고, IParagraph.ParagraphFormat을 통해 단락 서식을 지정합니다.
PowerPoint 슬라이드에서 텍스트에 그라디언트 색상을 어떻게 적용합니까?
그라디언트 색상을 적용하려면 IBasePortionFormat.FillFormat을 사용합니다. IFillFormat.FillType을 FillType.Gradient으로 설정하고, 그라디언트 정지점, 방향 및 투명도를 구성합니다.
관련 기능: Format text within slides.