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çindeki 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 akışını temsil eder. Her bölüm kendi metnine ve karakter‑seviyesindeki biçimlendirmeye sahip olabilir.
Bu nedenle bir paragraf, birden çok 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
Birden Çok Bölüm İçeren Paragraflar 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.
- İlgili slayta indeks üzerinden erişin.
- Slayta dikdörtgen bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin.
- Varsayılan paragrafı kullanın ve metin çerçevesine iki tane daha 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.
- Karakter seviyesindeki biçimlendirmeyi IPortion.getPortionFormat aracılığıyla uygulayın.
- Değiştirilmiş sunumu kaydedin.
Bu Java örneği adımları uygular:
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 Numaralı Listeler Oluşturma
Madde İşaretli veya Numaralı Liste Oluşturma
Madde işaretleri ve numaralar, ilgili öğelerin taranmasını kolaylaştırır. Aspose.Slides’te liste ayarları IBulletFormat aracılığıyla tanımlanır.
- Presentation sınıfının bir örneğini oluşturun.
- İlgili slayta indeks üzerinden erişin.
- Seçili slayta bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin.
- Varsayılan paragrafı metin çerçevesinden kaldırın.
- Sembol madde işareti için bir Paragraph oluşturun.
- IBulletFormat.setType metodunu BulletType.Symbol olarak ayarlayın ve madde işareti karakterini belirtin.
- Paragraf metnini, girintiyi, madde işareti rengini ve yüksekliğini ayarlayın.
- Paragrafı metin çerçevesine ekleyin.
- İkinci paragrafı oluşturun ve IBulletFormat.setType metodunu BulletType.Numbered olarak ayarlayın.
- Numaralı madde işareti stilini yapılandırın ve paragrafı metin çerçevesine ekleyin.
- Sunumu kaydedin.
Bu Java örneği bir sembol madde işareti ve bir numaralı madde işareti oluşturur:
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örüntü kullanmanıza olanak tanır.
- Presentation sınıfının bir örneğini oluşturun.
- İlgili slayta indeks üzerinden erişin.
- Bir IAutoShape ekleyin ve onun ITextFrame öğesine erişin.
- Varsayılan paragrafı metin çerçevesinden kaldırın.
- Madde işareti görüntüsünü yükleyin ve sunumun görüntü koleksiyonuna bir IPPImage olarak ekleyin.
- Bir Paragraph oluşturun ve metnini ayarlayın.
- IBulletFormat.setType metodunu 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ştirilmiş sunumu kaydedin.
Bu 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 Düzeyli Liste Oluşturma
IParagraphFormat.setDepth metodunu ayarlayarak paragrafları bir listenin farklı seviyelerine yerleştirebilirsiniz. Üst seviye 0 derinliğe sahiptir.
- Bir Presentation oluşturun ve bir slayta erişin.
- Bir IAutoShape ekleyin ve metin çerçevesindeki varsayılan paragrafı temizleyin.
- Dört paragraf oluşturup madde işareti sembollerini yapılandırın.
- Onların IParagraphFormat.setDepth değerlerini
0,1,2ve3olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
Bu Java örneği dört seviyeli madde işaretli bir liste oluşturur:
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 metodunu kullanarak numaralı bir paragrafın başlangıç sayısını ayarlayabilirsiniz.
- Bir Presentation oluşturun ve bir slayta IAutoShape ekleyin.
- Şeklin metin çerçevesindeki varsayılan paragrafı temizleyin.
- Üç numaralı paragraf oluşturun.
- İlgili paragraflar için IBulletFormat.setNumberedBulletStartWith metodunu sırasıyla
2,3ve7olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
Bu 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 Son Özelliklerini Kontrol Etme
İlk Satır Girintisi Ayarlama
IParagraphFormat.setIndent metodunu kullanarak bir paragrafın ilk satır girintisini kontrol edebilirsiniz. Bu metod 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 gerektiğinde IParagraphFormat.setMarginLeft kullanın. Sadece ilk satırı taşımak istediğinizde ise IParagraphFormat.setIndent kullanın.
Aşağıdaki örnek birkaç paragraf oluşturur ve farklı IParagraphFormat.setIndent değerleri 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 dikdörtgen bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı kaldırın.
- Çeşitli paragraflar oluşturun ve her biri için farklı IParagraphFormat.setIndent değerleri ayarlayın.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilmiş sunumu kaydedin.
Bu kod bir paragraf girintisi nasıl ayarlanır gösterir:
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ç:

