Java'da PowerPoint Metin Paragraflarını Yönetme
Genel Bakış
Aspose.Slides for Java, metni metin çerçeveleri, paragraflar ve bölümler hiyerarşisi olarak temsil eder:
- ITextFrame şekil içinde metin kapsayıcısını temsil eder ve paragraf koleksiyonuna erişim sağlar.
- IParagraph bir metin çerçevesindeki bir paragrafı temsil eder ve bölümlerine ve paragraf düzeyinde biçimlendirmeye erişim sağlar.
- IPortion bir paragrafta metin akışını temsil eder. Her bölüm, kendi metni ve karakter düzeyinde biçimlendirmesi olabilir.
Bu nedenle bir paragraf, birden fazla bölüm kullanarak farklı yazı tipleri, renkler, boyutlar ve diğer biçimlendirmeler içeren metin içerebilir.
Paragrafları Oluşturma ve Biçimlendirme
Şeklin metin çerçevesinde paragraflar oluşturun ve bölümleri kullanarak tek tek metin akışlarını biçimlendirin. Bu bölüm, her paragrafta birden fazla bölümü birleştirerek farklı renkler, yazı boyutları ve stiller uygulamayı gösterir.
Birden Çok Bölüm İçeren Paragraflar Oluşturma
Aşağıdaki Java örneği, IParagraph.getPortions koleksiyonunda dönen üç paragraf oluşturur; her biri üç metin akışı içerir. Varsayılan paragrafı ve boş bölümünü yeniden kullanır, ardından kalan paragrafları ve bölümleri ekler. Biçimlendirme, IPortion.getPortionFormat aracılığıyla uygulanır: her paragraftaki ilk bölüm kırmızı, kalın ve 15 puan; ikinci bölüm mavi, italik ve 18 puan. Üçüncü bölüm varsayılan biçimini korur:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 300, 150);
ITextFrame textFrame = shape.getTextFrame();
IParagraph firstParagraph = textFrame.getParagraphs().get_Item(0);
firstParagraph.getPortions().add(new Portion());
firstParagraph.getPortions().add(new Portion());
IParagraph secondParagraph = new Paragraph();
secondParagraph.getPortions().add(new Portion());
secondParagraph.getPortions().add(new Portion());
secondParagraph.getPortions().add(new Portion());
textFrame.getParagraphs().add(secondParagraph);
IParagraph thirdParagraph = new Paragraph();
thirdParagraph.getPortions().add(new Portion());
thirdParagraph.getPortions().add(new Portion());
thirdParagraph.getPortions().add(new Portion());
textFrame.getParagraphs().add(thirdParagraph);
int paragraphCount = textFrame.getParagraphs().getCount();
for (int paragraphIndex = 0; paragraphIndex < paragraphCount; paragraphIndex++) {
IParagraph paragraph = textFrame.getParagraphs().get_Item(paragraphIndex);
int portionCount = paragraph.getPortions().getCount();
for (int portionIndex = 0; portionIndex < portionCount; portionIndex++) {
IPortion portion = paragraph.getPortions().get_Item(portionIndex);
portion.setText("Portion " + (paragraphIndex + 1) + "." + (portionIndex + 1));
if (portionIndex == 0) {
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.RED);
portion.getPortionFormat().setFontBold(NullableBool.True);
portion.getPortionFormat().setFontHeight(15);
} else if (portionIndex == 1) {
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
portion.getPortionFormat().setFontItalic(NullableBool.True);
portion.getPortionFormat().setFontHeight(18);
}
}
}
presentation.save("paragraphs_with_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Madde İşaretli ve Numara Listeleri Oluşturma
Paragraf metnini semboller, sayılar veya özel görsellerle listelere dönüştürün. Bu bölümde madde işaretleme biçimlendirmesi, çok seviyeli listeler ve özel başlangıç numaraları örneklenir.
Madde İşaretli veya Numara Listesi Oluşturma
Madde işaretleri ve numaralar, ilgili öğelerin daha kolay taranmasını sağlar. Aspose.Slides’te liste ayarları, IBulletFormat aracılığıyla tanımlanır.
Bu Java örneği aynı metin çerçevesine bir sembol madde işareti ve bir numaralı öğe ekler. IBulletFormat.setType madde işareti türünü seçerken, IBulletFormat.setChar sembolü sağlar ve IBulletFormat.setNumberedBulletStyle numaralandırma stilini seçer. Her iki öğe de %100 yükseklikte siyah madde işaretleri ve 25 puan paragraf girintisi kullanır:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph symbolParagraph = new Paragraph();
symbolParagraph.setText("Welcome to Aspose.Slides");
symbolParagraph.getParagraphFormat().getBullet().setType(BulletType.Symbol);
symbolParagraph.getParagraphFormat().getBullet().setChar((char) 0x2022);
symbolParagraph.getParagraphFormat().setIndent(25);
symbolParagraph.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB);
symbolParagraph.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK);
symbolParagraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True);
symbolParagraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(symbolParagraph);
Paragraph numberedParagraph = new Paragraph();
numberedParagraph.setText("This is a numbered item");
numberedParagraph.getParagraphFormat().getBullet().setType(BulletType.Numbered);
numberedParagraph.getParagraphFormat().getBullet().setNumberedBulletStyle(NumberedBulletStyle.BulletCircleNumWDBlackPlain);
numberedParagraph.getParagraphFormat().setIndent(25);
numberedParagraph.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB);
numberedParagraph.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK);
numberedParagraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True);
numberedParagraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(numberedParagraph);
presentation.save("bulleted_and_numbered_list.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Resim Madde İşaretleri Kullanma
Resim madde işaretleri, bir sembol veya sayı yerine özel bir görsel kullanmanıza olanak tanır.
Bu Java örneği, sunumun görsel koleksiyonuna bir IPPImage ekler ve bunu paragraf madde işareti olarak kullanır. IBulletFormat.setType ile resim madde işareti seçilir ve görüntü, IBulletFormat.getPicture aracılığıyla atanır. IBulletFormat.setHeight %100 olarak ayarlanarak madde işaretinin paragraf metnine göre boyutu belirlenir:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IImage bulletImage = Images.fromFile("bullets.png");
IPPImage presentationImage;
try {
presentationImage = presentation.getImages().addImage(bulletImage);
} finally {
bulletImage.dispose();
}
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph paragraph = new Paragraph();
paragraph.setText("Welcome to Aspose.Slides");
paragraph.getParagraphFormat().getBullet().setType(BulletType.Picture);
paragraph.getParagraphFormat().getBullet().getPicture().setImage(presentationImage);
paragraph.getParagraphFormat().getBullet().setHeight(100);
textFrame.getParagraphs().add(paragraph);
presentation.save("picture_bullet.pptx", SaveFormat.Pptx);
presentation.save("picture_bullet.ppt", SaveFormat.Ppt);
} finally {
presentation.dispose();
}
Çok Seviyeli Liste Oluşturma
IParagraphFormat.setDepth ayarlanarak paragraflar bir listenin farklı seviyelerine yerleştirilir. En üst seviye derinliği 0 dır.
Bu Java örneği, dört paragraf için IParagraphFormat.setDepth değerlerini 0‑3 arasında atayarak tek bir metin çerçevesinde bir hiyerarşi oluşturur. Her paragraf bir sembol madde işareti kullanır; IBulletFormat.setChar yuvarlak madde işareti ve kısa çizgi arasında geçiş yaparak komşu seviyeleri ayırır:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
IParagraph firstParagraph = new Paragraph();
firstParagraph.setText("Content");
firstParagraph.getParagraphFormat().getBullet().setType(BulletType.Symbol);
firstParagraph.getParagraphFormat().getBullet().setChar((char) 0x2022);
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
firstParagraph.getParagraphFormat().setDepth((short) 0);
IParagraph secondParagraph = new Paragraph();
secondParagraph.setText("Second level");
secondParagraph.getParagraphFormat().getBullet().setType(BulletType.Symbol);
secondParagraph.getParagraphFormat().getBullet().setChar('-');
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
secondParagraph.getParagraphFormat().setDepth((short) 1);
IParagraph thirdParagraph = new Paragraph();
thirdParagraph.setText("Third level");
thirdParagraph.getParagraphFormat().getBullet().setType(BulletType.Symbol);
thirdParagraph.getParagraphFormat().getBullet().setChar((char) 0x2022);
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
thirdParagraph.getParagraphFormat().setDepth((short) 2);
IParagraph fourthParagraph = new Paragraph();
fourthParagraph.setText("Fourth level");
fourthParagraph.getParagraphFormat().getBullet().setType(BulletType.Symbol);
fourthParagraph.getParagraphFormat().getBullet().setChar('-');
fourthParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
fourthParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
fourthParagraph.getParagraphFormat().setDepth((short) 3);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
textFrame.getParagraphs().add(thirdParagraph);
textFrame.getParagraphs().add(fourthParagraph);
presentation.save("multilevel_list.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Numaralı Liste Öğelerini Özel Değerlerle Başlatma
IBulletFormat.setNumberedBulletStartWith kullanılarak numaralı bir paragrafın başlangıç numarası belirlenir.
Bu Java örneği, üç paragraf için numaralandırma kullanmak üzere IBulletFormat.setType ayarlar ve IBulletFormat.setNumberedBulletStartWith değerlerini 2, 3 ve 7 olarak atar. Başlangıç değeri her paragraf için ayrı ayrı yapılandırılır, bu da görüntülenen sayıların atlamasını sağlar:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph firstParagraph = new Paragraph();
firstParagraph.setText("Start at 2");
firstParagraph.getParagraphFormat().getBullet().setType(BulletType.Numbered);
firstParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith((short) 2);
textFrame.getParagraphs().add(firstParagraph);
Paragraph secondParagraph = new Paragraph();
secondParagraph.setText("Start at 3");
secondParagraph.getParagraphFormat().getBullet().setType(BulletType.Numbered);
secondParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith((short) 3);
textFrame.getParagraphs().add(secondParagraph);
Paragraph thirdParagraph = new Paragraph();
thirdParagraph.setText("Start at 7");
thirdParagraph.getParagraphFormat().getBullet().setType(BulletType.Numbered);
thirdParagraph.getParagraphFormat().getBullet().setNumberedBulletStartWith((short) 7);
textFrame.getParagraphs().add(thirdParagraph);
presentation.save("custom_numbered_list.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Paragraf Düzeni ve Bitiş Özelliklerini Kontrol Etme
Paragraf kenar boşlukları ve girintileri ayarlanarak ilk satır ve sarma satırlarının konumu kontrol edilir. Paragraf bitiş işaretini görünür metin bölümlerinden ayrı biçimlendirebilirsiniz.
İlk Satır Girintisi Ayarlama
IParagraphFormat.setIndent yöntemiyle bir paragrafın ilk satır girintisi kontrol edilir. Bu ayar yalnızca ilk satırı paragrafın sol kenar boşluğuna göre hareket ettirir. Pozitif bir değer ilk satırı sağa kaydırırken, kalan satırlar paragraf gövdesine hizalı kalır.
Tüm paragrafı taşımak gerektiğinde IParagraphFormat.setMarginLeft kullanın. Yalnızca ilk satırı taşımak istediğinizde ise IParagraphFormat.setIndent kullanın.
Aşağıdaki örnek, üç paragrafın aynı IParagraphFormat.setMarginLeft değerini 20 puan ve IParagraphFormat.setIndent değerlerini 0, 20 ve 40 puan olarak ayarlar. İlk satırlar giderek daha büyük ofsetlerde başlarken, sarma satırları aynı sol kenar boşluğunu korur:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 420, 220);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
textFrame.getParagraphs().clear();
Paragraph firstParagraph = new Paragraph();
firstParagraph.setText("No first-line indent. Wrapped lines start at the same position as the first line.");
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
firstParagraph.getParagraphFormat().setMarginLeft(20f);
firstParagraph.getParagraphFormat().setIndent(0f);
Paragraph secondParagraph = new Paragraph();
secondParagraph.setText("First-line indent of 20 points. The first line moves to the right, while wrapped lines remain aligned to the paragraph body.");
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
secondParagraph.getParagraphFormat().setMarginLeft(20f);
secondParagraph.getParagraphFormat().setIndent(20f);
Paragraph thirdParagraph = new Paragraph();
thirdParagraph.setText("First-line indent of 40 points. This paragraph shows a larger first-line offset to make the effect easier to see.");
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
thirdParagraph.getParagraphFormat().setMarginLeft(20f);
thirdParagraph.getParagraphFormat().setIndent(40f);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
textFrame.getParagraphs().add(thirdParagraph);
presentation.save("paragraph_indent.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Sonuç:

Sarkan Girinti Ayarlama
Sarkan girinti, ilk satırın kalan satırların solunda başladığı bir paragraf düzenidir. Aspose.Slides’te bu etki, IParagraphFormat.setIndent özelliğiyle oluşturulur. Indent değerini negatif yaparak ilk satırı paragraf gövdesine göre sola kaydırırsınız.
Pratikte, IParagraphFormat.setMarginLeft paragraf gövdesinin sol konumunu, IParagraphFormat.setIndent ise ilk satırın bu kenar boşluğuna göre konumunu belirler. Sarkan bir girinti oluşturmak için pozitif bir MarginLeft ve negatif bir Indent değeri ayarlayın.
Bu biçimlendirme, bibliyografiler, referanslar, sözlük girişleri ve sarma satırlarının paragraf gövdesinin altında hizalanması gereken diğer paragraflar için faydalıdır.
Aşağıdaki Java örneği, IParagraphFormat.setMarginLeft değerlerini 40 ve 60 puan, IParagraphFormat.setIndent değerlerini -20 ve -30 puan olarak eşleştirir. Her paragrafta ilk satır sarma satırlarının solunda başlar; ikinci paragraf daha derin bir sarkan girintiye sahiptir:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 420, 220);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
textFrame.getParagraphs().clear();
Paragraph firstParagraph = new Paragraph();
firstParagraph.setText("A hanging indent is created by combining a positive left margin with a negative indent. The first line starts to the left, while wrapped lines align with the paragraph body.");
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
firstParagraph.getParagraphFormat().setMarginLeft(40f);
firstParagraph.getParagraphFormat().setIndent(-20f);
Paragraph secondParagraph = new Paragraph();
secondParagraph.setText("This second example uses a deeper hanging indent so the difference between the first line and the wrapped lines is easier to compare.");
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
secondParagraph.getParagraphFormat().setMarginLeft(60f);
secondParagraph.getParagraphFormat().setIndent(-30f);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
presentation.save("hanging_indent.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Sonuç:

Paragraf Bitiş Çalışma Özelliklerini Ayarlama
IParagraph.setEndParagraphPortionFormat yöntemi, paragraf bitiş işaretinin biçimlendirmesini kontrol eder. Aşağıdaki örnek, PortionFormat oluşturur; IBasePortionFormat.setFontHeight 48 puan, IBasePortionFormat.setLatinFont Times New Roman olarak ayarlar. Bu format ikinci paragrafın bitiş işaretine atanır, görünür metin bölümleri değişmeden kalır:
import com.aspose.slides.*;
Presentation presentation = new Presentation("Test.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, 200, 250);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph firstParagraph = new Paragraph();
firstParagraph.getPortions().add(new Portion("Sample text"));
Paragraph secondParagraph = new Paragraph();
secondParagraph.getPortions().add(new Portion("Sample text 2"));
PortionFormat endParagraphFormat = new PortionFormat();
endParagraphFormat.setFontHeight(48);
endParagraphFormat.setLatinFont(new FontData("Times New Roman"));
secondParagraph.setEndParagraphPortionFormat(endParagraphFormat);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
presentation.save("end_paragraph_format.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Render Edilen Satırları Sayma
Satır sonlarında otomatik sarma ve noktalama üzerine etki eden paragraf kuralları için Control Line Breaking ve Control Hanging Punctuation bölümlerine bakın.
IParagraph.getLinesCount yöntemi, metin yerleşimi sonrasında bir paragrafın kapladığı satır sayısını, otomatik sarma dahil, sayar. Bu, sunum şablonlarında metin uzunluğunu ve yerleşimini kontrol ederken faydalıdır.
Bir paragraf, ITextFrame.getParagraphs içinde bir öğedir ve birkaç render edilen satır kaplayabilir. Paragraf içinde açık bir satır sonu, başka bir paragraf oluşturmadan yeni bir satır başlatır. Otomatik sarma, metnin içine ek bir satır sonu karakteri eklemeden mevcut genişliğe göre satır oluşturur. Bu yüzden paragraf sayısını veya satır sonu karakterlerini saymak render edilen satır sayısını vermez.
Aşağıdaki örnek bir metin şekli oluşturur, satırlarını sayar, şeklin genişliğini daraltır ve ardından metni daha kısa bir dizeyle değiştirir. Örnek, ITextFrameFormat.setWrapText ile sarma etkinleştirir ve ITextFrameFormat.setAutofitType ile otomatik sığdırmayı devre dışı bırakır; böylece şekil genişliği sarma kontrol eder, metin otomatik küçülmez veya şekil yeniden boyutlandırılmaz. Her ölçüm, IParagraph.getLinesCount kullanır. Şekil boyutları puan cinsindendir. Son olarak örnek bir paragraf daha ekler ve metin çerçevesi boyunca satır sayılarını toplar.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 400, 200);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(20);
paragraph.setText("This text demonstrates how automatic wrapping changes the number of rendered lines.");
System.out.println("Original width: " + paragraph.getLinesCount());
shape.setWidth(150);
System.out.println("Narrower shape: " + paragraph.getLinesCount());
paragraph.setText("Short text.");
System.out.println("Shorter text: " + paragraph.getLinesCount());
Paragraph secondParagraph = new Paragraph();
secondParagraph.setText("Another paragraph.");
secondParagraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(20);
textFrame.getParagraphs().add(secondParagraph);
int totalLineCount = 0;
for (IParagraph currentParagraph : textFrame.getParagraphs()) {
totalLineCount += currentParagraph.getLinesCount();
}
System.out.println("Total lines in the text frame: " + totalLineCount);
} finally {
presentation.dispose();
}
Bu metin ve bu boyutlarla şeklin daraltılması satır sayısını artırırken, kısa dizeyle değiştirildiğinde azaltır. Kesin sayılar, kullanılan yazı tipine, yedeklemeye, yazı boyutuna, kenar boşluklarına, girintilere, sarma ve otomatik sığdırma ayarlarına göre değişebilir. Şablon kontrolü yaparken hedef ortam için planlanan yazı tipleri ve yerleşim ayarlarını kullanın.
Satır sayısı tek başına metnin kapsayıcısını aşıp aşmadığını belirlemez. Kullanılabilir yükseklik, satır yükseklikleri, paragraf ve satır aralığı ve otomatik sığdırma davranışı da önemlidir; sarma devre dışı bırakıldığında tek bir satır bile kullanılabilir genişliği aşabilir.
Paragraf İçeriğini İçeri/Dışarı Aktarma
HTML kullanarak metni bir sunuma getirebilir veya mevcut paragrafları dışarıda kullanım için dışa aktarabilirsiniz. Bu bölüm ayrıca tablo hücrelerindeki paragraflar dahil bireysel paragrafları resim olarak nasıl oluşturacağınızı gösterir.
HTML Metnini Paragraflara İçe Aktarma
ParagraphCollection.addFromHtml yöntemi, HTML işaretlemesini bir metin çerçevesindeki paragraflara ve bölümlere dönüştürür.
Bu Java örneği, bir dosyadan HTML okur ve işaretlemeyi ParagraphCollection.addFromHtml metoduna iletir. Metin çerçevesinin varsayılan paragrafı temizlenir, böylece çerçeve yalnızca içe aktarılan içeriği içerir. Dikdörtgen şekil, slaytın her iki tarafında 10 puanlık bir kenar boşluğu bırakır:
import com.aspose.slides.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
float shapeWidth = (float) presentation.getSlideSize().getSize().getWidth() - 20;
float shapeHeight = (float) presentation.getSlideSize().getSize().getHeight() - 20;
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, shapeWidth, shapeHeight);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getTextFrame().getParagraphs().clear();
try {
byte[] htmlBytes = Files.readAllBytes(Paths.get("file.html"));
String html = new String(htmlBytes, StandardCharsets.UTF_8);
shape.getTextFrame().getParagraphs().addFromHtml(html);
presentation.save("html_text.pptx", SaveFormat.Pptx);
} catch (IOException exception) {
System.out.println("The HTML file could not be read: " + exception.getMessage());
}
} finally {
presentation.dispose();
}
Paragraf Metnini HTML’ye Dışa Aktarma
ParagraphCollection.exportToHtml yöntemi, seçilen paragraf aralığını HTML olarak dışa aktarır. Sunum metnini bir web sitesinde yeniden kullanırken, sunumun yazı tipi, boyutu veya metin kutusu stillerini taşımadan yerel vurgulamayı korumak isteyebilirsiniz. TextToHtmlConversionOptions.setTextInheritanceLimit ayarı, dışa aktarıcının biçimlendirme kalıtımını ne kadar takip edeceğini kontrol eder.
örnek sunumu indirin ve uygulamanın çalışma dizinine yerleştirin. İlk slayt, “Inherited text; explicit red 18pt” metnini içeren bir metin şekli barındırır. Girdi kasıtlı olarak birkaç biçimlendirme seviyesini kullanır:
- Sunumun varsayılan metin stili Calibri ve 28 pt sağlar.
- Metin çerçevesinin birinci düzey metin stili mavi metin ve italik sağlar.
- Paragraf kalın metin olarak ayarlanır.
- İkinci bölüm “explicit red 18pt”, kırmızı metin ve 18 pt boyutunu açıkça ayarlar.
Aşağıdaki tam örnek, aynı paragrafları üç kez dışa aktarır. TextToHtmlConversionOptions dışa aktarma metoduna geçirilir ve her sonuç ayrı bir UTF‑8 HTML dosyasına yazılır:
import com.aspose.slides.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
Presentation presentation = new Presentation("text-inheritance.pptx");
try {
IShape shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
if (shape instanceof IAutoShape) {
IAutoShape textShape = (IAutoShape) shape;
ITextFrame textFrame = textShape.getTextFrame();
if (textFrame != null) {
IParagraphCollection paragraphs = textFrame.getParagraphs();
int[] modes = { TextInheritanceLimit.All, TextInheritanceLimit.TextBox, TextInheritanceLimit.ParagraphOnly };
String[] fileNames = { "All.html", "TextBox.html", "ParagraphOnly.html" };
for (int i = 0; i < modes.length; i++) {
TextToHtmlConversionOptions options = new TextToHtmlConversionOptions();
options.setTextInheritanceLimit(modes[i]);
String html = paragraphs.exportToHtml(0, paragraphs.getCount(), options);
byte[] htmlBytes = html.getBytes(StandardCharsets.UTF_8);
try {
Files.write(Paths.get(fileNames[i]), htmlBytes);
} catch (IOException exception) {
System.out.println("The HTML file could not be written: " + exception.getMessage());
}
}
} else {
System.out.println("The first shape does not contain a text frame.");
}
} else {
System.out.println("The first shape is not a text shape.");
}
} finally {
presentation.dispose();
}
Oluşturulan HTML, ilk bölüm “Inherited text; ” için aşağıdaki CSS’i içerir. Tablo ilgili bildirimleri listeler; diğer üretilen özellikler açıklık için atlanmıştır.
| Çıktı | İlk bölüm için ilgili CSS | Görünüm |
|---|---|---|
All.html |
font-family:'Calibri'; font-size:28pt; color:#0000ff; font-style:italic; font-weight:bold |
Calibri mevcutsa 28 pt, mavi, kalın, italik metin. |
TextBox.html |
color:#0000ff; font-style:italic; font-weight:bold |
Mavi, kalın, italik metin; sayfa veya tarayıcı yazı tipi ve boyutunu sağlar. |
ParagraphOnly.html |
font-weight:bold |
Kalın metin; sayfa veya tarayıcı yazı tipi, boyutu, rengi ve italik stilini sağlar. |
İkinci bölüm, tüm üç çıktıda color:#ff0000, font-size:18pt ve font-weight:bold değerlerini korur. All ve TextBox için italik stilini de korur, ParagraphOnly için korumaz. Kalıtımı kısıtlamak, bir paragraf veya bölüme açıkça atanmış biçimlendirmeyi kaldırmaz.
Dosyaları aynı tarayıcıda açarak karşılaştırın. İki kısıtlı modda atlanmış CSS özellikleri, hedef sayfanın stilleri veya tarayıcı varsayılanları tarafından çözülür; bu nedenle ortaya çıkan görünüm HTML’nin nerede kullanıldığına bağlıdır.
HTML Pano Parçası Oluşturma
TextToHtmlConversionOptions.setAddClipboardFragmentHeader ile IParagraphCollection.exportToHtml çıktısı seçilir. false ise yöntem normal HTML döndürür. true ise dönen dize Windows pano başlığıyla başlar. StartHTML ve EndHTML alanları HTML’nin UTF‑8 bayt ofsetlerini, StartFragment ve EndFragment ise yapıştırılacak içeriği gösterir.
Bu örnek, iki biçimlendirilmiş paragrafı normal HTML (html) ve HTML pano parçacığı (clipboardHtml) olarak dışa aktarır. Uygulama ardından parçacığı sistem panosuna yazabilir. Pano API’si ham baytları bekliyorsa, parçacığı BOM‑siz UTF‑8 olarak kodlayın.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 400, 100);
IParagraphCollection paragraphs = shape.getTextFrame().getParagraphs();
paragraphs.clear();
paragraphs.addFromHtml("<p>Status: <b>Ready</b></p><p><i>Next steps</i></p>");
TextToHtmlConversionOptions options = new TextToHtmlConversionOptions();
options.setAddClipboardFragmentHeader(false);
String html = paragraphs.exportToHtml(0, paragraphs.getCount(), options);
options.setAddClipboardFragmentHeader(true);
String clipboardHtml = paragraphs.exportToHtml(0, paragraphs.getCount(), options);
} finally {
presentation.dispose();
}
Paragrafı Görüntü Olarak Oluşturma
IParagraph.getImage tek bir paragrafı doğrudan render eder ve bir IImage döndürür. Sonucu IImage.save ile dosyaya veya akışa kaydedin. İçeren şekli render etmenize veya bitmap’i manuel olarak kırpmanıza gerek yoktur.
IParagraph.getImage paragraf, ebeveyn koleksiyonunda bulunamazsa, geçerli bir renderleme sınırı yoksa veya renderlanamazsa null döndürebilir. Kaydetmeden önce sonucu kontrol edin ve kullanım sonrası döndürülen resmi serbest bırakın.
Varsayılan Ölçekte Paragraf Render Etme
Örnek, üç paragraf içeren bir metin kutusu olan tek bir slaytlı bir sunum kullanır.

