Android'de PowerPoint Metin Paragraflarını Yönetme
Genel Bakış
Aspose.Slides for Android via Java, metni metin çerçeveleri, paragraflar ve bölümler hiyerarşisi olarak temsil eder:
- ITextFrame bir şeklin 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‑seviyesindeki biçimlendirmeye erişim sağlar.
- IPortion bir paragraftaki metin yürütmesini temsil eder. Her bölüm kendi metnine ve karakter‑seviyesindeki biçimlendirmeye sahip olabilir.
Bu nedenle bir paragraf, birden çok bölüm kullanılarak farklı yazı tipleri, renkler, boyutlar ve diğer biçimlendirmeler içerebilir.
Paragrafları Oluşturma ve Biçimlendirme
Birden Çok Bölüm ile Paragraf Oluşturma
Aşağıdaki adımlar, her biri üç bölüm içeren üç paragrafla bir metin çerçevesi oluşturur:
- Presentation sınıfının bir örneğini oluşturun.
- İndeksi aracılığıyla ilgili slayta erişin.
- Slayta dikdörtgen bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin.
- Varsayılan paragrafı kullanın ve metin çerçevesine iki ek IParagraph nesnesi ekleyin.
- Her paragrafın üç bölüm içermesi için yeterli sayıda IPortion nesnesi ekleyin. Varsayılan paragraf zaten bir boş bölüm içerir.
- Her bölümün metnini ayarlayın.
- IPortion.getPortionFormat aracılığıyla karakter‑seviyesinde biçimlendirme uygulayın.
- Değiştirilen sunumu kaydedin.
Bu Android via Java örneği adımları uygular:
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, 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 İşareti ve Numaralı Listeler Oluşturma
Madde İşareti veya Numaralı Liste Oluşturma
Madde işaretleri ve numaralandırma, ilgili öğeleri daha kolay taranabilir kılar. Aspose.Slides içinde liste ayarları, IBulletFormat aracılığıyla tanımlanır.
- Presentation sınıfının bir örneğini oluşturun.
- İndeksi aracılığıyla ilgili slayta erişin.
- Seçilen slayta bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin.
- Metin çerçevesinden varsayılan paragrafı kaldırın.
- Bir sembol madde işareti için bir Paragraph oluşturun.
- IBulletFormat.setType değerini BulletType.Symbol olarak ayarlayın ve madde işareti karakterini belirleyin.
- Paragraf metnini, girintiyi, madde işareti rengini ve yüksekliğini ayarlayın.
- Paragrafı metin çerçevesine ekleyin.
- İkinci bir paragraf oluşturun ve IBulletFormat.setType değerini BulletType.Numbered olarak ayarlayın.
- Numaralı madde işareti stilini yapılandırın ve paragrafı metin çerçevesine ekleyin.
- Sunumu kaydedin.
Bu Android via Java örneği bir sembol madde işareti ve bir numaralı madde işareti oluşturur:
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, 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örüntü kullanmanıza olanak tanır.
- Presentation sınıfının bir örneğini oluşturun.
- İndeksi aracılığıyla ilgili slayta erişin.
- Bir IAutoShape ekleyin ve onun ITextFrame öğesine erişin.
- Metin çerçevesinden varsayılan paragrafı kaldırın.
- Madde işareti görüntüsünü yükleyin ve sunumun görsel koleksiyonuna bir IPPImage olarak ekleyin.
- Bir Paragraph oluşturun ve metnini ayarlayın.
- IBulletFormat.setType değerini BulletType.Picture olarak ayarlayın.
- Görüntüyü IBulletFormat.getPicture aracılığıyla atayın ve madde işareti yüksekliğini ayarlayın.
- Paragrafı metin çerçevesine ekleyin.
- Değiştirilen sunumu kaydedin.
Bu Android via Java örneği bir resim madde işareti oluşturur:
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 listenin farklı seviyelerinde konumlandırılır. En üst seviye derinliği 0 dır.
- Bir Presentation oluşturun ve bir slayta erişin.
- Bir IAutoShape ekleyin ve varsayılan paragrafı metin çerçevesinden temizleyin.
- Dört paragraf oluşturun ve madde işareti sembollerini yapılandırın.
- IParagraphFormat.setDepth değerlerini sırasıyla
0,1,2ve3olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
Bu Android via Java örneği dört seviyeli bir madde işaretli liste oluşturur:
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, 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 bir numaralı paragraf için ilk gösterilen sayı ayarlanır.
- Bir Presentation oluşturun ve bir slayta bir IAutoShape ekleyin.
- Şeklin metin çerçevesinden varsayılan paragrafı temizleyin.
- Üç numaralı paragraf oluşturun.
- İlgili paragraflar için IBulletFormat.setNumberedBulletStartWith değerlerini sırasıyla
2,3ve7olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
Bu Android via Java örneği her paragraf için özel bir başlangıç numarası atar:
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
İlk Satır Girintisi Ayarlama
IParagraphFormat.setIndent kullanılarak bir paragrafın ilk satır girintisi kontrol edilir. Bu yöntem yalnızca paragrafın sol kenar boşluğuna göre ilk satırı 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 istediğinizde IParagraphFormat.setMarginLeft kullanılmalıdır. Yalnızca ilk satırı taşımak istediğinizde ise IParagraphFormat.setIndent kullanılmalıdır.
Aşağıdaki örnek, birkaç paragraf oluşturur ve farklı IParagraphFormat.setIndent değerlerini uygulayarak ilk satır girintisinin paragraf düzenini nasıl etkilediğini gösterir.
- Presentation sınıfının bir örneğini oluşturun.
- Hedef slayta erişin.
- Slayta bir dikdörtgen IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı kaldırın.
- Birkaç paragraf oluşturun ve bunlar için farklı IParagraphFormat.setIndent değerleri ayarlayın.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilen sunumu kaydedin.
Bu kod bir paragraf girintisinin nasıl ayarlanacağını gösterir:
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, 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ç:

Askı Girintisi Ayarlama
Askı girintisi, ilk satırın kalan satırların solundan daha sola başlamasıyla ortaya çıkan bir paragraf düzenidir. Aspose.Slides içinde bu etki, IParagraphFormat.setIndent ile negatif bir değer verilerek elde edilir; bu, ilk satırı paragraf gövdesine göre sola hareket ettirir.
Uygulamada, IParagraphFormat.setMarginLeft paragraf gövdesinin sol konumunu, IParagraphFormat.setIndent ise ilk satırın bu kenar boşluğuna göre konumunu belirler. Askı girintisi oluşturmak için setMarginLeft pozitif, setIndent ise negatif bir değer almalıdır.
Bu biçimlendirme, bibliyografiler, kaynakça, sözlük girdileri ve sarılmış satırların paragraf gövdesinin altında hizalanması gereken diğer paragraflar için uygundur.
- Presentation sınıfının bir örneğini oluşturun.
- Hedef slayta erişin.
- Slayta bir dikdörtgen IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı kaldırın.
- Paragraflar oluşturun ve her biri için IParagraphFormat.setMarginLeft değerini pozitif olarak ayarlayın.
- Askı etkisini yaratmak için IParagraphFormat.setIndent değerini negatif olarak geçirin.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilen sunumu kaydedin.
Bu kod bir paragraf için askı girintisinin nasıl ayarlanacağını gösterir:
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, 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 Sonu Çalıştırma Özelliklerini Ayarlama
IParagraph.setEndParagraphPortionFormat paragraf son işaretinin biçimlendirmesini kontrol eder. Aşağıdaki örnek, ikinci paragrafın son işaretine bir yazı tipi boyutu ve Latin yazı tipi atar:
- Bir Presentation yükleyin ve bir slayta erişin.
- Bir IAutoShape ekleyin ve varsayılan paragrafını temizleyin.
- İki paragraf oluşturun ve bunlara metin bölümleri ekleyin.
- İkinci paragrafın son işareti için bir PortionFormat oluşturun.
- IBasePortionFormat.setFontHeight ve IBasePortionFormat.setLatinFont ayarlayın.
- Formatı IParagraph.setEndParagraphPortionFormat ile atayın ve sunumu kaydedin.
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 kaydırma ve noktalama işaretlerini etkileyen paragraf kuralları için Control Line Breaking ve Control Hanging Punctuation bölümlerine bakın.
Bir paragrafın metin düzenlemesi sonrası kapladığı satır sayısını saymak için IParagraph.getLinesCount kullanılır; bu, otomatik kaydırma dahil olmak üzere render edilen satırları içerir. Bu, sunum şablonlarında metin uzunluğunu ve düzenini kontrol ederken kullanışlıdır.
Bir paragraf, ITextFrame.getParagraphs içinde bir öğedir ve birden çok render edilen satır kaplayabilir. Paragraf içinde açık bir satır sonu, yeni bir paragraf oluşturmadan yeni bir satır başlatır. Otomatik kaydırma, metne açık satır sonları 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, şekli daraltır ve ardından metni daha kısa bir dizeyle değiştirir. Kaydırma etkinleştirilmiş ve otomatik sığdırma devre dışı bırakılmıştır; böylece şekil genişliği, metni otomatik olarak küçültmeden kaydırmayı kontrol eder. Şekil boyutları puan cinsindendir. Son olarak örnek, metin çerçevesine bir paragraf daha ekler ve 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 boyutlarla, şekli daraltmak satır sayısını artırırken kısa dizeye geçmek azaltır. Kesin sayılar, kullanılan yazı tipine, boyutuna, kenar boşluklarına, girintilere, kaydırmaya ve otomatik sığdırma ayarlarına bağlı olarak değişebilir. Şablon kontrolü yaparken hedef ortam için planlanan yazı tiplerini ve düzen ayarlarını kullanın.
Satır sayısı yalnızca metnin kapsayıcısının dışına taşma durumunu belirlemez. Mevcut yükseklik, satır yüksekliği, paragraf ve satır aralığı ve otomatik sığdırma davranışı da önemlidir; kaydırma devre dışı bırakıldığında tek bir satır bile mevcut genişliği aşabilir.
Paragraf İçeriğini İçe ve Dışa Aktarma
HTML Metnini Paragraflara İçe Aktarma
ParagraphCollection.addFromHtml kullanılarak HTML işaretlemesi, bir metin çerçevesindeki paragraflara ve bölümlere dönüştürülür.
- Bir Presentation sınıfının bir örneğini oluşturun.
- Bir slayta erişin ve bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı temizleyin.
- Kaynak HTML dosyasını okuyun.
- HTML dizesini ParagraphCollection.addFromHtml metoduna aktarın.
- Değiştirilen sunumu kaydedin.
Bu Android via Java örneği HTML’i bir metin çerçevesine içe aktarı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 kullanılarak seçilen paragraf aralığı HTML olarak dışa aktarılır.
- Bir Presentation sınıfının bir örneğini oluşturun ve istenen sunumu yükleyin.
- Slayta erişin ve metni içeren IAutoShape bulun.
- Şeklin ITextFrame öğesine erişin.
- Başlangıç paragrafı indeksi ve dışa aktarılacak paragraf sayısı ile ParagraphCollection.exportToHtml metodunu çağırın.
- Dönen HTML dizesini bir dosyaya yazın.
Bu Android via Java örneği ilk metin şeklinin tüm paragraflarını dışa aktarı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("ExportingHTMLText.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();
String html = paragraphs.exportToHtml(0, paragraphs.getCount(), null);
try {
Files.write(Paths.get("paragraphs.html"), html.getBytes(StandardCharsets.UTF_8));
} 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();
}
Paragrafı Görüntü Olarak Render Etme
IParagraph.getImage bireysel bir paragrafı doğrudan render eder ve bir IImage döndürür. Sonucu bir dosyaya veya akıma IImage.save ile kaydedebilirsiniz. İçeren şekli render etmenize veya bir bitmap’i elle kırpmanıza gerek yoktur.
IParagraph.getImage paragraf bulunamazsa, geçerli bir render sınırı yoksa veya render edilemezse null döndürebilir. Kaydetmeden önce sonucu kontrol edin ve kullanımdan sonra döndürülen görüntüyü serbest bırakın.
Paragrafı Varsayılan Ölçekte Render Etme
sample.pptx adlı bir sunum dosyamızın bir slaytı olduğunu ve ilk şeklinin üç paragraf içeren bir metin kutusu olduğunu varsayalım.

