Android'de PowerPoint Metin Paragraflarını Yönet
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çindeki metin kapsayıcısını temsil eder ve paragraf koleksiyonuna erişim sağlar.
- IParagraph bir metin çerçevesinde bir paragrafı temsil eder ve bölümlerine ve paragraf düzeyinde biçimlendirmesine erişim sağlar.
- IPortion bir paragraftaki metin çalışmasını (run) temsil eder. Her bölüm kendi metni ve karakter düzeyinde 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çeren metin barındırabilir.
Paragraflar Oluşturma ve Biçimlendirme
Birden Çok Bölüm İçeren Paragraflar Oluşturma
Aşağıdaki adımlar üç paragraftan oluşan ve her biri üç bölüm içeren bir metin çerçevesi oluşturur:
- [Presentation] sınıfının bir örneğini oluşturun.
- İlgili slayta indeks aracılığıyla erişin.
- Slayta dikdörtgen bir [IAutoShape] ekleyin.
- Şeklin [ITextFrame]‘ine erişin.
- Varsayılan paragrafı kullanın ve metin çerçevesine iki adet 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 belirleyin.
- Karakter düzeyinde biçimlendirmeyi [IPortion.getPortionFormat] aracılığıyla uygulayın.
- Değiştirilmiş sunumu kaydedin.
This Android via Java example implements the steps:
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 İşaretli ve Numaralı Listeler Oluşturma
Madde İşaretli veya Numaralı Liste Oluşturma
Madde işaretleri ve numaralar, ilgili öğelerin daha kolay taranmasını sağ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.
- İlgili slayta indeks aracılığıyla erişin.
- Seçilen slayta bir [IAutoShape] ekleyin.
- Şeklin [ITextFrame]‘ine erişin.
- Metin çerçevesinden varsayılan paragrafı kaldırın.
- Sembol madde işareti için bir [Paragraph] oluşturun.
- [IBulletFormat.setType] değerini [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 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.
This Android via Java example creates a symbol bullet and a numbered bullet:
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ızı sağlar.
- [Presentation] sınıfının bir örneğini oluşturun.
- İlgili slayta indeks aracılığıyla erişin.
- Bir [IAutoShape] ekleyin ve onun [ITextFrame]‘ine erişin.
- Metin çerçevesinden varsayılan paragrafı kaldırın.
- Madde işareti resmini yükleyin ve sunumun görüntü koleksiyonuna bir [IPPImage] olarak ekleyin.
- Bir [Paragraph] oluşturun ve metnini ayarlayın.
- [IBulletFormat.setType] değerini [BulletType.Picture] olarak ayarlayın.
- [IBulletFormat.getPicture] aracılığıyla resmi atayın ve madde işareti yüksekliğini ayarlayın.
- Paragrafı metin çerçevesine ekleyin.
- Değiştirilmiş sunumu kaydedin.
This Android via Java example creates a picture bullet:
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] ayarını kullanarak paragrafları bir listenin farklı seviyelerine yerleştirin. En üst seviye 0 derinliğe sahiptir.
- 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
0,1,2ve3olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
This Android via Java example creates a four-level bulleted list:
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
Numaralı bir paragraf için başlangıç numarasını ayarlamak üzere [IBulletFormat.setNumberedBulletStartWith] kullanın.
- Bir [Presentation] oluşturun ve bir [IAutoShape] slayta ekleyin.
- Şeklin metin çerçevesinden varsayılan paragrafı temizleyin.
- Üç numaralı paragraf oluşturun.
- İlgili paragraflar için [IBulletFormat.setNumberedBulletStartWith] değerini sırasıyla
2,3ve7olarak ayarlayın. - Paragrafları metin çerçevesine ekleyin ve sunumu kaydedin.
This Android via Java example assigns a custom starting number to each paragraph:
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] yöntemi, bir paragrafın yalnızca ilk satırının girintisini kontrol eder. Pozitif bir değer ilk satırı sağa kaydırırken, kalan satırlar paragraf gövdesine hizalanmış kalır.
Tüm paragrafı taşımak gerektiğinde [IParagraphFormat.setMarginLeft] kullanın. Yalnızca ilk satırı taşımak için [IParagraphFormat.setIndent] kullanın.
Aşağıdaki örnek, birkaç paragraf oluşturur ve farklı [IParagraphFormat.setIndent] değerlerini uygulayarak ilk satır girintisinin paragraf düzenine etkisini 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]‘ine erişin ve varsayılan paragrafı kaldırın.
- Birkaç paragraf oluşturun ve her biri için farklı [IParagraphFormat.setIndent] değerleri ayarlayın.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilmiş sunumu kaydedin.
This code shows you how to set a paragraph indent:
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();
}
The result:

Askı Girintisi Ayarlama
Askı girintisi, ilk satırın geri kalan satırların solundan daha fazla sola kaydığı bir paragraf düzenidir. Aspose.Slides’te bu etkiyi [IParagraphFormat.setIndent] ile negatif bir değer vererek elde edersiniz.
Pratikte, [IParagraphFormat.setMarginLeft] paragraf gövdesinin sol konumunu, [IParagraphFormat.setIndent] ise ilk satırın bu marj göreceli konumunu belirler. Askı girintisi oluşturmak için setMarginLefta pozitif bir değer, setIndente negatif bir değer gönderin.
Bu biçimlendirme, bibliyografyalar, referanslar, sözlük girdileri ve sarılmış satırların paragraf gövdesi 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]‘ine erişin ve varsayılan paragrafı kaldırın.
- Her paragraf için [IParagraphFormat.setMarginLeft]a pozitif bir değer gönderin.
- Askı girintisi etkisini oluşturmak için [IParagraphFormat.setIndent]e negatif bir değer gönderin.
- Paragrafları metin çerçevesine ekleyin.
- Değiştirilmiş sunumu kaydedin.
This code shows you how to set a hanging indent for a paragraph:
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();
}
The result:

Paragraf Sonu Çalışma Ö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.
- [IParagraph.setEndParagraphPortionFormat] ile formatı 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/Dışa Aktarma
HTML Metnini Paragraflara İçe Aktarma
Paragraf koleksiyonunda HTML işaretlemesini paragraf ve bölümlere dönüştürmek için [ParagraphCollection.addFromHtml] kullanın.
- Bir [Presentation] sınıfının bir örneğini oluşturun.
- Bir slayta erişin ve bir [IAutoShape] ekleyin.
- Şeklin [ITextFrame]‘ine erişin ve varsayılan paragrafı temizleyin.
- Kaynak HTML dosyasını okuyun.
- HTML dizesini [ParagraphCollection.addFromHtml]‘a gönderin.
- Değiştirilmiş sunumu kaydedin.
This Android via Java example imports HTML into a text frame:
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’e Dışa Aktarma
Seçili bir paragraf aralığını HTML olarak dışa aktarmak için [ParagraphCollection.exportToHtml] kullanın.
- 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]‘i bulun.
- Şeklin [ITextFrame]‘ine erişin.
- Başlangıç paragraf indeksi ve dışa aktarılacak paragraf sayısını belirterek [ParagraphCollection.exportToHtml] çağırın.
- Döndürülen HTML dizesini bir dosyaya yazın.
This Android via Java example exports all paragraphs from the first text shape:
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 Oluşturma
[IParagraph.getImage] tek bir paragrafı doğrudan render eder ve bir [IImage] döndürür. Sonucu [IImage.save] ile dosya ya da akışa kaydedebilirsiniz. Şeklin tamamını render etmeye veya bitmap kırpmaya gerek yoktur.
[IParagraph.getImage] paragraf bulunamazsa, geçerli bir render alanı yoksa veya render edilemezse null döndürebilir. 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 adında bir sunum dosyamız olduğunu ve bir slayt içerdiğini, 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();
}
The result:

Tablo Hücresinde Paragrafı Ölçeklendirme ile Oluşturma
Yatay ve dikey ölçek faktörlerini ayarlamak için float scaleX ve float scaleY parametrelerini kabul eden [IParagraph.getImage] aşırı yüklemesini kullanın. Aşağıdaki örnek bir tablo oluşturur, paragrafı ilk hücresinde varsayılan genişliğinin ve yüksekliğinin iki katı ölçekte 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ü ekseni varsayılan piksel boyutunda tutar. Örneğin, her iki faktör için 2 kullanmak, genişliği ve yüksekliği yaklaşık iki kat olan bir görüntü üretir; bu da piksel sayısını dört kat artırır. Daha büyük faktörler yakınlaştırma veya yüksek çözünürlüklü çıktıda daha keskin metin sağlar, ancak bellek kullanımını ve dosya boyutunu da artırır. 1‘in altındaki faktörler daha az detaylı, daha küçük 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.
[IShape.getImage] ile tüm şekli render etmek, çıktının şeklin doldurulması, kenarlık veya diğer görsel bağlamı 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. Satır kaydırmayı devre dışı bırakmak için [ITextFrameFormat.setWrapText] değerini 0 olarak ayarlayın; böylece satırlar metin çerçevesinin kenarlarında kırılmaz.
Belirli bir paragrafın slayt üzerindeki tam sınırlarını nasıl alabilirim?
Paragrafın sınırlayıcı dikdörtgenini elde etmek için [IParagraph.getRect] kullanın. Bireysel bir bölümün sınırlarını almak için [IPortion.getRect] kullanabilirsiniz.
Paragraf hizalaması (sol, sağ, ortalanmış veya iki yana yaslanmış) nerede kontrol edilir?
[IParagraphFormat.setAlignment] bir paragraf düzeyinde ayardır ve bireysel bölüm biçimlendirmesinden bağımsız olarak tüm paragrafı etkiler.
Paragrafın bir bölümü için dil denetim ayarını belirleyebilir miyim?
Evet. Bireysel bölümler için [IBasePortionFormat.setLanguageId] ayarlayarak bir paragrafta birden fazla dilde metin bulundurabilirsiniz.