Sarkıtılmış Girinti Ayarlama
Sarkıtılmış girinti, ilk satırın kalan satırların solundan daha sola başlamasıyla elde edilen bir paragraf düzenidir. Aspose.Slides’te bu etkiyi IParagraphFormat.setIndent ile oluşturursunuz; negatif bir değer ilk satırı paragraf gövdesine göre sola kaydırır.
Uygulamada, IParagraphFormat.setMarginLeft paragraf gövdesinin sol konumunu belirler, IParagraphFormat.setIndent ise ilk satırın bu kenar boşluğuna göre konumunu tanımlar. Sarkıtılmış bir girinti oluşturmak için setMarginLeft metoduna pozitif bir değer, setIndent metoduna negatif bir değer veririz.
Bu biçimlendirme, bibliyografyalar, referanslar, sözlük girdileri ve satırların paragraf gövdesinin altında hizalanması gereken diğer paragraflar için faydalıdır.
- Presentation sınıfının bir örneğini oluşturun.
- Hedef slayta erişin.
- Slayta dikdörtgen bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı kaldırın.
- Paragraflar oluşturun ve her biri için IParagraphFormat.setMarginLeft metoduna pozitif bir değer verin.
- Sarkıtılmış etkiyi oluşturmak için IParagraphFormat.setIndent metoduna negatif bir değer verin.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilmiş sunumu kaydedin.
Bu kod bir paragraf için sarkıtılmış girinti nasıl ayarlanır gösterir:
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 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.
- Biçimi 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();
}
Paragraf İçeriğini İçe ve Dışa Aktarma
HTML Metnini Paragraflara İçe Aktarma
ParagraphCollection.addFromHtml metodunu kullanarak HTML işaretlemesini bir metin çerçevesindeki paragraflara ve bölümlere dönüştürebilirsiniz.
- Presentation sınıfının bir örneğini oluşturun.
- Bir slayta bir IAutoShape ekleyin.
- Şeklin ITextFrame öğesine erişin ve varsayılan paragrafı temizleyin.
- Kaynak HTML dosyasını okuyun.
- HTML dizisini ParagraphCollection.addFromHtml metoduna geçirin.
- Değiştirilmiş sunumu kaydedin.
Bu 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 Olarak Dışa Aktarma
ParagraphCollection.exportToHtml metodunu kullanarak seçili paragraf aralığını HTML olarak dışa aktarabilirsiniz.
- 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öndürülen HTML dizgisini bir dosyaya yazın.
Bu 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();
}
Bir Paragrafı Görüntü Olarak Oluşturma
IParagraph.getImage bir paragrafı doğrudan render eder ve bir IImage döndürür. Sonucu IImage.save ile dosyaya veya akışa kaydedebilirsiniz. İçeren şekli render etmenize veya bitmap’i elle kırpmanıza gerek yoktur.
IParagraph.getImage paragraf bulunamazsa, geçerli bir render alanı yoksa veya render edilemezse null dönebilir. Kaydetmeden önce sonucu kontrol edin ve kullanım sonrası döndürülen görüntüyü serbest bırakın.
Paragrafı Varsayılan Ölçekte Oluşturma
sample.pptx adlı bir sunum dosyamızın bir slaydı olduğunu ve ilk şeklinin üç paragraf içeren bir metin kutusu olduğunu varsayalım.

Aşağıdaki örnek, normal bir metin şeklinin ikinci paragrafını varsayılan ölçekte render eder ve döndürülen görüntüyü 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 Paragrafı Ölçeklendirme ile Oluşturma
float scaleX ve float scaleY parametrelerini kabul eden IParagraph.getImage aşırı yüklemesini kullanarak yatay ve dikey ölçek faktörlerini ayarlayabilirsiniz. Aşağıdaki örnek bir tablo oluşturur, paragrafı ilk hücresinde varsayılan genişliğinin iki katı 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 kullanmak, genişlik ve yüksekliği yaklaşık olarak iki katına çıkaran bir görüntü üretir; bu da piksel sayısını dört katına yükseltir. Daha büyük faktörler, yakınlaştırma veya yüksek çözünürlüklü çıktı için daha keskin metin sağlar, ancak bellek kullanımı ve dosya boyutunu da artırır. 1’in altındaki faktörler daha küçük ve daha az detaylı görüntüler üretir. 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.
Bir şeklin tamamını IShape.getImage ile render etmek, çıktının şeklin doldurması, kenarlığı 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
Metin çerçevesi içinde satır kaydırmayı tamamen devre dışı bırakabilir miyim?
Evet. Kaydırmayı devre dışı bırakmak ve satırların metin çerçevesinin kenarlarında kırılmasını önlemek için ITextFrameFormat.setWrapText metodunu ayarlayın.
Belirli bir paragrafın slayt üzerindeki tam sınırlamalarını nasıl alabilirim?
Paragrafın sınırlayan dikdörtgenini almak için IParagraph.getRect metodunu kullanın. Tek bir bölümün sınırlamalarını elde etmek için IPortion.getRect metodunu kullanabilirsiniz.
Paragraf hizalaması (sol, sağ, merkez veya iki kenara yaslama) nerede kontrol edilir?
IParagraphFormat.setAlignment bir paragraf‑seviyesi ayarıdır ve bireysel bölümlerin biçimlendirmesinden bağımsız olarak tüm paragrafı etkiler.
Paragrafın bir kısmı için dil denetimi ayarlayabilir miyim?
Evet. Bireysel bölümler için IBasePortionFormat.setLanguageId metodunu ayarlayarak bir paragrafın içinde birden fazla dilde metin bulunmasını sağlayabilirsiniz.