### Python Project Setup with Setuptools
Source: https://github.com/aspose-slides/aspose.slides-for-java/blob/master/Plugins/Aspose-Slides-Java-for-Python/untitled text 5.txt
This snippet shows the standard Python setup configuration using setuptools. It defines the package name, version, description, author information, and classifiers for the project.
```python
from setuptools import setup, find_packages
setup(
name = 'aspose-slides-java-for-python',
packages = find_packages(),
version = '1.0',
description = 'Aspose.Slides Java for Python is a project that demonstrates / provides the Aspose.Slides for Java API usage examples in Python.',
author='Fahad Adeel',
author_email='slides@aspose.com',
url='http://www.aspose.com/docs/display/slidesjava/Aspose.Slides+Java+for+Python',
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent'
]
)
```
--------------------------------
### Create WordArt with 3D Effects
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Applies various effects like shadow, glow, and 3D bevels to text within a shape. This example demonstrates setting font properties, text transformations, and 3D formatting. Ensure the `Presentation` object is disposed after use.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation();
try {
IAutoShape shape = pres.getSlides().get_Item(0).getShapes()
.addAutoShape(ShapeType.Rectangle, 100, 100, 400, 150);
ITextFrame tf = shape.getTextFrame();
Portion portion = (Portion) tf.getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.setText("WordArt Demo");
portion.getPortionFormat().setLatinFont(new FontData("Arial Black"));
portion.getPortionFormat().setFontHeight(36);
// Outer shadow
portion.getPortionFormat().getEffectFormat().enableOuterShadowEffect();
portion.getPortionFormat().getEffectFormat().getOuterShadowEffect()
.getShadowColor().setColor(Color.BLACK);
portion.getPortionFormat().getEffectFormat().getOuterShadowEffect().setBlurRadius(4.73);
portion.getPortionFormat().getEffectFormat().getOuterShadowEffect().setDirection(230);
// Glow
portion.getPortionFormat().getEffectFormat().enableGlowEffect();
portion.getPortionFormat().getEffectFormat().getGlowEffect().getColor().setR((byte) 255);
portion.getPortionFormat().getEffectFormat().getGlowEffect().setRadius(7);
// Arc text transform
tf.getTextFrameFormat().setTransform(TextShapeType.ArchUpPour);
// 3D bevel on shape
shape.getThreeDFormat().getBevelTop().setBevelType(BevelPresetType.Circle);
shape.getThreeDFormat().getBevelTop().setHeight(12.5);
shape.getThreeDFormat().setDepth(3);
shape.getThreeDFormat().setMaterial(MaterialPresetType.Plastic);
pres.save("WordArt.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Embed Audio File into Presentation
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
This example shows how to embed an audio file (WAV or MP3) into a slide and configure its playback properties such as playing across slides, rewinding, auto-play mode, and volume. Ensure the audio file exists and the presentation object is disposed.
```java
import com.aspose.slides.*;
import java.io.FileInputStream;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
try (FileInputStream fstr = new FileInputStream("audio.wav")) {
IAudioFrame af = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr);
af.setPlayAcrossSlides(true);
af.setRewindAudio(true);
af.setPlayMode(AudioPlayModePreset.Auto);
af.setVolume(AudioVolumeMode.Loud);
}
pres.save("WithAudio.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Check Presentation Password Without Opening in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Use PresentationFactory.getPresentationInfo() to get metadata and verify a password without fully loading the presentation. This is useful for checking password correctness.
```java
import com.aspose.slides.*;
IPresentationInfo info = PresentationFactory.getInstance()
.getPresentationInfo("ProtectedPresentation.ppt");
boolean correct = info.checkPassword("pass1");
System.out.println("Password correct: " + correct); // true / false
```
--------------------------------
### Add Shape Animations with Different Triggers
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
This snippet demonstrates adding two types of animations: an auto-play animation that starts after the previous one ends, and a custom animation triggered by a click. It also shows how to define a custom motion path. Ensure the presentation object is disposed.
```java
import com.aspose.slides.*;
import java.awt.geom.Point2D;
import java.lang.reflect.Array;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
IAutoShape box = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 150, 250, 25);
box.addTextFrame("Animated TextBox");
// Auto-play PathFootball on previous effect end
pres.getSlides().get_Item(0).getTimeline().getMainSequence()
.addEffect(box, EffectType.PathFootball,
EffectSubtype.None, EffectTriggerType.AfterPrevious);
// Custom user-path motion on button click
IShape btn = sld.getShapes().addAutoShape(ShapeType.Bevel, 10, 10, 20, 20);
ISequence seq = sld.getTimeline().getInteractiveSequences().add(btn);
IEffect fx = seq.addEffect(box, EffectType.PathUser,
EffectSubtype.None, EffectTriggerType.OnClick);
IMotionEffect motion = (IMotionEffect) fx.getBehaviors().get_Item(0);
Point2D.Float[] pts = (Point2D.Float[]) Array.newInstance(Point2D.Float.class, 1);
pts[0] = new Point2D.Float(0.076f, 0.59f);
motion.getPath().add(MotionCommandPathType.LineTo, pts, MotionPathPointsType.Auto, true);
pts[0] = new Point2D.Float(-0.076f, -0.59f);
motion.getPath().add(MotionCommandPathType.LineTo, pts, MotionPathPointsType.Auto, false);
motion.getPath().add(MotionCommandPathType.End, null, MotionPathPointsType.Auto, false);
pres.save("AnimatedShape.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create and Save a Presentation in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Instantiate Presentation to create a new presentation from scratch. Add shapes and text, then save the presentation to a file.
```java
import com.aspose.slides.*;
// Create a new presentation from scratch
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
// Add a rectangle auto-shape with text
IAutoShape shape = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 300, 80);
shape.addTextFrame("Hello, Aspose.Slides!");
// Style the text portion
IPortion portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.BLACK);
portion.getPortionFormat().setFontHeight(24f);
// Remove shape fill, keep border white
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getShapeStyle().getLineColor().setColor(java.awt.Color.WHITE);
// Save as PPTX
pres.save("output.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create Table from Scratch in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Demonstrates creating a table shape from scratch using `IShapeCollection.addTable()`, defining column widths and row heights. Includes styling cell borders and merging cells.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
double[] cols = {120, 120, 120};
double[] rows = {40, 40, 40, 40};
ITable tbl = sld.getShapes().addTable(50, 50, cols, rows);
// Style all cell borders
for (int r = 0; r < tbl.getRows().size(); r++) {
for (int c = 0; c < tbl.getRows().get_Item(r).size(); c++) {
ICellFormat fmt = tbl.get_Item(c, r).getCellFormat();
for (ILineFormat border : new ILineFormat[]{
fmt.getBorderTop(), fmt.getBorderBottom(),
fmt.getBorderLeft(), fmt.getBorderRight()})
{
border.getFillFormat().setFillType(FillType.Solid);
border.getFillFormat().getSolidFillColor().setColor(Color.DARK_GRAY);
border.setWidth(2);
}
}
}
// Merge cells (0,0) through (1,1)
tbl.mergeCells(tbl.get_Item(0, 0), tbl.get_Item(1, 1), false);
tbl.get_Item(0, 0).getTextFrame().setText("Merged Header");
// Fill remaining cells
tbl.get_Item(2, 0).getTextFrame().setText("Col C");
tbl.get_Item(0, 1).getTextFrame().setText("Row 2");
pres.save("Table.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create Presentation from Scratch in Java
Source: https://github.com/aspose-slides/aspose.slides-for-java/blob/master/README.md
Instantiate a Presentation object, add shapes and text to slides, and save the presentation. Remember to dispose of the Presentation object.
```java
Presentation pres = new Presentation();
try {
ISlide sld = (ISlide) pres.getSlides().get_Item(0);
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
ashp.addTextFrame("Hello World");
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat()
.setFillType(FillType.Solid);
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat()
.getSolidFillColor().setColor(java.awt.Color.BLACK);
ashp.getShapeStyle().getLineColor().setColor(java.awt.Color.WHITE);
ashp.getFillFormat().setFillType(FillType.NoFill);
pres.save("output.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create Pie Chart with Styled Sectors in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Demonstrates how to create a pie chart, add data points, and style individual sectors using `addDataPointForPieSeries()`. Enables varied sector colors and custom labels.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes()
.addChart(ChartType.Pie, 100, 100, 400, 400);
chart.getChartTitle().addTextFrameForOverriding("Market Share");
chart.setTitle(true);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
chart.getChartData().getCategories().add(wb.getCell(0, 1, 0, "Product A"));
chart.getChartData().getCategories().add(wb.getCell(0, 2, 0, "Product B"));
chart.getChartData().getCategories().add(wb.getCell(0, 3, 0, "Product C"));
IChartSeries series = chart.getChartData().getSeries()
.add(wb.getCell(0, 0, 1, "Series 1"), chart.getType());
series.getDataPoints().addDataPointForPieSeries(wb.getCell(0, 1, 1, 45));
series.getDataPoints().addDataPointForPieSeries(wb.getCell(0, 2, 1, 30));
series.getDataPoints().addDataPointForPieSeries(wb.getCell(0, 3, 1, 25));
// Enable varied sector colors
chart.getChartData().getSeriesGroups().get_Item(0).setColorVaried(true);
// Custom label: show percentage on slice 1
series.getDataPoints().get_Item(1).getLabel().getDataLabelFormat().setShowPercentage(true);
series.getDataPoints().get_Item(1).getLabel().getDataLabelFormat().setShowLegendKey(true);
// Rotate first slice start angle
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);
pres.save("PieChart.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Initialize Aspose.Slides for Java in Ruby
Source: https://github.com/aspose-slides/aspose.slides-for-java/blob/master/Plugins/Aspose_Slides_Java_for_Ruby/README.md
This snippet shows how to require the Aspose.Slides library and initialize it for use within a Ruby script. Ensure the library path is correctly set.
```ruby
require File.dirname(File.dirname(File.dirname(__FILE__))) + '/lib/asposeslidesjava'
include Asposeslidesjava
include Asposeslidesjava::HelloWorld
initialize_aspose_slides
```
--------------------------------
### Convert Presentation to PDF in Java
Source: https://github.com/aspose-slides/aspose.slides-for-java/blob/master/README.md
Instantiate a Presentation object and save it to PDF format. Ensure the Presentation object is disposed of after use.
```java
Presentation pres = new Presentation("demo.pptx");
try {
pres.save("output.pdf", SaveFormat.Pdf);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Open a Password-Protected Presentation in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Use LoadOptions.setPassword() to provide the decryption password before loading a protected presentation. Ensure to dispose of the presentation object.
```java
import com.aspose.slides.*;
LoadOptions loadOptions = new LoadOptions();
loadOptions.setPassword("pass");
Presentation pres = new Presentation("ProtectedPresentation.pptx", loadOptions);
try {
System.out.println("Slide count: " + pres.getSlides().size());
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to Password-Protected PDF
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Creates a password-protected PDF output by setting a password using PdfOptions. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Demo.pptx");
try {
PdfOptions opts = new PdfOptions();
opts.setPassword("pdfPassword");
pres.save("ProtectedOutput.pdf", SaveFormat.Pdf, opts);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Embed Video File into Presentation
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Demonstrates how to embed a local video file into a slide and set its playback mode and volume. Make sure the video file path is correct and dispose of the presentation object.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, "video.mp4");
vf.setPlayMode(VideoPlayModePreset.Auto);
vf.setVolume(AudioVolumeMode.Loud);
pres.save("WithVideo.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Encrypt Presentation with Password in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Use ProtectionManager.encrypt() to set a password for the presentation. This password will be required when opening the file. Ensure to dispose of the presentation object.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
// ... build your presentation content ...
pres.getProtectionManager().encrypt("mySecretPass");
pres.save("EncryptedPresentation.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to Custom PDF
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to PDF with custom options including JPEG quality, metafiles as PNG, text compression, PDF/A compliance, and notes layout. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
// PDF with custom options (JPEG quality, text compression, PDF/A compliance, notes)
Presentation pres2 = new Presentation("Demo.pptx");
try {
PdfOptions opts = new PdfOptions();
opts.setJpegQuality((byte) 90);
opts.setSaveMetafilesAsPng(true);
opts.setTextCompression(PdfTextCompression.Flate);
opts.setCompliance(PdfCompliance.PdfA2a);
NotesCommentsLayoutingOptions notesOpts = new NotesCommentsLayoutingOptions();
notesOpts.setNotesPosition(NotesPositions.BottomFull);
opts.setSlidesLayoutOptions(notesOpts);
pres2.save("output_custom.pdf", SaveFormat.Pdf, opts);
} finally {
if (pres2 != null) pres2.dispose();
}
```
--------------------------------
### Convert Presentation to Default PDF
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to a standard PDF file using default options. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
// Default PDF export
Presentation pres = new Presentation("Demo.pptx");
try {
pres.save("output.pdf", SaveFormat.Pdf);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to GIF
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to a GIF animation with configurable frame size, slide delay, and transition frame rate. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
import java.awt.Dimension;
Presentation pres = new Presentation("Presentation.pptx");
try {
GifOptions gifOpts = new GifOptions();
gifOpts.setFrameSize(new Dimension(540, 480));
gifOpts.setDefaultDelay(1500); // ms per slide
gifOpts.setTransitionFps(60); // smooth animation
pres.save("output.gif", SaveFormat.Gif, gifOpts);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Set Default Opening View
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Configures the default view that opens when the presentation file is launched using `ViewProperties.setLastView()`. Ensure the `Presentation` object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
pres.getViewProperties().setLastView(ViewType.SlideMasterView);
pres.save("SetViewType.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to HTML
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to classic HTML format with options for HTML formatter and notes layout. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Presentation.pptx");
try {
HtmlOptions htmlOpts = new HtmlOptions();
htmlOpts.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
NotesCommentsLayoutingOptions notesOpts = new NotesCommentsLayoutingOptions();
notesOpts.setNotesPosition(NotesPositions.BottomFull);
htmlOpts.setSlidesLayoutOptions(notesOpts);
pres.save("output.html", SaveFormat.Html, htmlOpts);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to HTML5
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to modern HTML5 format, with options to enable shape and transition animations. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Demo.pptx");
try {
Html5Options opts = new Html5Options();
opts.setAnimateShapes(true);
opts.setAnimateTransitions(true);
pres.save("Demo.html", SaveFormat.Html5, opts);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Save Presentation to a Stream in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Use Presentation.save(OutputStream, SaveFormat) to write the presentation directly to any Java OutputStream. Remember to dispose of the presentation object.
```java
import com.aspose.slides.*;
import java.io.FileOutputStream;
Presentation pres = new Presentation();
try {
IAutoShape shape = pres.getSlides().get_Item(0).getShapes()
.addAutoShape(ShapeType.Rectangle, 200, 200, 200, 200);
shape.getTextFrame().setText("Saved to stream.");
try (FileOutputStream stream = new FileOutputStream("output_stream.pptx")) {
pres.save(stream, SaveFormat.Pptx);
}
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Add, Clone, and Remove Slides
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Use `ISlideCollection.addEmptySlide()` to add a blank slide based on a layout, `insertClone()` to duplicate an existing slide, and `remove()` to delete a slide. Remember to dispose of the presentation object.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Source.pptx");
try {
ISlideCollection slides = pres.getSlides();
// Add empty slides for each available layout
for (int i = 0; i < pres.getLayoutSlides().size(); i++) {
slides.addEmptySlide(pres.getLayoutSlides().get_Item(i));
}
// Clone slide at index 1 and insert it at position 2
slides.insertClone(2, pres.getSlides().get_Item(1));
// Remove a slide by index
slides.remove(slides.get_Item(0));
pres.save("Modified.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Add Aspose.Slides for Java Maven Dependency
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Include this XML configuration in your Maven project's pom.xml file to add the Aspose.Slides for Java library. Ensure the repository URL and version are correct for your project.
```xml
AsposeJavaAPI
Aspose Java API
https://releases.aspose.com/java/repo/
com.aspose
aspose-slides
26.4
jdk16
```
--------------------------------
### Add and Modify SmartArt Diagram
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Demonstrates how to add a SmartArt shape with a specific layout and then change its layout and node text at runtime. Ensure the presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
ISlide slide = pres.getSlides().get_Item(0);
// Add a BasicBlockList SmartArt
ISmartArt smart = slide.getShapes()
.addSmartArt(0, 0, 400, 300, SmartArtLayoutType.BasicBlockList);
// Change layout at runtime
smart.setLayout(SmartArtLayoutType.BasicProcess);
// Access and rename a node
smart.getAllNodes().get_Item(0).getTextFrame().setText("Step 1");
smart.getAllNodes().get_Item(1).getTextFrame().setText("Step 2");
pres.save("SmartArt.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Set Slide Background Image
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Set a picture as a slide background using `IBackground.getFillFormat()`. The image can be stretched to fill the background. Remember to dispose of the presentation object.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Presentation.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
// Use a picture as background
slide.getBackground().setType(BackgroundType.OwnBackground);
slide.getBackground().getFillFormat().setFillType(FillType.Picture);
slide.getBackground().getFillFormat().getPictureFillFormat()
.setPictureFillMode(PictureFillMode.Stretch);
IImage img = Images.fromFile("background.jpg");
IPPImage ppImg = pres.getImages().addImage(img);
slide.getBackground().getFillFormat().getPictureFillFormat()
.getPicture().setImage(ppImg);
pres.save("WithImageBackground.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Low-Code: Merge Multiple Presentations
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Concatenates multiple presentation files into a single output presentation using the Merger utility class. This is a straightforward method for combining presentations.
```java
import com.aspose.slides.Merger;
Merger.process(
new String[]{ "file1.pptx", "file2.pptx", "file3.pptx" },
"Merged-out.pptx"
);
```
--------------------------------
### Low-Code: Convert Presentation to JPEG, PNG, TIFF
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Utilizes the Convert utility class for a simplified, one-liner conversion of a presentation to JPEG, PNG, and TIFF image formats. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Demo.pptx");
try {
Convert.toJpeg(pres, "output.jpg");
Convert.toPng(pres, "output.png");
Convert.toTiff(pres, "output.tiff");
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Convert Presentation to Markdown
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Exports a presentation to Markdown format, with options to control the export type and the folder for embedded images. Ensure the Presentation object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Demo.pptx");
try {
MarkdownSaveOptions mdOpts = new MarkdownSaveOptions();
mdOpts.setExportType(MarkdownExportType.Visual);
mdOpts.setImagesSaveFolderName("md-images");
mdOpts.setBasePath("output/");
pres.save("output/pres.md", SaveFormat.Md, mdOpts);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Low-Code: Iterate Over Text Portions
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Traverses all text portions across all slides, including notes, using the ForEach.portion utility. A callback function is executed for each portion, allowing custom processing like printing text content.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Demo.pptx");
try {
ForEach.portion(pres, true, (portion, para, slide, index) -> {
if (!portion.getText().isEmpty())
System.out.println("[" + index + "] " + portion.getText());
});
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Find and Replace Text with Formatting
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Searches all slides for a specified text and replaces it with new text, applying a given `PortionFormat`. Ensure the `Presentation` object is disposed after use.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation("Source.pptx");
try {
PortionFormat fmt = new PortionFormat();
fmt.setFontHeight(24f);
fmt.setFontItalic(NullableBool.True);
fmt.getFillFormat().setFillType(FillType.Solid);
fmt.getFillFormat().getSolidFillColor().setColor(Color.RED);
// Replace all occurrences of "[placeholder]" with "new text" + the given format
SlideUtil.findAndReplaceText(pres, true, "[placeholder]", "new text", fmt);
pres.save("Replaced.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create a Group Shape with Multiple Shapes
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Shows how to group several shapes (rectangles and ellipses) into a single group shape, allowing them to be moved and resized together. Remember to dispose of the presentation object.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
IGroupShape group = sld.getShapes().addGroupShape();
group.getShapes().addAutoShape(ShapeType.Rectangle, 300, 100, 100, 100);
group.getShapes().addAutoShape(ShapeType.Rectangle, 500, 100, 100, 100);
group.getShapes().addAutoShape(ShapeType.Ellipse, 300, 300, 100, 100);
group.getShapes().addAutoShape(ShapeType.Ellipse, 500, 300, 100, 100);
group.setFrame(new ShapeFrame(100, 300, 500, 40,
NullableBool.False, NullableBool.False, 0));
pres.save("GroupShape.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Remove Unused Master Slides and Layouts
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Call `Compress.removeUnusedMasterSlides()` and `Compress.removeUnusedLayoutSlides()` to reduce presentation file size. Ensure to dispose of the presentation object after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("LargePresentation.pptx");
try {
System.out.println("Masters before: " + pres.getMasters().size());
Compress.removeUnusedMasterSlides(pres);
Compress.removeUnusedLayoutSlides(pres);
System.out.println("Masters after: " + pres.getMasters().size());
pres.save("Compressed.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Add Trend Lines to Chart Series in Java
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Shows how to add various analytical trend lines (Exponential, Linear, Moving Average, Polynomial) to chart series using `IChartSeries.getTrendLines().add()`. Configures display options and properties for each trend line type.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes()
.addChart(ChartType.ClusteredColumn, 20, 20, 500, 400);
// Exponential trend line on series 0
ITrendline exp = chart.getChartData().getSeries().get_Item(0)
.getTrendLines().add(TrendlineType.Exponential);
exp.setDisplayEquation(false);
// Linear trend line (red) on series 0
ITrendline lin = chart.getChartData().getSeries().get_Item(0)
.getTrendLines().add(TrendlineType.Linear);
lin.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
lin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
// Moving average (period=3) on series 1
ITrendline ma = chart.getChartData().getSeries().get_Item(1)
.getTrendLines().add(TrendlineType.MovingAverage);
ma.setPeriod((byte) 3);
ma.setTrendlineName("3-period MA");
// Polynomial (order 3) on series 2
ITrendline poly = chart.getChartData().getSeries().get_Item(2)
.getTrendLines().add(TrendlineType.Polynomial);
poly.setOrder((byte) 3);
poly.setForward(1);
pres.save("TrendLines.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Manage Custom Document Properties
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Accesses and modifies built-in and custom document metadata using `IDocumentProperties`. This includes adding, reading, and removing custom properties, as well as setting standard properties like title and company. Ensure the `Presentation` object is disposed after use.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation();
try {
IDocumentProperties props = pres.getDocumentProperties();
// Add custom properties
props.set_Item("Author", "John Doe");
props.set_Item("Version", 3);
props.set_Item("Project", "Alpha");
// Read a property by name
System.out.println("Author: " + props.get_Item("Author"));
// Remove a custom property
props.removeCustomProperty("Project");
// Built-in properties
props.setTitle("Quarterly Report");
props.setCompany("Acme Corp");
pres.save("WithProperties.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Generate Slide Thumbnail Image
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Generate a slide thumbnail using `ISlide.getImage(scaleX, scaleY)`. The image can be saved in different formats like JPEG or PNG. Ensure the presentation object is disposed.
```java
import com.aspose.slides.*;
Presentation pres = new Presentation("Presentation.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
// Full scale (1f × 1f) thumbnail
IImage img = slide.getImage(1f, 1f);
img.save("Thumbnail.jpg"); // default JPEG
// Custom dimensions (half size)
IImage imgHalf = slide.getImage(0.5f, 0.5f);
imgHalf.save("Thumbnail_half.png");
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Highlight Words in Text Frame
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Marks occurrences of a search string within a text frame using a specified highlight color. Supports whole-word matching. Ensure the `Presentation` object is disposed after use.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation("Presentation.pptx");
try {
IAutoShape shape = (AutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0);
// Highlight all occurrences of "title" in blue
shape.getTextFrame().highlightText("title", Color.BLUE);
// Highlight whole-word "to" occurrences in magenta
TextSearchOptions opts = new TextSearchOptions();
opts.setWholeWordsOnly(true);
shape.getTextFrame().highlightText("to", Color.MAGENTA, opts, null);
pres.save("Highlighted.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
--------------------------------
### Create Clustered Column Chart
Source: https://context7.com/aspose-slides/aspose.slides-for-java/llms.txt
Add a clustered column chart to a slide using `IShapeCollection.addChart()`. Configure chart title, categories, series, and data points. Ensure the presentation object is disposed.
```java
import com.aspose.slides.*;
import java.awt.Color;
Presentation pres = new Presentation();
try {
ISlide sld = pres.getSlides().get_Item(0);
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 400);
// Set title
chart.getChartTitle().addTextFrameForOverriding("Sales Report");
chart.getChartTitle().setHeight(20);
chart.setTitle(true);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Add categories
chart.getChartData().getCategories().add(wb.getCell(0, 1, 0, "Q1"));
chart.getChartData().getCategories().add(wb.getCell(0, 2, 0, "Q2"));
chart.getChartData().getCategories().add(wb.getCell(0, 3, 0, "Q3"));
// Add series and data
IChartSeries s1 = chart.getChartData().getSeries()
.add(wb.getCell(0, 0, 1, "Revenue"), chart.getType());
s1.getDataPoints().addDataPointForBarSeries(wb.getCell(0, 1, 1, 20));
s1.getDataPoints().addDataPointForBarSeries(wb.getCell(0, 2, 1, 50));
s1.getDataPoints().addDataPointForBarSeries(wb.getCell(0, 3, 1, 30));
s1.getFormat().getFill().setFillType(FillType.Solid);
s1.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE);
// Show value labels
s1.getLabels().getDefaultDataLabelFormat().setShowValue(true);
pres.save("ColumnChart.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.