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

리터럴 텍스트나 정규식 매치를 찾고 강조 표시하려면 Search and Replace Text를 참조하세요.
텍스트 배경 색상 설정
단락의 기본 강조 색상을 설정하려면 IParagraphFormat.getDefaultPortionFormat을 사용하고, 개별 텍스트 부분에 대해서는 IBasePortionFormat.getHighlightColor을 사용합니다.
다음 예제는 첫 번째 단락에 라이트 그레이 강조 색을 기본값으로 설정합니다. 개별 부분에 대한 명시적 강조 색은 이 기본값보다 우선합니다:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// 전체 단락에 대한 강조 색상을 설정합니다.
paragraph.getParagraphFormat().getDefaultPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
presentation.save("gray_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

아래 코드 예제는 굵은 글꼴 텍스트 부분에 대한 배경 색을 설정하는 방법을 보여줍니다:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// 텍스트 부분에 대한 강조 색상을 설정합니다.
portion.getPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
}
}
presentation.save("gray_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

텍스트 단락 정렬
텍스트 프레임 내에서 단락 정렬을 설정하려면 IParagraphFormat.setAlignment을 사용합니다. 값은 중앙, 왼쪽 정렬, 오른쪽 정렬, 양쪽 맞춤 등일 수 있습니다.
다음 코드 예제는 단락을 가운데에 정렬하는 방법을 보여줍니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// 단락의 정렬을 가운데로 설정합니다.
paragraph.getParagraphFormat().setAlignment(TextAlignment.Center);
presentation.save("aligned_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

줄 내 글꼴 정렬
다른 글꼴 크기의 텍스트 부분을 한 줄 안에서 수직으로 정렬하려면 IParagraphFormat.setFontAlignment을 사용합니다. 이 설정은 전체 단락에 적용되며 각 줄 내부의 정렬을 제어합니다.
다음 자체 포함 예제는 하나의 슬라이드에 네 개의 라벨이 붙은 텍스트 상자를 생성합니다. 각 단락은 18, 36, 54 포인트의 동일한 텍스트를 포함하며, 서로 다른 글꼴 정렬을 사용합니다. Arial을 사용하고 자동 맞춤 및 줄 바꿈을 비활성화하며 텍스트 프레임을 단일 줄에 충분히 크게 유지합니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
int[] alignments = { FontAlignment.Baseline, FontAlignment.Top, FontAlignment.Center, FontAlignment.Bottom };
String[] alignmentNames = { "Baseline", "Top", "Center", "Bottom" };
float[] fontSizes = { 18f, 36f, 54f };
for (int i = 0; i < alignments.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 20 + i * 130, 660, 120);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
IParagraph label = textFrame.getParagraphs().get_Item(0);
label.setText(alignmentNames[i]);
label.getParagraphFormat().setAlignment(TextAlignment.Left);
label.getParagraphFormat().getDefaultPortionFormat().setFontHeight(14);
label.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setFontAlignment(alignments[i]);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
for (float fontSize : fontSizes) {
Portion portion = new Portion("Ag ");
portion.getPortionFormat().setFontHeight(fontSize);
paragraph.getPortions().add(portion);
}
textFrame.getParagraphs().add(paragraph);
}
presentation.save("font_alignment.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

글꼴 정렬은 글꼴 메트릭을 사용하므로 개별 문자 가장자리가 정확히 일치하지 않을 수 있습니다. 예제에는 대문자와 받침 문자가 포함되어 베이스라인과 바닥 정렬의 차이를 보여줍니다. 글꼴 가용성 및 대체, 사용된 문자, 글꼴 크기 차이가 결과에 영향을 미칩니다. 프레임 크기, 여백, 줄 간격, 줄 바꿈 및 자동 맞춤도 레이아웃에 영향을 주므로 모드를 비교할 때 동일한 글꼴 및 레이아웃 설정을 사용하세요.
이 설정은 수평 단락 정렬을 제어하는 IParagraphFormat.setAlignment 및 텍스트 블록을 도형 내에서 수직으로 위치시키는 ITextFrameFormat.setAnchoringType와 다릅니다. IBasePortionFormat.setEscapement을 사용한 위첨자 및 아래첨자 서식은 개별 부분을 베이스라인에 대해 이동시킬 뿐, 단락 줄에 대한 글꼴 정렬을 설정하지는 않습니다.
텍스트 투명도 설정
텍스트 투명도는 IBasePortionFormat.getFillFormat에 지정된 색상의 알파 구성 요소를 통해 제어됩니다. 아래 예제에서 alpha = 50은 0–255 범위의 ARGB 알파 채널 값이며, 투명도 백분율이 아닙니다.
다음 코드 예제는 전체 단락에 투명도를 적용하는 방법을 보여줍니다:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// 텍스트의 채우기 색상을 투명 색으로 설정합니다.
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
presentation.save("transparent_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

다음 코드 예제는 굵은 글꼴 텍스트 부분에 투명도를 적용하는 방법을 보여줍니다:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// 텍스트 부분의 투명도를 설정합니다.
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
}
}
presentation.save("transparent_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

텍스트 문자 간격 설정
텍스트 상자 내 문자 간격을 확장하거나 축소하려면 IBasePortionFormat.setSpacing을 사용합니다. 예제에서는 3포인트 간격을 추가하고, 음수 값은 텍스트를 조밀하게 만듭니다.
다음 Java 코드는 전체 단락의 문자 간격을 확장하는 방법을 보여줍니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// 참고: 문자 간격을 압축하려면 음수 값을 사용합니다.
paragraph.getParagraphFormat().getDefaultPortionFormat().setSpacing(3); // 문자 간격을 확대합니다.
presentation.save("character_spacing_in_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

다음 코드 예제는 굵은 글꼴 텍스트 부분의 문자 간격을 확장하는 방법을 보여줍니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// 참고: 문자 간격을 압축하려면 음수 값을 사용합니다.
portion.getPortionFormat().setSpacing(3); // 문자 간격을 확대합니다.
}
}
presentation.save("character_spacing_in_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

특정 글꼴에 대한 커닝 비활성화
때때로 Aspose.Slides가 렌더링한 텍스트가 PowerPoint에서 표시되는 텍스트보다 약간 더 촘촘하게 보일 수 있습니다. 이는 PowerPoint가 특정 글꼴에 대해 커닝 데이터를 무시할 때 발생합니다(글꼴에 유효한 커닝 정보가 있으며 PowerPoint 설정에서 커닝이 활성화된 경우에도).
이러한 경우에 PowerPoint와 더 가깝게 렌더링하려면 해당 글꼴을 사용하는 텍스트 부분에 대해 커닝을 비활성화할 수 있습니다. IBasePortionFormat.setKerningMinimalSize을 실제 글꼴 크기보다 큰 값으로 설정합니다. 이 예제는 첫 번째 슬라이드 첫 번째 도형에 텍스트 상자가 있는 “presentation.pptx"를 필요로 합니다. 상속된 글꼴을 포함한 유효 글꼴 이름을 확인하고 Roboto를 사용하는 부분에 대해 100포인트 임계값을 설정합니다. 이는 100포인트 미만의 글꼴 크기를 가진 해당 부분의 커닝을 비활성화합니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
String targetFont = "Roboto";
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
IPortionFormatEffectiveData portionFormat = portion.getPortionFormat().getEffective();
if ((portionFormat.getLatinFont() != null &&
portionFormat.getLatinFont().getFontName().equals(targetFont)) ||
(portionFormat.getEastAsianFont() != null &&
portionFormat.getEastAsianFont().getFontName().equals(targetFont)) ||
(portionFormat.getComplexScriptFont() != null &&
portionFormat.getComplexScriptFont().getFontName().equals(targetFont))) {
portion.getPortionFormat().setKerningMinimalSize(100);
}
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
임계값 이하의 일치하는 텍스트에 대해 이 설정은 커닝을 방지하고, PowerPoint 특유 동작에 영향을 받는 글꼴에 대해 Aspose.Slides 렌더링을 PowerPoint 시각 출력과 맞추는 데 도움이 될 수 있습니다.
텍스트 글꼴 속성 관리
글꼴 속성은 IParagraphFormat.getDefaultPortionFormat을 통해 단락 수준에서 설정하거나, 개별 부분에 대해 IPortionFormat을 통해 설정할 수 있습니다.
다음 예제는 첫 번째 단락의 기본 글꼴을 12포인트 Times New Roman, 굵게, 기울임꼴, 점선 밑줄로 설정합니다. 개별 부분에 대한 명시적 서식은 이러한 기본값보다 우선합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// 단락에 대한 글꼴 속성을 설정합니다.
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(12);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontBold(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontItalic(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Times New Roman"));
presentation.save("font_properties_for_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

다음 예제는 굵은 유효 서식을 가진 부분에 대해 13포인트 Times New Roman, 기울임꼴, 점선 밑줄을 적용합니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// 텍스트 부분에 대한 글꼴 속성을 설정합니다.
portion.getPortionFormat().setFontHeight(13);
portion.getPortionFormat().setFontItalic(NullableBool.True);
portion.getPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
portion.getPortionFormat().setLatinFont(new FontData("Times New Roman"));
}
}
presentation.save("font_properties_for_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

텍스트 높이 정규화 제어
템플릿 타이포그래피를 재현하거나 문자 높이 차이를 조사할 때는 IBasePortionFormat.setNormaliseHeight를 사용합니다. PowerPoint에서는 정규화를 활성화하면 개별 문자를 수직으로 늘리거나 압축하여 텍스트 부분 내에서 균일한 가시 높이를 부여합니다. 이는 다른 글꼴 간에 동일한 텍스트 높이를 보장하지는 않습니다.
속성을 NullableBool.True 또는 False로 설정하여 정규화를 명시적으로 활성화하거나 비활성화합니다. NullableBool.NotDefined는 로컬 설정을 지정하지 않아 해당 부분이 단락의 getDefaultPortionFormat 등에서 값을 상속하도록 합니다. 이것은 False와 동일한 의미가 아닙니다. IPortionFormat.getEffective를 사용하고 IBasePortionFormatEffectiveData.getNormaliseHeight를 읽어 해결된 Boolean 값을 가져옵니다.
다음 자체 포함 예제는 Arial이 설치되어 있어야 합니다. 동일한 대문자, 소문자, 받침 및 악센트 문자를 54포인트로 두 텍스트 블록에 생성합니다. 두 단락 모두 기본적으로 정규화를 활성화합니다. 상단 부분은 명시적으로 비활성화하고, 하단 부분은 상속받습니다. 프레임 크기, 여백 및 단락 간격은 동일하며, 줄 바꿈 및 자동 맞춤을 비활성화하여 비교를 일관되게 유지합니다. 예제는 False: false와 NotDefined: true를 출력한 뒤 “text_height_normalization.pptx"를 저장합니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
byte[] settings = { NullableBool.False, NullableBool.NotDefined };
String[] settingNames = { "False", "NotDefined" };
for (int i = 0; i < settings.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 60 + i * 200, 660, 150);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.setText("Hxgjpq ÅÉ 0123");
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setMarginTop(0);
textFrame.getTextFrameFormat().setMarginLeft(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceBefore(0);
paragraph.getParagraphFormat().setSpaceAfter(0);
paragraph.getParagraphFormat().setSpaceWithin(100);
paragraph.getParagraphFormat().getDefaultPortionFormat().setNormaliseHeight(NullableBool.True);
IPortion portion = paragraph.getPortions().get_Item(0);
FontData font = new FontData("Arial");
portion.getPortionFormat().setLatinFont(font);
portion.getPortionFormat().setFontHeight(54);
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
portion.getPortionFormat().setNormaliseHeight(settings[i]);
System.out.println(settingNames[i] + ": " + portion.getPortionFormat().getEffective().getNormaliseHeight());
}
presentation.save("text_height_normalization.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
아래 비교 이미지는 저장된 프레젠테이션에서 내보낸 것입니다. 상단 행은 정규화가 비활성화된(False) 상태이며, 하단 행은 상속된 설정(NotDefined → True)으로 정규화가 활성화된 상태입니다. 이 모습을 재현하려면 Arial이 설치되어 있어야 합니다.

정규화는 할당된 getFontHeight 값(포인트 단위)을 변경하지 않고 문자 높이만 변경합니다. 단락 setSpaceWithin은 줄 간격을 제어하고, 텍스트 프레임 setAutofitType은 텍스트나 컨테이너가 맞춰지도록 조정합니다. 이러한 설정은 서로 다른 목적을 갖고 전체 레이아웃에 독립적으로 영향을 줄 수 있습니다. 단락 서식 및 상속에 대한 자세한 내용은 Manage Paragraph를 참조하세요.
취소선 적용 및 제거
텍스트 부분에 취소선을 적용하려면 IBasePortionFormat.setStrikethroughType를 사용합니다. 이는 원본 텍스트를 삭제하지 않고 교정, 취소된 용어 또는 이전 가격을 표시하는 데 유용합니다. TextStrikethroughType.Single 또는 Double을 설정하면 텍스트에 한 줄 또는 두 줄의 선이 그어집니다.
취소선을 제거하려면 TextStrikethroughType.None을 전달합니다. 이는 주변 서식이 취소선을 지정하더라도 효과를 명시적으로 비활성화합니다. 반면에 TextStrikethroughType.NotDefined를 사용하면 로컬 설정이 정의되지 않아 단락 등에서 서식을 상속받게 됩니다. 이는 취소선이 반드시 제거된다는 보장은 아닙니다. 결과 서식을 읽으려면 IPortionFormat.getEffective를 사용하십시오.
다음 자체 포함 예제는 세 개의 가격 비교를 생성합니다. 각 단락은 레이블, 이전 가격, 현재 가격에 대한 별도 부분을 가지고 있어 이전 가격에만 취소선이 적용됩니다. 첫 번째 행은 취소선을 적용한 뒤 제거하고, 다른 행들은 각각 단일 및 이중 취소선을 유지합니다. 이 설정을 변경하면 텍스트와 다른 서식(예: 굵은 이전 가격)이 보존됩니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 620, 220);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
shape.getTextFrame().getParagraphs().clear();
String[] labels = { "None: ", "Single: ", "Double: " };
for (String label : labels) {
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceAfter(20);
IPortionFormat format = paragraph.getParagraphFormat().getDefaultPortionFormat();
format.setFontHeight(28);
FontData font = new FontData("Arial");
format.setLatinFont(font);
format.getFillFormat().setFillType(FillType.Solid);
format.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
Portion labelPortion = new Portion(label);
paragraph.getPortions().add(labelPortion);
Portion previousPrice = new Portion("$100");
previousPrice.getPortionFormat().setFontBold(NullableBool.True);
paragraph.getPortions().add(previousPrice);
Portion currentPrice = new Portion(" → $80");
paragraph.getPortions().add(currentPrice);
shape.getTextFrame().getParagraphs().add(paragraph);
}
IParagraphCollection paragraphs = shape.getTextFrame().getParagraphs();
// 취소선을 적용하고, 첫 번째 이전 가격에서는 명시적으로 제거합니다.
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.None);
paragraphs.get_Item(1).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(2).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Double);
presentation.save("strikethrough.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과 (위에서 아래 순서): 취소선 없음, 단일 취소선, 이중 취소선.

텍스트 회전 설정
텍스트 프레임 내에서 미리 정의된 텍스트 방향을 설정하려면 ITextFrameFormat.setTextVerticalType를 사용합니다.
다음 코드 예제는 텍스트 방향을 TextVerticalType.Vertical270으로 설정하여 텍스트를 시계 반대 방향으로 90도 회전시킵니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setTextVerticalType(TextVerticalType.Vertical270);
presentation.save("text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

텍스트 프레임에 대한 사용자 지정 회전 설정
ITextFrameFormat.setRotationAngle을 사용하여 ITextFrame에 대한 사용자 지정 회전 각도를 설정합니다.
다음 코드 예제는 도형 내 텍스트 프레임을 시계 방향으로 3도 회전시킵니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setRotationAngle(3);
presentation.save("custom_text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

단락 줄 간격 설정
Aspose.Slides는 IParagraphFormat.setSpaceAfter, IParagraphFormat.setSpaceBefore, IParagraphFormat.setSpaceWithin를 제공하여 단락 간격을 제어합니다. 사용 방법은 다음과 같습니다:
- 양수 값을 사용하면 줄 높이의 백분율로 줄 간격을 지정합니다.
- 음수 값을 사용하면 포인트 단위로 줄 간격을 지정합니다.
다음 예제는 첫 번째 단락의 내부 간격을 줄 높이의 200%(두 배)로 설정합니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setSpaceWithin(200);
presentation.save("line_spacing.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

줄 바꿈 제어
단락 줄 바꿈 규칙은 좁은 텍스트 블록 및 라틴어와 동아시아어 텍스트가 혼합된 프레젠테이션에서 유용합니다. 다음 메서드는 IParagraphFormat에 속하므로 전체 단락에 적용됩니다:
- setLatinLineBreak은 라틴어 줄 바꿈 규칙을 제어합니다. 혼합 텍스트에서는 인접한 동아시아 텍스트와 구두점의 줄 바꿈 위치에도 영향을 줄 수 있습니다.
- setEastAsianLineBreak은 동아시아어 줄 바꿈 규칙을 제어하며, 행의 시작 및 끝에 위치할 수 있는 문자에 대한 제한을 포함합니다.
이 규칙은 텍스트 프레임 내 자동 줄 바꿈을 활성화하는 ITextFrameFormat.setWrapText을 대체하지 않으며, 줄 바꿈이 발생할 때 레이아웃에 영향을 미칩니다; 줄 바꿈 문자 자체를 삽입하지는 않습니다. 명시적 줄 바꿈은 가용 너비와 무관하게 단락 내에서 새 줄을 강제합니다.
다음 자체 포함 예제는 중국어와 라틴어 텍스트가 혼합된 좁은 텍스트 블록을 생성합니다. 두 줄 바꿈 옵션을 명시적으로 설정하고 “line_breaking.pptx"를 저장합니다. 어느 규칙을 실험하려면 다른 설정은 그대로 두고 해당 값을 변경하십시오. 예제는 24포인트 Arial 및 SimSun을 사용하고 프레임 너비를 160포인트, 텍스트 프레임 수평 여백을 0으로 설정합니다. ITextFrameFormat.setAutofitType은 TextAutofitType.None으로 호출되어 텍스트 크기와 프레임 크기가 고정됩니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 160, 300);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("中文排版测试,PowerPoint 中文演示。");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
FontData eastAsianFont = new FontData("SimSun");
format.getDefaultPortionFormat().setEastAsianFont(eastAsianFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setLatinLineBreak(NullableBool.False);
format.setEastAsianLineBreak(NullableBool.True);
presentation.save("line_breaking.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
걸림 부호 제어
IParagraphFormat.setHangingPunctuation을 사용하면 해당 구두점이 텍스트 줄 오른쪽 가장자리를 넘어 확장될 수 있습니다(다음 줄에 배치되지 않음). 이는 전체 단락에 적용되며, 들여쓰기와는 다릅니다.
다음 자체 포함 예제는 100포인트 너비 텍스트 프레임에서 걸림 부호를 활성화하고 “hanging_punctuation.pptx"를 저장합니다. 24포인트 Arial 및 텍스트 프레임 수평 여백 0인 경우, 마지막 마침표가 “sentence” 뒤에 남아 오른쪽 텍스트 가장자를 넘어갑니다. 속성을 NullableBool.False로 설정하면 비교할 수 있습니다: 이 설정에서는 마침표가 별도 라인에 배치됩니다. 줄 바꿈을 활성화하고 자동 맞춤을 비활성화하여 가용 너비를 고정합니다.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 200);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("Simple text, next sentence.");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setHangingPunctuation(NullableBool.True);
presentation.save("hanging_punctuation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
모든 구두점이 걸릴 수 있는 것은 아닙니다. 위에서 설명한 글꼴 및 레이아웃 조건도 이 비교에 적용됩니다: 글꼴, 가용 너비, 여백 또는 자동 맞춤 설정을 변경하면 눈에 보이는 차이가 사라질 수 있습니다.
텍스트 프레임 자동 맞춤 유형 설정
ITextFrameFormat.setAutofitType은 텍스트가 컨테이너 경계를 초과할 때 텍스트가 어떻게 동작할지 결정합니다. 텍스트가 축소, 넘침, 또는 자동으로 도형 크기를 조정하도록 제어할 수 있습니다. 다음 예제는 텍스트에 맞도록 도형을 자동으로 크기 조정하도록 구성하고 결과를 “autofit_type.pptx"로 저장합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
presentation.save("autofit_type.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
자동 줄 바꿈 후 라인 수를 확인하고 텍스트나 도형 너비가 결과에 어떻게 영향을 주는지 보려면 Count Rendered Lines를 참조하세요. 라인 수만으로 텍스트가 컨테이너를 초과했는지는 판단할 수 없습니다.
텍스트 프레임 앵커 설정
ITextFrameFormat.setAnchoringType은 텍스트가 도형 내부에서 수직으로 어떻게 배치될지 정의합니다(예: 위쪽, 가운데, 아래쪽). 다음 예제는 첫 번째 도형의 텍스트를 아래쪽에 고정하고 결과를 “text_anchor.pptx"로 저장합니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Bottom);
presentation.save("text_anchor.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
텍스트 탭 설정
IParagraphFormat.setDefaultTabSize와 IParagraphFormat.getTabs을 사용하여 단락의 탭 정지를 구성합니다. 다음 예제는 기본 탭 간격을 100포인트로 설정하고 30포인트에 왼쪽 정렬 탭 정지를 추가합니다. 이러한 설정은 탭 문자를 포함한 텍스트에 영향을 미칩니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setDefaultTabSize(100);
paragraph.getParagraphFormat().getTabs().add(30, TabAlignment.Left);
presentation.save("paragraph_tabs.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
결과:

맞춤 언어 설정
Aspose.Slides는 IBasePortionFormat.setLanguageId을 제공하여 텍스트 부분의 맞춤 언어를 설정할 수 있습니다. 맞춤 언어는 PowerPoint에서 맞춤법 및 문법 검사에 사용되는 언어를 결정합니다.
다음 예제는 첫 번째 슬라이드 첫 번째 도형에 텍스트 상자가 있는 “presentation.pptx"와 최소 하나의 단락을 필요로 합니다. 첫 번째 단락의 내용을 “1。“으로 교체하고 글꼴을 SimSun으로 설정한 뒤, 간체 중국어 맞춤 언어(zh-CN)를 할당하고 결과를 “proofing_language.pptx"로 저장합니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getPortions().clear();
FontData font = new FontData("SimSun");
Portion textPortion = new Portion();
textPortion.getPortionFormat().setComplexScriptFont(font);
textPortion.getPortionFormat().setEastAsianFont(font);
textPortion.getPortionFormat().setLatinFont(font);
// 교정 언어의 Id를 설정합니다.
textPortion.getPortionFormat().setLanguageId("zh-CN");
textPortion.setText("1。");
paragraph.getPortions().add(textPortion);
presentation.save("proofing_language.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
기본 언어 설정
LoadOptions.setDefaultTextLanguage을 사용하여 프레젠테이션을 로드하거나 생성할 때 텍스트에 대한 기본 언어를 정의할 수 있습니다. 다음 예제는 기본 텍스트 언어를 미국 영어로 설정하고 텍스트 상자를 추가한 뒤, 첫 번째 텍스트 부분에 대해 en-US를 출력합니다.
import com.aspose.slides.*;
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDefaultTextLanguage("en-US");
Presentation presentation = new Presentation(loadOptions);
try {
ISlide slide = presentation.getSlides().get_Item(0);
// 새로운 사각형 도형에 텍스트를 추가합니다.
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 150, 50);
shape.getTextFrame().setText("Sample text");
// 첫 번째 부분의 언어를 확인합니다.
IPortion portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println(portion.getPortionFormat().getLanguageId());
} finally {
presentation.dispose();
}
기본 텍스트 스타일 설정
프레젠테이션 수준에서 기본 텍스트 서식을 적용하려면 IPresentation.getDefaultTextStyle을 사용합니다.
다음 예제는 새 프레젠테이션의 최상위 단락에 14포인트 굵은 글꼴을 기본값으로 설정하고 이를 “default_text_style.pptx"로 저장합니다. 텍스트는 더 구체적인 서식이 없으면 이러한 기본값을 상속받습니다.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
// 최상위 수준 단락 서식을 가져옵니다.
IParagraphFormat paragraphFormat = presentation.getDefaultTextStyle().getLevel(0);
if (paragraphFormat != null) {
paragraphFormat.getDefaultPortionFormat().setFontHeight(14);
paragraphFormat.getDefaultPortionFormat().setFontBold(NullableBool.True);
}
presentation.save("default_text_style.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
전체 대문자 효과가 적용된 텍스트 추출
PowerPoint에서 All Caps 글꼴 효과를 적용하면 슬라이드에 대문자로 표시되지만 원본 텍스트는 소문자로 입력됩니다. Aspose.Slides로 해당 텍스트 부분을 가져오면 라이브러리는 입력된 그대로 반환합니다. 표시된 텍스트와 일치시키려면 TextCapType을 확인하고 값이 All인 경우 반환 문자열을 대문자로 변환하십시오.
이 예제는 첫 번째 슬라이드 첫 번째 도형에 텍스트 상자가 있는 “sample2.pptx"를 필요로 합니다. 첫 번째 단락의 첫 번째 부분에 All Caps 효과가 적용된 “Hello, Aspose!“가 포함되어 있습니다(아래 참조).

다음 코드 예제는 All Caps 효과가 적용된 텍스트를 추출하는 방법을 보여줍니다:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample2.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IPortion textPortion = autoShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println("Original text: " + textPortion.getText());
IPortionFormatEffectiveData textFormat = textPortion.getPortionFormat().getEffective();
if (textFormat.getTextCapType() == TextCapType.All) {
String text = textPortion.getText().toUpperCase();
System.out.println("All-Caps effect: " + text);
}
} finally {
presentation.dispose();
}
출력:
Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!
FAQ
슬라이드의 표에서 텍스트를 어떻게 수정하나요?
슬라이드의 표에서 텍스트를 수정하려면 ITable를 사용하십시오. 셀을 순회하면서 ICell.getTextFrame을 통해 각 셀을 업데이트하고, IParagraph.getParagraphFormat을 통해 단락 서식을 업데이트합니다.
PowerPoint 슬라이드의 텍스트에 그라데이션 색을 어떻게 적용하나요?
텍스트에 그라데이션 색을 적용하려면 IBasePortionFormat.getFillFormat을 사용하십시오. IFillFormat.setFillType을 FillType.Gradient으로 설정하고 그라데이션 정지점, 방향 및 투명도를 구성합니다.