Mengelola Daftar Berpoin dan Bernomor dalam Presentasi di Java
Overview
Aspose.Slides for Java memungkinkan Anda membuat dan memformat daftar berpoin dan bernomor dalam presentasi PowerPoint dan OpenDocument. Sebuah item daftar adalah paragraf yang pengaturan bullet‑nya dikontrol melalui format paragrafnya.
Gunakan metode IParagraph.getParagraphFormat untuk mengakses pengaturan daftar pada level paragraf. Titik masuk utama adalah IParagraphFormat.getBullet, yang mengembalikan objek IBulletFormat. Dengan objek ini, Anda dapat mengatur tipe bullet, simbol, gambar, warna, ukuran, gaya penomoran, dan nomor mulai.
Artikel ini menunjukkan cara:
- membuat daftar berpoin dengan simbol khusus
- membuat bullet gambar
- membuat daftar multilevel dengan mengatur kedalaman paragraf
- membuat daftar bernomor
- memeriksa dan mengubah format daftar dalam presentasi yang ada
- membaca penanda dan nomor daftar yang sebenarnya bersamaan dengan teks paragraf
Create a Bulleted List
Untuk membuat daftar berpoin, tambahkan objek IParagraph ke ITextFrame dan setel IBulletFormat.setType ke BulletType.Symbol. Anda kemudian dapat mengatur IBulletFormat.setChar, IBulletFormat.getColor , dan IBulletFormat.setHeight untuk mengontrol tampilan bullet.
The following Java code demonstrates how to create a bulleted list in a slide:
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 50);
ITextFrame textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
Color bulletColor = new Color(205, 92, 92);
Paragraph paragraph1 = new Paragraph();
paragraph1.getParagraphFormat().getBullet().setType(BulletType.Symbol);
paragraph1.getParagraphFormat().getBullet().setChar('*');
paragraph1.getParagraphFormat().setIndent(15);
paragraph1.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True);
paragraph1.getParagraphFormat().getBullet().getColor().setColor(bulletColor);
paragraph1.getParagraphFormat().getBullet().setHeight(100);
paragraph1.setText("The first paragraph");
textFrame.getParagraphs().add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.getParagraphFormat().getBullet().setType(BulletType.Symbol);
paragraph2.getParagraphFormat().getBullet().setChar('*');
paragraph2.getParagraphFormat().setIndent(15);
paragraph2.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True);
paragraph2.getParagraphFormat().getBullet().getColor().setColor(bulletColor);
paragraph2.getParagraphFormat().getBullet().setHeight(100);
paragraph2.setText("The second paragraph");
textFrame.getParagraphs().add(paragraph2);
presentation.save("symbol_bullets.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
The result:

Create a Numbered List
Gunakan daftar bernomor ketika urutan item penting. Setel IBulletFormat.setType ke BulletType.Numbered. Anda juga dapat memilih format penomoran dengan IBulletFormat.setNumberedBulletStyle atau setel IBulletFormat.setNumberedBulletStartWith ketika daftar harus dimulai dari nilai selain 1.
The following Java code shows how to create a numbered list in a slide:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 90, 80);
ITextFrame textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph paragraph1 = new Paragraph();
paragraph1.getParagraphFormat().getBullet().setType(BulletType.Numbered);
paragraph1.setText("Apple");
textFrame.getParagraphs().add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.getParagraphFormat().getBullet().setType(BulletType.Numbered);
paragraph2.setText("Orange");
textFrame.getParagraphs().add(paragraph2);
Paragraph paragraph3 = new Paragraph();
paragraph3.getParagraphFormat().getBullet().setType(BulletType.Numbered);
paragraph3.setText("Banana");
textFrame.getParagraphs().add(paragraph3);
presentation.save("numbered_bullets.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
The result:

Create a Picture Bullet
Aspose.Slides memungkinkan Anda mengganti simbol bullet standar dengan gambar. Bullet gambar paling cocok dengan gambar sederhana yang tetap terbaca pada ukuran kecil, seperti ikon atau file PNG transparan kecil.
Note
Idealnya, jika Anda berencana mengganti simbol bullet standar dengan gambar, sebaiknya pilih grafik sederhana dengan latar belakang transparan. Gambar semacam itu cocok sebagai simbol bullet khusus.
Perlu diingat bahwa gambar akan diperkecil menjadi ukuran yang sangat kecil. Oleh karena itu, kami sangat menyarankan memilih gambar yang tetap jelas dan efektif secara visual ketika digunakan sebagai bullet dalam daftar.
Untuk membuat picture bullet, tambahkan gambar ke Presentation.getImages dan tugaskan objek gambar yang dikembalikan ke IBulletFormat.getPicture. Setel IBulletFormat.setType ke BulletType.Picture sebelum menugaskan gambar.
Misalkan kita memiliki “image.png”:

The following Java code shows how to create picture bullets in a slide:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 50);
ITextFrame textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
IPPImage bulletImage = presentation.getImages().addImage(Images.fromFile("image.png"));
Paragraph paragraph1 = new Paragraph();
paragraph1.getParagraphFormat().getBullet().setType(BulletType.Picture);
paragraph1.getParagraphFormat().getBullet().getPicture().setImage(bulletImage);
paragraph1.getParagraphFormat().setIndent(15);
paragraph1.getParagraphFormat().getBullet().setHeight(100);
paragraph1.setText("The first paragraph");
textFrame.getParagraphs().add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.getParagraphFormat().getBullet().setType(BulletType.Picture);
paragraph2.getParagraphFormat().getBullet().getPicture().setImage(bulletImage);
paragraph2.getParagraphFormat().setIndent(15);
paragraph2.getParagraphFormat().getBullet().setHeight(100);
paragraph2.setText("The second paragraph");
textFrame.getParagraphs().add(paragraph2);
presentation.save("picture_bullets.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
The result:

Create a Multilevel List
Gunakan IParagraphFormat.setDepth untuk menempatkan item daftar pada level yang berbeda. Level 0 adalah level teratas, level 1 berada di dalamnya, dan seterusnya.
The following Java code shows how to create a multilevel bulleted list:
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 260, 110);
ITextFrame textFrame = autoShape.getTextFrame();
textFrame.getParagraphs().clear();
Paragraph paragraph1 = new Paragraph();
paragraph1.getParagraphFormat().setDepth((short) 0);
paragraph1.setText("My text - Depth 0");
textFrame.getParagraphs().add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.getParagraphFormat().setDepth((short) 1);
paragraph2.setText("My text - Depth 1");
textFrame.getParagraphs().add(paragraph2);
Paragraph paragraph3 = new Paragraph();
paragraph3.getParagraphFormat().setDepth((short) 2);
paragraph3.setText("My text - Depth 2");
textFrame.getParagraphs().add(paragraph3);
Paragraph paragraph4 = new Paragraph();
paragraph4.getParagraphFormat().setDepth((short) 3);
paragraph4.setText("My text - Depth 3");
textFrame.getParagraphs().add(paragraph4);
presentation.save("multilevel_bullets.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
The result:

Change an Existing List
Untuk mengubah format daftar dalam presentasi yang ada, akses paragraf target dan perbarui pengaturan IParagraphFormat.getBullet‑nya. Properti yang sama yang digunakan untuk membuat daftar dapat dipakai untuk memeriksa atau memodifikasi daftar yang dimuat dari file PPT, PPTX, atau ODP.
The following Java code changes the first paragraph in a text frame to use a numbered list style:
import com.aspose.slides.*;
Presentation presentation = new Presentation("input.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape) slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered);
paragraph.getParagraphFormat().getBullet().setNumberedBulletStyle(NumberedBulletStyle.BulletRomanUCPeriod);
paragraph.getParagraphFormat().getBullet().setNumberedBulletStartWith((short) 1);
paragraph.getParagraphFormat().setMarginLeft(30);
paragraph.getParagraphFormat().setIndent(-20);
presentation.save("updated_list.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Read Actual Bullet Values
Saat mengekstrak konten presentasi, pertahankan penanda daftar bersamaan dengan teks paragraf. Panggil IParagraphFormat.getEffective dan akses IParagraphFormatEffectiveData.getBullet untuk memperoleh format bullet yang efektif. Periksa getType sebelum membaca getActualBulletValue.
Untuk daftar bernomor, bedakan tiga nilai berikut:
- getNumberedBulletStyle menentukan format, seperti angka Arab diikuti titik atau huruf kecil diikuti titik.
- getNumberedBulletStartWith menentukan nomor mulai untuk sekumpulan paragraf bernomor.
- getActualBulletValue mengembalikan penanda yang diformat untuk paragraf tertentu. Misalnya, item kedua dalam daftar yang dimulai pada 5 mengembalikan
6..
Pertahankan getDepth pada setiap paragraf untuk mempertahankan level nestingnya. Penanda sebenarnya tidak menyandi seluruh hierarki: item bersarang dapat mengembalikan c. alih‑alih label gabungan seperti 6.c..
The following self-contained example creates lists, saves them to a presentation, and reloads the presentation to report each paragraph’s text, depth, bullet type, and actual value. The small blue picture marker is created from inline SVG.
import com.aspose.slides.*;
import java.awt.Color;
Presentation presentation = new Presentation();
try {
presentation.getSlideSize().setSize(720, 440, SlideSizeScaleType.DoNotScale);
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 20, 660, 400);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
// Buat penanda gambar tanpa file gambar eksternal.
SvgImage svg = new SvgImage("<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><rect width='16' height='16' rx='4' fill='#0078D4'/></svg>");
IPPImage bulletImage = presentation.getImages().addImage(svg);
class ListBuilder {
void addParagraph(String text, short depth, byte type, short start, byte style) {
Paragraph paragraph = new Paragraph();
paragraph.setText(text);
IParagraphFormat format = paragraph.getParagraphFormat();
format.setDepth(depth);
format.setMarginLeft(30 + depth * 40);
format.setIndent(-28);
format.setSpaceAfter(8);
format.getDefaultPortionFormat().setFontHeight(22);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.getBullet().setType(type);
format.getBullet().setBulletHardColor(NullableBool.True);
format.getBullet().getColor().setColor(Color.BLACK);
if (type == BulletType.Numbered) {
format.getBullet().setNumberedBulletStyle(style);
format.getBullet().setNumberedBulletStartWith(start);
} else if (type == BulletType.Symbol) {
format.getBullet().setChar('\u2022');
} else if (type == BulletType.Picture) {
format.getBullet().getPicture().setImage(bulletImage);
}
textFrame.getParagraphs().add(paragraph);
}
}
ListBuilder list = new ListBuilder();
list.addParagraph("First item", (short) 0, BulletType.Numbered, (short) 5, NumberedBulletStyle.BulletArabicPeriod);
list.addParagraph("Second item", (short) 0, BulletType.Numbered, (short) 5, NumberedBulletStyle.BulletArabicPeriod);
list.addParagraph("Nested item", (short) 1, BulletType.Numbered, (short) 3, NumberedBulletStyle.BulletAlphaLCPeriod);
list.addParagraph("Next nested item", (short) 1, BulletType.Numbered, (short) 3, NumberedBulletStyle.BulletAlphaLCPeriod);
list.addParagraph("Deep item", (short) 2, BulletType.Numbered, (short) 4, NumberedBulletStyle.BulletRomanLCPeriod);
list.addParagraph("Back to top level", (short) 0, BulletType.Numbered, (short) 5, NumberedBulletStyle.BulletArabicPeriod);
list.addParagraph("Symbol marker", (short) 0, BulletType.Symbol, (short) 1, NumberedBulletStyle.BulletArabicPeriod);
list.addParagraph("No bullet", (short) 0, BulletType.None, (short) 1, NumberedBulletStyle.BulletArabicPeriod);
list.addParagraph("Picture marker", (short) 0, BulletType.Picture, (short) 1, NumberedBulletStyle.BulletArabicPeriod);
presentation.save("actual_bullet_values.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Presentation loadedPresentation = new Presentation("actual_bullet_values.pptx");
try {
IAutoShape loadedShape = (IAutoShape) loadedPresentation.getSlides().get_Item(0).getShapes().get_Item(0);
System.out.println("Text | Depth | Type | Actual value");
for (IParagraph paragraph : loadedShape.getTextFrame().getParagraphs()) {
IBulletFormatEffectiveData bullet = paragraph.getParagraphFormat().getEffective().getBullet();
String marker;
switch (bullet.getType()) {
case BulletType.Numbered:
case BulletType.Symbol:
marker = bullet.getActualBulletValue();
break;
case BulletType.None:
marker = bullet.getActualBulletValue() + " (no bullet)";
break;
case BulletType.Picture:
marker = bullet.getActualBulletValue() + " (image required)";
break;
default:
marker = "unsupported bullet type";
break;
}
String typeName = BulletType.getName(BulletType.class, bullet.getType());
System.out.println(paragraph.getText() + " | " + paragraph.getParagraphFormat().getDepth() + " | " + typeName + " | " + marker);
}
} finally {
loadedPresentation.dispose();
}
The source lists are shown below.

The report matches the markers displayed in PowerPoint:
Text | Depth | Type | Actual value
First item | 0 | Numbered | 5.
Second item | 0 | Numbered | 6.
Nested item | 1 | Numbered | c.
Next nested item | 1 | Numbered | d.
Deep item | 2 | Numbered | iv.
Back to top level | 0 | Numbered | 7.
Symbol marker | 0 | Symbol | •
No bullet | 0 | None | null (no bullet)
Picture marker | 0 | Picture | null (image required)
Untuk BulletType.None and BulletType.Picture, getActualBulletValue mengembalikan null, bukan string kosong. Tangani tipe‑tipe ini secara terpisah: yang pertama tidak memiliki penanda, sedangkan yang kedua memerlukan ekstraksi gambar bullet secara terpisah. Picture bullet tidak dapat direproduksi hanya dengan mengekstrak penanda teks.
FAQ
Can bulleted and numbered lists be exported to PDF or images?
Ya. Aspose.Slides mempertahankan pemformatan daftar ketika format target mendukung tata letak teks dan fitur bullet yang bersangkutan.
Can I edit lists in existing presentations?
Ya. Muat presentasi, akses paragraf target, periksa atau perbarui pengaturan IParagraphFormat.getBullet, dan simpan presentasi.
Can lists contain non-Latin text?
Ya. Teks item daftar dapat berisi karakter Unicode, sehingga Anda dapat membuat daftar dalam presentasi multibahasa. Pastikan font yang digunakan dalam presentasi mendukung karakter yang Anda butuhkan.