Aşağıdaki örnek, ikinci paragrafı normal bir metin şekli içinde varsayılan ölçekte render eder ve PNG formatında kaydeder. finally bloğu, görüntünün doğru şekilde serbest bırakılmasını sağlar.
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çeklendirme ile Paragraf Render Etme
IParagraph.getImage aşırı yüklemesi, float scaleX ve float scaleY parametrelerini kabul eder; böylece yatay ve dikey ölçek faktörleri ayarlanabilir. Aşağıdaki örnek bir tablo oluşturur, paragrafı ilk hücresinde varsayılan genişliğinin ve yüksekliğinin iki katı olarak render eder ve sonucu PNG görüntüsü 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ü, ekseni varsayılan piksel boyutunda tutar. Örneğin, her iki faktör için 2 ayarlandığında, genişliği ve yüksekliği yaklaşık iki katına çıkan bir görüntü elde edilir; bu da piksel sayısının dört katı demektir. Daha büyük faktörler, yakınlaştırma veya yüksek çözünürlüklü çıkışlar için metni daha keskin yapar, ancak bellek kullanımı ve dosya boyutunu da artırır. 1’in altındaki faktörler, daha az detaylı daha küçük görüntüler üretir. Görüntünün en‑boy oranını korumak için aynı faktörler kullanılmalı; farklı yatay ve düşey faktörler çıkışı bağımsız olarak uzatır.
Bir bütün şekli IShape.getImage ile render etmek, çıktının şeklin dolgu, kenarlık veya diğer görsel bağlamını içermesi gerektiğinde faydalıdır. Sadece paragrafın görüntüsü için IParagraph.getImage kullanılmalıdır.
SSS
Bir metin çerçevesi içinde satır kaydırmayı tamamen devre dışı bırakabilir miyim?
Evet. Satır kaydırmayı devre dışı bırakmak için ITextFrameFormat.setWrapText ayarlayın; böylece satırlar metin çerçevesinin kenarlarında kırılmaz.
Belirli bir paragrafın slayt üzerindeki kesin sınırlarını nasıl alabilirim?
IPortion.getRect bir bölümün sınırlarını, IParagraph.getRect ise bir paragrafın sınırlarını döndürür.
Paragraf hizalaması (sol, sağ, orta veya iki yana yaslama) nerede kontrol edilir?
IParagraphFormat.setAlignment bir paragraf‑seviyesi ayarıdı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 olarak hizalamak için Align Fonts Within a Line konusuna bakın.
Paragrafın bir kısmı için imla denetimi dili ayarlayabilir miyim?
Evet. Bireysel bölümler için IBasePortionFormat.setLanguageId ayarlayarak bir paragraf içinde birden çok dilde metin bulunabilir.