Aşağıdaki örnek, indeks 1’deki ikinci paragrafı seçer ve ölçek parametresi olmadan IParagraph.getImage çağırır. Şeklin gerekli paragrafı içerdiğini ve renderlamanın bir görüntü döndürdüğünü kontrol ettikten sonra, görüntüyü PNG formatında kaydetmek için IImage.save kullanır. finally bloğu, kullanım sonrası görüntüyü serbest bırakır.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
IShape shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
if (shape instanceof IAutoShape) {
IAutoShape textShape = (IAutoShape) shape;
ITextFrame textFrame = textShape.getTextFrame();
if (textFrame != null && textFrame.getParagraphs().getCount() > 1) {
IParagraph paragraph = textFrame.getParagraphs().get_Item(1);
IImage paragraphImage = paragraph.getImage();
if (paragraphImage != null) {
try {
paragraphImage.save("paragraph.png", ImageFormat.Png);
} finally {
paragraphImage.dispose();
}
} else {
System.out.println("The paragraph could not be rendered.");
}
} else {
System.out.println("The expected paragraph was not found.");
}
} else {
System.out.println("The first shape is not a text shape.");
}
} finally {
presentation.dispose();
}
Sonuç:

Tablo Hücresinde Ölçekli Paragraf Render Etme
float scaleX ve float scaleY parametrelerini kabul eden IParagraph.getImage aşırı yüklemesi kullanılabilir. Aşağıdaki örnek bir tablo oluşturur, ilk hücresindeki paragrafı varsayılan genişliğinin ve yüksekliğinin iki katına ölçekleyerek render eder ve sonucu PNG olarak kaydeder.
import com.aspose.slides.*;
float scaleX = 2f;
float scaleY = 2f;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
ITable table = slide.getShapes().addTable(50, 50, new double[] { 300 }, new double[] { 80 });
IParagraph paragraph = table.get_Item(0, 0).getTextFrame().getParagraphs().get_Item(0);
paragraph.setText("Text in a table cell");
IImage paragraphImage = paragraph.getImage(scaleX, scaleY);
if (paragraphImage != null) {
try {
paragraphImage.save("table_paragraph.png", ImageFormat.Png);
} finally {
paragraphImage.dispose();
}
} else {
System.out.println("The paragraph could not be rendered.");
}
} finally {
presentation.dispose();
}
1 ölçek faktörü eksen başına varsayılan piksel boyutunu korur. Örneğin, iki faktör için 2 girildiğinde, genişlik ve yükseklik yaklaşık olarak varsayılan boyutların iki katı olur ve piksel sayısı dört katına çıkar. Daha büyük faktörler, yakınlaştırma veya yüksek çözünürlüklü çıktı için daha keskin metin üretir, ancak bellek kullanımını ve dosya boyutunu da artırır. 1’in altındaki faktörler, daha az detay içeren daha küçük görüntüler üretir. Paragrafın en/boy oranını korumak için eşit faktörler kullanın; farklı yatay ve dikey faktörler çıktıyı bağımsız olarak uzatır.
IShape.getImage ile tüm bir şekli render etmek, çıktının şeklin doldurmasını, kenarlığını veya diğer görsel bağlamını içermesi gerektiğinde yararlıdır. Sadece paragraf görüntüsü için IParagraph.getImage kullanın.
SSS
Bir metin çerçevesi içinde satır sarma tamamen devre dışı bırakılabilir mi?
Evet. ITextFrameFormat.setWrapText değerini false yaparak sarma devre dışı bırakılır, böylece satırlar metin çerçevesinin kenarlarında kırılmaz.
Belirli bir paragrafın slayt üzerindeki kesin sınırları nasıl elde edebilirim?
IParagraph.getRect yöntemi, paragrafın sınırlayıcı dikdörtgenini döndürür. IPortion.getRect ise tek bir bölümün sınırlarını sağlar.
Paragraf hizalaması (sol, sağ, ortalanmış veya iki yana yaslanmış) nerede kontrol edilir?
IParagraphFormat.setAlignment bir paragraf‑düzeyi ayardır ve bireysel bölüm biçimlendirmesinden bağımsız olarak bütün paragrafı etkiler.
Her satır içinde farklı yazı tipi boyutlarına sahip bölümleri dikey hizalamak için Align Fonts Within a Line bölümüne bakın.
Paragrafın bir kısmı için doğrulama dili ayarlanabilir mi?
Evet. IBasePortionFormat.setLanguageId tek tek bölümlere uygulanabilir; böylece bir paragraf birden fazla dilde metin içerebilir.