Manage PowerPoint Text Paragraphs in JavaScript
Aspose.Slides provides all the classs and classes you need to work with PowerPoint texts, paragraphs, and portions in Java.
- Aspose.Slides provides the TextFrame class to allow you to add objects that represent a paragraph. A
TextFameobject can have one or multiple paragraphs (each paragraph is created through a carriage return). - Aspose.Slides provides the Paragraph class to allow you to add objects that represent portions. A
Paragraphobject can have one or multiple portions (collection of text portion objects). - Aspose.Slides provides Portion class to allow you to add objects that represent texts and their formatting properties.
A Paragraph object is capable of handling texts with different formatting properties through its underlying Portion objects.
Add Multiple Paragraph Containing Multiple Portions
These steps show you how to add a text frame containing 3 paragraphs and each paragraph containing 3 portions:
- Create an instance of the Presentation class.
- Access the relevant slide’s reference through its index.
- Add a Rectangle AutoShape to the slide.
- Get the ITextFrame associated with the AutoShape.
- Create two Paragraph objects and add them to the
IParagraphscollection of the TextFrame. - Create three Portion objects for each new
Paragraph(two Portion objects for default Paragraph) and add eachPortionobject to the IPortion collection of eachParagraph. - Set some text for each portion.
- Apply your preferred formatting features to each portion using the formatting properties exposed by the
Portionobject. - Save the modified presentation.
This Javascript code is an implementation of the steps for adding paragraphs containing portions:
// Instantiate a Presentation class that represents a PPTX file
var pres = new aspose.slides.Presentation();
try {
// Accessing first slide
var slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
var ashp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 150, 300, 150);
// Access TextFrame of the AutoShape
var tf = ashp.getTextFrame();
// Create Paragraphs and Portions with different text formats
var para0 = tf.getParagraphs().get_Item(0);
var port01 = new aspose.slides.Portion();
var port02 = new aspose.slides.Portion();
para0.getPortions().add(port01);
para0.getPortions().add(port02);
var para1 = new aspose.slides.Paragraph();
tf.getParagraphs().add(para1);
var port10 = new aspose.slides.Portion();
var port11 = new aspose.slides.Portion();
var port12 = new aspose.slides.Portion();
para1.getPortions().add(port10);
para1.getPortions().add(port11);
para1.getPortions().add(port12);
var para2 = new aspose.slides.Paragraph();
tf.getParagraphs().add(para2);
var port20 = new aspose.slides.Portion();
var port21 = new aspose.slides.Portion();
var port22 = new aspose.slides.Portion();
para2.getPortions().add(port20);
para2.getPortions().add(port21);
para2.getPortions().add(port22);
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
var portion = tf.getParagraphs().get_Item(i).getPortions().get_Item(j);
portion.setText("Portion0" + j);
if (j == 0) {
portion.getPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "RED"));
portion.getPortionFormat().setFontBold(aspose.slides.NullableBool.True);
portion.getPortionFormat().setFontHeight(15);
} else if (j == 1) {
portion.getPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLUE"));
portion.getPortionFormat().setFontItalic(aspose.slides.NullableBool.True);
portion.getPortionFormat().setFontHeight(18);
}
}
}
// Write PPTX to Disk
pres.save("multiParaPort_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Manage Paragraph Bullets
Bullet lists help you to organize and present information quickly and efficiently. Bulleted paragraphs are always easier to read and understand.
- Create an instance of the Presentation class.
- Access the relevant slide’s reference through its index.
- Add an AutoShape to the selected slide.
- Access the autoshape’s TextFrame.
- Remove the default paragraph in the
TextFrame. - Create the first paragraph instance using the Paragraph class.
- Set the bullet
Typefor the paragraph toSymboland set the bullet character. - Set the paragraph
Text. - Set the paragraph
Indentfor the bullet. - Set a color for the bullet.
- Set a height of the bullet.
- Add the new paragraph to the
TextFrameparagraph collection. - Add the second paragraph and repeat the process given in steps 7 to 13.
- Save the presentation.
This Javascript code shows you how to add a paragraph bullet:
// Instantiates a Presentation class that represents a PPTX file
var pres = new aspose.slides.Presentation();
try {
// Accesses the first slide
var slide = pres.getSlides().get_Item(0);
// Adds and accesses Autoshape
var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
// Accesses the autoshape text frame
var txtFrm = aShp.getTextFrame();
// Removes the default paragraph
txtFrm.getParagraphs().removeAt(0);
// Creates a paragraph
var para = new aspose.slides.Paragraph();
// Sets a paragraph bullet style and symbol
para.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
para.getParagraphFormat().getBullet().setChar(8226);
// Sets a paragraph text
para.setText("Welcome to Aspose.Slides");
// Sets bullet indent
para.getParagraphFormat().setIndent(25);
// Sets bullet color
para.getParagraphFormat().getBullet().getColor().setColorType(aspose.slides.ColorType.RGB);
para.getParagraphFormat().getBullet().getColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
para.getParagraphFormat().getBullet().setBulletHardColor(aspose.slides.NullableBool.True);// set IsBulletHardColor to true to use own bullet color
// Sets Bullet Height
para.getParagraphFormat().getBullet().setHeight(100);
// Adds Paragraph to text frame
txtFrm.getParagraphs().add(para);
// Creates second paragraph
var para2 = new aspose.slides.Paragraph();
// Sets paragraph bullet type and style
para2.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
para2.getParagraphFormat().getBullet().setNumberedBulletStyle(aspose.slides.NumberedBulletStyle.BulletCircleNumWDBlackPlain);
// Adds paragraph text
para2.setText("This is numbered bullet");
// Sets bullet indent
para2.getParagraphFormat().setIndent(25);
para2.getParagraphFormat().getBullet().getColor().setColorType(aspose.slides.ColorType.RGB);
para2.getParagraphFormat().getBullet().getColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
para2.getParagraphFormat().getBullet().setBulletHardColor(aspose.slides.NullableBool.True);// set IsBulletHardColor to true to use own bullet color
// Sets Bullet Height
para2.getParagraphFormat().getBullet().setHeight(100);
// Adds Paragraph to text frame
txtFrm.getParagraphs().add(para2);
// Saves the modified presentation
pres.save("Bullet_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Manage Picture Bullets
Bullet lists help you to organize and present information quickly and efficiently. Picture paragraphs are easy to read and understand.
- Create an instance of the Presentation class.
- Access the relevant slide’s reference through its index.
- Add an AutoShape to the slide.
- Access the autoshape’s TextFrame.
- Remove the default paragraph in the
TextFrame. - Create the first paragraph instance using the Paragraph class.
- Load the image in PPImage.
- Set the bullet type to Picture and set the image.
- Set the Paragraph
Text. - Set the Paragraph
Indentfor the bullet. - Set a color for the bullet.
- Set a height for the bullet.
- Add the new paragraph to the
TextFrameparagraph collection. - Add the second paragraph and repeat the process based on the previous steps.
- Save the modified presentation.
This Javascript code shows you how to add and manage picture bullets:
// Instantiates a Presentation class that represents a PPTX file
var presentation = new aspose.slides.Presentation();
try {
// Accesses the first slide
var slide = presentation.getSlides().get_Item(0);
// Instantiates the image for bullets
var picture;
var image = aspose.slides.Images.fromFile("bullets.png");
try {
picture = presentation.getImages().addImage(image);
} finally {
if (image != null) {
image.dispose();
}
}
// Adds and accesses Autoshape
var autoShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
// Accesses the autoshape textframe
var textFrame = autoShape.getTextFrame();
// Removes the default paragraph
textFrame.getParagraphs().removeAt(0);
// Creates a new paragraph
var paragraph = new aspose.slides.Paragraph();
paragraph.setText("Welcome to Aspose.Slides");
// Sets paragraph bullet style and image
paragraph.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Picture);
paragraph.getParagraphFormat().getBullet().getPicture().setImage(picture);
// Sets bullet Height
paragraph.getParagraphFormat().getBullet().setHeight(100);
// Adds paragraph to text frame
textFrame.getParagraphs().add(paragraph);
// Writes the presentation as a PPTX file
presentation.save("ParagraphPictureBulletsPPTX_out.pptx", aspose.slides.SaveFormat.Pptx);
// Writes the presentation as a PPT file
presentation.save("ParagraphPictureBulletsPPT_out.ppt", aspose.slides.SaveFormat.Ppt);
} catch (e) {console.log(e);
} finally {
if (presentation != null) {
presentation.dispose();
}
}
Manage Multilevel Bullets
Bullet lists help you to organize and present information quickly and efficiently. Multilevel bullets are easy to read and understand.
- Create an instance of the Presentation class.
- Access the relevant slide’s reference through its index.
- Add an AutoShape in the new slide.
- Access the autoshape’s TextFrame.
- Remove the default paragraph in the
TextFrame. - Create the first paragraph instance through the Paragraph class and set the depth to 0.
- Create the second paragraph instance through the
Paragraphclass and set the depth set to 1. - Create the third paragraph instance through the
Paragraphclass and set the depth set to 2. - Create the fourth paragraph instance through the
Paragraphclass and set the depth set to 3. - Add the new paragraphs to the
TextFrameparagraph collection. - Save the modified presentation.
This Javascript code shows you how to add and manage multilevel bullets:
// Instantiates a Presentation class that represents a PPTX file
var pres = new aspose.slides.Presentation();
try {
// Accesses the first slide
var slide = pres.getSlides().get_Item(0);
// Adds and accesses Autoshape
var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
// Accesses the text frame of created autoshape
var text = aShp.addTextFrame("");
// Clears the default paragraph
text.getParagraphs().clear();
// Adds the first paragraph
var para1 = new aspose.slides.Paragraph();
para1.setText("Content");
para1.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
para1.getParagraphFormat().getBullet().setChar(8226);
para1.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
para1.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
// Sets the bullet level
para1.getParagraphFormat().setDepth(0);
// Adds the second paragraph
var para2 = new aspose.slides.Paragraph();
para2.setText("Second Level");
para2.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
para2.getParagraphFormat().getBullet().setChar('-');
para2.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
para2.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
// Sets the bullet level
para2.getParagraphFormat().setDepth(1);
// Adds the third paragraph
var para3 = new aspose.slides.Paragraph();
para3.setText("Third Level");
para3.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
para3.getParagraphFormat().getBullet().setChar(8226);
para3.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
para3.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
// Sets the bullet level
para3.getParagraphFormat().setDepth(2);
// Adds the fourth paragraph
var para4 = new aspose.slides.Paragraph();
para4.setText("Fourth Level");
para4.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
para4.getParagraphFormat().getBullet().setChar('-');
para4.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
para4.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
// Sets the bullet level
para4.getParagraphFormat().setDepth(3);
// Adds paragraphs to collection
text.getParagraphs().add(para1);
text.getParagraphs().add(para2);
text.getParagraphs().add(para3);
text.getParagraphs().add(para4);
// Writes the presentation as a PPTX file
pres.save("MultilevelBullet.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Manage Paragraph with Custom Numbered List
The BulletFormat class provides the NumberedBulletStartWith property and others that allow you to manage paragraphs with custom numbering or formatting.
- Create an instance of the Presentation class.
- Access the slide containing the paragraph.
- Add an AutoShape to the slide.
- Access the autoshape TextFrame.
- Remove the default paragraph in the
TextFrame. - Create the first paragraph instance through the Paragraph class and set NumberedBulletStartWith to 2.
- Create the second paragraph instance through the
Paragraphclass and setNumberedBulletStartWithto 3. - Create the third paragraph instance through the
Paragraphclass and setNumberedBulletStartWithto 7. - Add the new paragraphs to the
TextFrameparagraph collection. - Save the modified presentation.
This Javascript code shows you how to add and manage paragraphs with custom numbering or formatting:
var presentation = new aspose.slides.Presentation();
try {
var shape = presentation.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
// Accesses the text frame of created autoshape
var textFrame = shape.getTextFrame();
// Removes the default exisiting paragraph
textFrame.getParagraphs().removeAt(0);
// First list
var paragraph1 = new aspose.slides.Paragraph();
paragraph1.setText("bullet 2");
paragraph1.getParagraphFormat().setDepth(4);
paragraph1.getParagraphFormat().getBullet().setNumberedBulletStartWith(2);
paragraph1.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
textFrame.getParagraphs().add(paragraph1);
var paragraph2 = new aspose.slides.Paragraph();
paragraph2.setText("bullet 3");
paragraph2.getParagraphFormat().setDepth(4);
paragraph2.getParagraphFormat().getBullet().setNumberedBulletStartWith(3);
paragraph2.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
textFrame.getParagraphs().add(paragraph2);
var paragraph5 = new aspose.slides.Paragraph();
paragraph5.setText("bullet 7");
paragraph5.getParagraphFormat().setDepth(4);
paragraph5.getParagraphFormat().getBullet().setNumberedBulletStartWith(7);
paragraph5.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
textFrame.getParagraphs().add(paragraph5);
presentation.save("SetCustomBulletsNumber-slides.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (presentation != null) {
presentation.dispose();
}
}
Set First-Line Indent for a Paragraph
Use the ParagraphFormat.setIndent method to control the first-line indent of a paragraph. This method moves only the first line relative to the paragraph’s left margin. A positive value shifts the first line to the right, while the remaining lines stay aligned to the paragraph body.
Use ParagraphFormat.setMarginLeft when you need to move the whole paragraph. Use ParagraphFormat.setIndent when you need to move only the first line.
The example below creates several paragraphs and applies different indent values to demonstrate how the first-line indent affects paragraph layout.
- Create an instance of the Presentation class.
- Access the target slide.
- Add a rectangular AutoShape to the slide.
- Add an empty TextFrame to the shape and remove the default paragraph.
- Create several paragraphs and set different Indent values for them.
- Add the paragraphs to the text frame.
- Save the modified presentation.
This code shows you how to set a paragraph indent:
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let rectangleShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 420, 220);
rectangleShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
rectangleShape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
rectangleShape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "GRAY"));
let textFrame = rectangleShape.addTextFrame("");
textFrame.getTextFrameFormat().setAutofitType(java.newByte(aspose.slides.TextAutofitType.Shape));
textFrame.getParagraphs().removeAt(0);
let firstParagraph = new aspose.slides.Paragraph();
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
firstParagraph.setText("No first-line indent. Wrapped lines start at the same position as the first line.");
firstParagraph.getParagraphFormat().setMarginLeft(20);
firstParagraph.getParagraphFormat().setIndent(0);
let secondParagraph = new aspose.slides.Paragraph();
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
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().setMarginLeft(20);
secondParagraph.getParagraphFormat().setIndent(20);
let thirdParagraph = new aspose.slides.Paragraph();
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
thirdParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
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().setMarginLeft(20);
thirdParagraph.getParagraphFormat().setIndent(40);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
textFrame.getParagraphs().add(thirdParagraph);
presentation.save("paragraph_indent.pptx", aspose.slides.SaveFormat.Pptx);
}
finally {
presentation.dispose();
}
The result:

Set Hanging Indent for a Paragraph
A hanging indent is a paragraph layout in which the first line starts to the left of the remaining lines. In Aspose.Slides, you create this effect with the ParagraphFormat.setIndent method. Set the indent to a negative value to move the first line to the left relative to the paragraph body.
In practice, ParagraphFormat.setMarginLeft defines the left position of the paragraph body, and ParagraphFormat.setIndent defines the position of the first line relative to that margin. To create a hanging indent, set a positive MarginLeft value and a negative Indent value.
This formatting is useful for bibliographies, references, glossary entries, and other paragraphs where wrapped lines must align under the paragraph body rather than under the first character of the first line.
- Create an instance of the Presentation class.
- Access the target slide.
- Add a rectangular AutoShape to the slide.
- Add an empty TextFrame to the shape and remove the default paragraph.
- Create paragraphs and set a positive MarginLeft value for each paragraph.
- Set a negative Indent value to create the hanging indent effect.
- Add the paragraphs to the text frame.
- Save the modified presentation.
This code shows you how to set a hanging indent for a paragraph:
let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let rectangleShape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 50, 50, 420, 220);
rectangleShape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
rectangleShape.getLineFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
rectangleShape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "GRAY"));
let textFrame = rectangleShape.addTextFrame("");
textFrame.getTextFrameFormat().setAutofitType(java.newByte(aspose.slides.TextAutofitType.Shape));
textFrame.getParagraphs().removeAt(0);
let firstParagraph = new aspose.slides.Paragraph();
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
firstParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
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().setMarginLeft(40);
firstParagraph.getParagraphFormat().setIndent(-20);
let secondParagraph = new aspose.slides.Paragraph();
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
secondParagraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
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().setMarginLeft(60);
secondParagraph.getParagraphFormat().setIndent(-30);
textFrame.getParagraphs().add(firstParagraph);
textFrame.getParagraphs().add(secondParagraph);
presentation.save("hanging_indent.pptx", aspose.slides.SaveFormat.Pptx);
}
finally {
presentation.dispose();
}
The result:

Manage End Paragraph Run Properties for Paragraph
- Create an instance of Presentation class.
- Get the reference for the slide containing the paragraph through its position.
- Add a rectangle AutoShape to the slide.
- Add a TextFrame with two paragraphs to the Rectangle.
- Set the
FontHeightand Font type for the paragraphs. - Set the End properties for the paragraphs.
- Write the modified presentation as a PPTX file.
This Javascript code shows you how to set the End properties for paragraphs in PowerPoint:
var pres = new aspose.slides.Presentation();
try {
var shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 10, 10, 200, 250);
var para1 = new aspose.slides.Paragraph();
para1.getPortions().add(new aspose.slides.Portion("Sample text"));
var para2 = new aspose.slides.Paragraph();
para2.getPortions().add(new aspose.slides.Portion("Sample text 2"));
var portionFormat = new aspose.slides.PortionFormat();
portionFormat.setFontHeight(48);
portionFormat.setLatinFont(new aspose.slides.FontData("Times New Roman"));
para2.setEndParagraphPortionFormat(portionFormat);
shape.getTextFrame().getParagraphs().add(para1);
shape.getTextFrame().getParagraphs().add(para2);
pres.save(resourcesOutputPath + "pres.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Import HTML Text into Paragraphs
Aspose.Slides provides enhanced support for importing HTML text into paragraphs.
- Create an instance of the Presentation class.
- Access the relevant slide’s reference through its index.
- Add an AutoShape to the slide.
- Add and access
AutoShape’s TextFrame. - Remove the default paragraph in the
TextFrame. - Read the source HTML file in a TextReader.
- Create the first paragraph instance through the Paragraph class.
- Add the HTML file content in the read TextReader to the TextFrame’s ParagraphCollection.
- Save the modified presentation.
This Javascript code is an implementation of the steps for importing HTML texts in paragraphs:
// Create Empty presentation instance
var pres = new aspose.slides.Presentation();
try {
// Acesss the default first slide of presentation
var slide = pres.getSlides().get_Item(0);
// Adding the AutoShape to accomodate the HTML content
var ashape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 10, 10, pres.getSlideSize().getSize().getWidth() - 20, pres.getSlideSize().getSize().getHeight() - 10);
ashape.getFillFormat().setFillType(java.newByte(aspose.slides.FillType.NoFill));
// Adding text frame to the shape
ashape.addTextFrame("");
// Clearing all paragraphs in added text frame
ashape.getTextFrame().getParagraphs().clear();
// Loading the HTML file using stream reader
var tr = java.newInstanceSync("StreamReader", "file.html");
// Adding text from HTML stream reader in text frame
ashape.getTextFrame().getParagraphs().addFromHtml(tr.readToEnd());
// Saving Presentation
pres.save("output.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Export Paragraphs Text to HTML
Aspose.Slides provides enhanced support for exporting texts (contained in paragraphs) to HTML.
- Create an instance of the Presentation class and load the desired presentation.
- Access the relevant slide’s reference through its index.
- Access the shape containing the text that will be exported to HTML.
- Access the shape TextFrame.
- Create an instance of
StreamWriterand add the new HTML file. - Provide a starting index to StreamWriter and export your preferred paragraphs.
This Javascript code shows you how to export PowerPoint paragraph texts to HTML:
// Load the presentation file
var pres = new aspose.slides.Presentation("ExportingHTMLText.pptx");
try {
// Acesss the default first slide of presentation
var slide = pres.getSlides().get_Item(0);
// Desired index
var index = 0;
// Accessing the added shape
var ashape = slide.getShapes().get_Item(index);
// Creating output HTML file
var os = java.newInstanceSync("java.io.FileOutputStream", "output.html");
var writer = java.newInstanceSync("java.io.OutputStreamWriter", os, "UTF-8");
// Extracting first paragraph as HTML
// Writing Paragraphs data to HTML by providing paragraph starting index, total paragraphs to be copied
writer.write(ashape.getTextFrame().getParagraphs().exportToHtml(0, ashape.getTextFrame().getParagraphs().getCount(), null));
writer.close();
} catch (e) {console.log(e);
} finally {
if (pres != null) {
pres.dispose();
}
}
Save a Paragraph as an Image
In this section, we will explore two examples that demonstrate how to save a text paragraph, represented by the Paragraph class, as an image. Both examples include obtaining the image of a shape containing the paragraph using the getImage methods from the Shape class, calculating the bounds of the paragraph within the shape, and exporting it as a bitmap image. These approaches allow you to extract specific parts of the text from PowerPoint presentations and save them as separate images, which can be useful for further use in various scenarios.
Let’s assume we have a presentation file called sample.pptx with one slide, where the first shape is a text box containing three paragraphs.

Example 1
In this example, we obtain the second paragraph as an image. To do this, we extract the image of the shape from the first slide of the presentation and then calculate the bounds of the second paragraph in the shape’s text frame. The paragraph is then redrawn onto a new bitmap image, which is saved in PNG format. This method is especially useful when you need to save a specific paragraph as a separate image while preserving the exact dimensions and formatting of the text.
const imageio = java.import("javax.imageio.ImageIO");
const presentation = new aspose.slides.Presentation("sample.pptx");
try {
const firstShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
// Save the shape in memory as a bitmap.
const shapeImage = firstShape.getImage();
const shapeImageStream = java.newInstanceSync("java.io.ByteArrayOutputStream");
shapeImage.save(shapeImageStream, aspose.slides.ImageFormat.Png);
shapeImage.dispose();
shapeImageStream.flush();
// Create a shape bitmap from memory.
const byteBuffer = java.callMethodSync(shapeImageStream, "toByteArray");
const javaBytes = java.newArray("byte", Array.from(byteBuffer));
const ByteArrayInputStream = java.import("java.io.ByteArrayInputStream");
const shapeImageInputStream = new ByteArrayInputStream(javaBytes);
const shapeBitmap = imageio.read(shapeImageInputStream);
// Calculate the boundaries of the second paragraph.
const secondParagraph = firstShape.getTextFrame().getParagraphs().get_Item(1);
const paragraphRectangle = secondParagraph.getRect();
// Calculate the coordinates and size for the output image (minimum size - 1x1 pixel).
const imageX = Math.floor(paragraphRectangle.getX());
const imageY = Math.floor(paragraphRectangle.getY());
const imageWidth = Math.max(1, Math.ceil(paragraphRectangle.getWidth()));
const imageHeight = Math.max(1, Math.ceil(paragraphRectangle.getHeight()));
// Crop the shape bitmap to get the paragraph bitmap only.
const paragraphBitmap = shapeBitmap.getSubimage(imageX, imageY, imageWidth, imageHeight);
const file = java.newInstanceSync("java.io.File", "paragraph.png");
imageio.write(paragraphBitmap, "png", file);
} finally {
if (presentation != null) {
presentation.dispose();
}
}
The result:

Example 2
In this example, we extend the previous approach by adding scaling factors to the paragraph image. The shape is extracted from the presentation and saved as an image with a scaling factor of 2. This allows for a higher resolution output when exporting the paragraph. The paragraph bounds are then calculated considering the scale. Scaling can be particularly useful when a more detailed image is needed, for example, for use in high-quality printed materials.
const imageScaleX = 2;
const imageScaleY = imageScaleX;
const imageio = java.import("javax.imageio.ImageIO");
const presentation = new aspose.slides.Presentation("sample.pptx");
try {
const firstShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
// Save the shape in memory as a bitmap with scaling.
const shapeImage = firstShape.getImage(aspose.slides.ShapeThumbnailBounds.Shape, imageScaleX, imageScaleY);
const shapeImageStream = java.newInstanceSync("java.io.ByteArrayOutputStream");
shapeImage.save(shapeImageStream, aspose.slides.ImageFormat.Png);
shapeImage.dispose();
// Create a shape bitmap from memory.
const byteBuffer = java.callMethodSync(shapeImageStream, "toByteArray");
const javaBytes = java.newArray("byte", Array.from(byteBuffer));
const ByteArrayInputStream = java.import("java.io.ByteArrayInputStream");
const shapeImageInputStream = new ByteArrayInputStream(javaBytes);
const shapeBitmap = imageio.read(shapeImageInputStream);
// Calculate the boundaries of the second paragraph.
const secondParagraph = firstShape.getTextFrame().getParagraphs().get_Item(1);
const paragraphRectangle = secondParagraph.getRect();
paragraphRectangle.setRect(
paragraphRectangle.getX() * imageScaleX,
paragraphRectangle.getY() * imageScaleY,
paragraphRectangle.getWidth() * imageScaleX,
paragraphRectangle.getHeight() * imageScaleY
);
// Calculate the coordinates and size for the output image (minimum size - 1x1 pixel).
const imageX = Math.floor(paragraphRectangle.getX());
const imageY = Math.floor(paragraphRectangle.getY());
const imageWidth = Math.max(1, Math.ceil(paragraphRectangle.getWidth()));
const imageHeight = Math.max(1, Math.ceil(paragraphRectangle.getHeight()));
// Crop the shape bitmap to get the paragraph bitmap only.
const paragraphBitmap = shapeBitmap.getSubimage(imageX, imageY, imageWidth, imageHeight);
const file = java.newInstanceSync("java.io.File", "paragraph.png");
imageio.write(paragraphBitmap, "png", file);
} finally {
if (presentation != null) {
presentation.dispose();
}
}
FAQ
Can I completely disable line wrapping inside a text frame?
Yes. Use the text frame’s wrapping setting (setWrapText) to turn wrapping off so lines won’t break at the frame’s edges.
How can I get the exact on-slide bounds of a specific paragraph?
You can retrieve the paragraph’s (and even a single portion’s) bounding rectangle to know its precise position and size on the slide.
Where is paragraph alignment (left/right/center/justify) controlled?
setAlignment is a method for a paragraph-level setting in ParagraphFormat; it applies to the whole paragraph regardless of individual portion formatting.
Can I set a spell-check language for just part of a paragraph (e.g., one word)?
Yes. The language is set at the portion level (PortionFormat.setLanguageId), so multiple languages can coexist within a single paragraph.