Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-slides/a1b0b7f99c2b44d84c6d to your computer and use it in GitHub Desktop.
Save aspose-slides/a1b0b7f99c2b44d84c6d to your computer and use it in GitHub Desktop.
This Gist contains code snippets of examples of Aspose.Slides for Java.

This Gist contains code snippets for sample code of Aspose.Slides

// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
com.aspose.slides.Metered metered=new com.aspose.slides.Metered();
try {
// Access the setMeteredKey property and pass public and private keys as parameters
metered.setMeteredKey("<valid pablic key>", "<valid private key>");
// Get consumed qantity value before accessing API
double quantityOld = com.aspose.slides.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantityOld);
// Get consumed qantity value after accessing API
double quantity = com.aspose.slides.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantity());
} catch (Exception ex) {
Logger.getLogger(MeteredLicensing.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static String quantity() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingMediaPlayerActiveXControlInSlides.class);
// Create empty presentation instance
Presentation newPptx = new Presentation();
// Adding the Media Player ActiveX control
newPptx.getSlides().get_Item(0).getControls().addControl(ControlType.WindowsMediaPlayer, 100, 100, 400, 400);
// Access the Media Player ActiveX control and set the video path
newPptx.getSlides().get_Item(0).getControls().get_Item(0).getProperties().set_Item("URL", "Wildlife.wmv");
// Save the Presentation
newPptx.save(dataDir + "Output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(LinkingVideoWithMediaPlayerActiveXControl.class);
// Accessing the presentation with ActiveX controls
Presentation pres = new Presentation(dataDir + "template.pptx");
// Create empty presentation instance
Presentation newPptx = new Presentation();
// Remove default slide
newPptx.getSlides().removeAt(0);
// Clone slide with Media Player ActiveX Control
newPptx.getSlides().insertClone(0, pres.getSlides().get_Item(0));
// Access the Media Player ActiveX control and set the video path
newPptx.getSlides().get_Item(0).getControls().get_Item(0).getProperties().set_Item("URL", "Wildlife.wmv");
// Save the Presentation
newPptx.save(dataDir + "Output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Accessing the presentation with ActiveX controls
Presentation pres = new Presentation(dataDir + "ActiveX.pptm");
// Accessing the first slide in presentation
ISlide slide = pres.getSlides().get_Item(0);
// changing TextBox text
IControl control = slide.getControls().get_Item(0);
if (control.getName() == "TextBox1" && control.getProperties() != null) {
String newText = "Changed text";
control.getProperties().set_Item("Value", newText);
// Changing substitute image. PowerPoint will replace this image during activeX activation,
// so sometime it's OK to leave image unchanged.
BufferedImage image = new BufferedImage((int) control.getFrame().getWidth(), (int) control.getFrame().getHeight(),
BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics graphics = image.getGraphics();
graphics.setColor(SystemColor.window);
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
java.awt.Font font = new java.awt.Font(control.getProperties().get_Item("FontName"), java.awt.Font.PLAIN, 16);
graphics.setColor(SystemColor.windowText);
graphics.setFont(font);
graphics.drawString(newText, 10, 20);
graphics.setColor(SystemColor.controlShadow);
graphics.drawLine(0, image.getHeight() - 1, 0, 0);
graphics.drawLine(0, 0, image.getWidth() - 1, 0);
graphics.setColor(SystemColor.controlDkShadow);
graphics.drawLine(1, image.getHeight() - 2, 1, 1);
graphics.drawLine(1, 1, image.getWidth() - 2, 1);
graphics.setColor(SystemColor.controlHighlight);
graphics.drawLine(1, image.getHeight() - 1, image.getWidth() - 1, image.getHeight() - 1);
graphics.drawLine(image.getWidth() - 1, image.getHeight() - 1, image.getWidth() - 1, 1);
graphics.setColor(SystemColor.controlLtHighlight);
graphics.drawLine(0, image.getHeight(), image.getWidth(), image.getHeight());
graphics.drawLine(image.getWidth(), image.getHeight(), image.getWidth(), 0);
graphics.dispose();
control.getSubstitutePictureFormat().getPicture().setImage(pres.getImages().addImage(image));
}
// Changing Button caption
control = pres.getSlides().get_Item(0).getControls().get_Item(1);
if (control.getName().equalsIgnoreCase("CommandButton1") && control.getProperties() != null) {
String newCaption = "Show MessageBox";
control.getProperties().set_Item("Caption", newCaption);
// Changing substitute
BufferedImage image = new BufferedImage((int) control.getFrame().getWidth(), (int) control.getFrame().getHeight(),
BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics graphics = image.getGraphics();
graphics.setColor(SystemColor.control);
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
java.awt.Font font = new java.awt.Font(control.getProperties().get_Item("FontName"), java.awt.Font.PLAIN, 16);
graphics.setColor(SystemColor.windowText);
graphics.setFont(font);
FontMetrics metrics = graphics.getFontMetrics(font);
graphics.drawString(newCaption, (image.getWidth() - metrics.stringWidth(newCaption)) / 2, 20);
graphics.setColor(SystemColor.controlLtHighlight);
graphics.drawLine(0, image.getHeight() - 1, 0, 0);
graphics.drawLine(0, 0, image.getWidth() - 1, 0);
graphics.setColor(SystemColor.controlHighlight);
graphics.drawLine(1, image.getHeight() - 2, 1, 1);
graphics.drawLine(1, 1, image.getWidth() - 2, 1);
graphics.setColor(SystemColor.controlShadow);
graphics.drawLine(1, image.getHeight() - 1, image.getWidth() - 1, image.getHeight() - 1);
graphics.drawLine(image.getWidth() - 1, image.getHeight() - 1, image.getWidth() - 1, 1);
graphics.setColor(SystemColor.controlDkShadow);
graphics.drawLine(0, image.getHeight(), image.getWidth(), image.getHeight());
graphics.drawLine(image.getWidth(), image.getHeight(), image.getWidth(), 0);
graphics.dispose();
control.getSubstitutePictureFormat().getPicture().setImage(pres.getImages().addImage(image));
}
// moving 100 points down
for (IControl ctl : pres.getSlides().get_Item(0).getControls()) {
IShapeFrame frame = ctl.getFrame();
ctl.setFrame(new ShapeFrame(frame.getX(), frame.getY() + 100,
frame.getWidth(), frame.getHeight(), frame.getFlipH(), frame.getFlipV(), frame.getRotation()));
}
pres.save(dataDir + "withActiveX-edited_java.pptm", SaveFormat.Pptm);
// removing controls
pres.getSlides().get_Item(0).getControls().clear();
pres.save(dataDir + "withActiveX-cleared_java.pptm", SaveFormat.Pptm);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingAnIndividualSlideToHTML.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Setting HTML Options
HtmlOptions opts = new HtmlOptions();
opts.setIncludeComments(true);
opts.setHtmlFormatter(HtmlFormatter.createCustomFormatter(new CustomFormattingController()));
// Saving to individual files
for (int i = 0; i < pres.getSlides().size(); i++)
pres.save(dataDir + "slide" + (i + 1) + ".html", new int[] { i + 1 }, SaveFormat.Html, opts);
}
private static class CustomFormattingController implements IHtmlFormattingController {
private String SlideHeader = "<div class=\"slide\" name=\"slide\" id=\"slide{0}\">";
private String SlideFooter = "</div>";
public CustomFormattingController() {
}
public void writeDocumentStart(IHtmlGenerator generator, IPresentation presentation) {
}
public void writeDocumentEnd(IHtmlGenerator generator, IPresentation presentation) {
}
public void writeSlideStart(IHtmlGenerator generator, ISlide slide) {
generator.addHtml(String.format(SlideHeader, generator.getSlideIndex() + 1));
}
public void writeSlideEnd(IHtmlGenerator generator, ISlide slide) {
generator.addHtml(SlideFooter);
}
public void writeShapeStart(IHtmlGenerator generator, IShape shape) {
}
public void writeShapeEnd(IHtmlGenerator generator, IShape shape) {
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingASpecificSlideToPDF.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Setting array of slides positions
int[] slides = new int[] { 2, 3, 5 };
// Save the presentation to PDF
pres.save(dataDir + "demo.pdf", slides, SaveFormat.Pdf);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPPTToPPTX.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "Aspose.ppt");
// Saving the PPTX presentation to PPTX format
pres.save(dataDir + "ConvertedAspose.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ConvertingPresentationInNotesSlideViewToPDF.class);
//Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
//Saving the presentation to PDF notes
pres.save(dataDir + "TestNotes.pdf", SaveFormat.PdfNotes);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationInNotesSlideViewToTIFF.class);
//Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
//Saving the presentation to TIFF notes
pres.save(dataDir + "TestNotes.tiff", SaveFormat.TiffNotes);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToHTML1.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
HtmlOptions htmlOpt = new HtmlOptions();
htmlOpt.setIncludeComments(true);
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
// Saving the presentation to HTML
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ConvertingPresentationToHTMLWithComments.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
HtmlOptions htmlOpt = new HtmlOptions();
htmlOpt.setIncludeComments(true);
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
// Saving the presentation to HTML
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir_Conversion();
Presentation pres = new Presentation(dataDir+"pres.pptx");
try
{
//Exclude default presentation fonts
String[] fontNameExcludeList = { "Calibri", "Arial" };
Paragraph para = new Paragraph();
ITextFrame txt;
EmbedAllFontsHtmlController embedFontsController = new EmbedAllFontsHtmlController(fontNameExcludeList);
LinkAllFontsHtmlController linkcont = new LinkAllFontsHtmlController(fontNameExcludeList,"C:/Windows/Fonts/");
HtmlOptions htmlOptionsEmbed = new HtmlOptions();
htmlOptionsEmbed.setHtmlFormatter(HtmlFormatter.createCustomFormatter((IHtmlFormattingController) linkcont));
pres.save("pres.html", SaveFormat.Html, htmlOptionsEmbed);
}
finally {
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToHTMLWithMediaFiles.class);
final String htmlDocumentFileName = "presentationWithVideo.html";
Presentation pres = new Presentation("presentationWith.pptx");
try
{
VideoPlayerHtmlController controller = new VideoPlayerHtmlController(
"", htmlDocumentFileName, "http://www.example.com/");
HtmlOptions htmlOptions = new HtmlOptions(controller);
SVGOptions svgOptions = new SVGOptions(controller);
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller));
htmlOptions.setSlideImageFormat(SlideImageFormat.svg(svgOptions));
pres.save(htmlDocumentFileName, SaveFormat.Html, htmlOptions);
} finally
{
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation("input.pptx");
try
{
//Exclude default presentation fonts
String[] fontNameExcludeList = { "Calibri", "Arial" };
EmbedAllFontsHtmlController embedFontsController = new EmbedAllFontsHtmlController(fontNameExcludeList);
HtmlOptions htmlOptionsEmbed = new HtmlOptions();
htmlOptionsEmbed.setHtmlFormatter(HtmlFormatter.createCustomFormatter(embedFontsController));
pres.save("input-PFDinDisplayPro-Regular-installed.html", SaveFormat.Html, htmlOptionsEmbed);
} finally {
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Instantiate the PdfOptions class
PdfOptions opts = new PdfOptions();
// Setting PDF password
opts.setPassword("password");
// Save the presentation to password protected PDF
pres.save(dataDir + "demo.pdf", SaveFormat.Pdf, opts);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation(dataDir + "demo.pptx");
try {
// Instantiate the PdfOptions class
PdfOptions pdfOptions = new PdfOptions();
// Specify that the generated document should include hidden slides
pdfOptions.setShowHiddenSlides(true);
// Save the presentation to PDF with specified options
pres.save(dataDir + "Presentation.pdf", SaveFormat.Pdf, pdfOptions);
} finally {
if (pres != null)
pres.dispose();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToPDFUsingCustomOptions.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Instantiate the PdfOptions class
PdfOptions opts = new PdfOptions();
opts.setIncludeComments(true);
// Set JPEG Quality
opts.setJpegQuality((byte) 90);
// Define behavior for Metafiles
opts.setSaveMetafilesAsPng(true);
// Set Text Compression level
opts.setTextCompression(PdfTextCompression.Flate);
// Define the PDF standard
opts.setCompliance(PdfCompliance.Pdf15);
// Save the presentation to PDF with specified options
pres.save(dataDir + "demo.pdf", SaveFormat.Pdf, opts);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ConvertingPresentationToPDFUsingDefaultOptions.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Save the presentation to PDF with default options
pres.save(dataDir + "demoDefault.pdf", SaveFormat.Pdf);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation(dataDir + "presentation.pptx");
try {
ResponsiveHtmlController controller = new ResponsiveHtmlController();
HtmlOptions htmlOptions = new HtmlOptions();
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller));
pres.save(dataDir + "pres_out.html", SaveFormat.Html, htmlOptions);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToSWF.class);
Presentation pres = new Presentation(dataDir + "Sample.pptx");
try {
SwfOptions swfOptions = new SwfOptions();
swfOptions.setIncludeComments(true);
swfOptions.setViewerIncluded(false);
// Saving presentation
pres.save(dataDir + "Sample.swf", SaveFormat.Swf, swfOptions);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (pres != null)
pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation object that represents a Presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
TiffOptions options = new TiffOptions();
options.setPixelFormat(ImagePixelFormat.Format8bppIndexed);
/*
* ImagePixelFormat contains the following values (as could be seen from
* documentation):
* Format1bppIndexed; // 1 bits per pixel, indexed.
* Format4bppIndexed; // 4 bits per pixel, indexed.
* Format8bppIndexed; // 8 bits per pixel, indexed.
* Format24bppRgb; // 24 bits per pixel, RGB.
* Format32bppArgb; // 32 bits per pixel, ARGB.
*/
// Save the presentation to TIFF with specified image size
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff, options);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToTIFFWithCustomSize.class);
// Instantiate a Presentation object that represents a Presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Instantiate the TiffOptions class
TiffOptions opts = new TiffOptions();
opts.setIncludeComments(true);
// Setting compression type
// Possible values are:
// Default - Specifies the default compression scheme (LZW).
// None - Specifies no compression.
// CCITT3
// CCITT4
// LZW
// RLE
opts.setCompressionType(TiffCompressionTypes.Default);
// Depth – depends on the compression type and cannot be set manually.
// Resolution unit – is always equal to “2�? (dots per inch)
// Setting image DPI
opts.setDpiX(200);
opts.setDpiY(100);
// Set Image Size
opts.setImageSize(new java.awt.Dimension(1728, 1078));
// Save the presentation to TIFF with specified image size
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff, opts);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ConvertingPresentationToTIFFWithDefaultSize.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Saving the presentation to TIFF document
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToXPSWithoutXpsOptions.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Saving the presentation to XPS document
pres.save(dataDir + "demo.xps", SaveFormat.Xps);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingPresentationToXPSWithXpsOptions.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Instantiate the TiffOptions class
XpsOptions opts = new XpsOptions();
// Save MetaFiles as PNG
opts.setSaveMetafilesAsPng(true);
// Save the presentation to XPS document
pres.save(dataDir + "demo.xps", SaveFormat.Xps, opts);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public class CustomHeaderAndFontsController extends EmbedAllFontsHtmlController
{
private final int m_basePath=0;
// Custom header template
final static String Header = "<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\">\n" +
"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n" +
"</head>";
private final String m_cssFileName;
public CustomHeaderAndFontsController(String cssFileName)
{
m_cssFileName = cssFileName;
}
public void writeDocumentStart(IHtmlGenerator generator, IPresentation presentation) {
generator.addHtml(String.format(Header, m_cssFileName));
writeAllFonts(generator, presentation);
}
public void writeAllFonts(IHtmlGenerator generator, IPresentation presentation) {
generator.addHtml("<!-- Embedded fonts -->");
super.writeAllFonts(generator, presentation);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public class LinkAllFontsHtmlController extends EmbedAllFontsHtmlController
{
private final String m_basePath;
public LinkAllFontsHtmlController(String[] fontNameExcludeList, String basePath)
{
super(fontNameExcludeList);
m_basePath = basePath;
}
/**
*
* @param generator
* @param originalFont
* @param substitutedFont
* @param fontStyle
* @param fontWeight
* @param fontData
* @throws IOException
*/
public void writeFont
(
IHtmlGenerator generator,
IFontData originalFont,
IFontData substitutedFont,
String fontStyle,
String fontWeight,
byte[] fontData)
{
try {
String fontName = substitutedFont == null ? originalFont.getFontName() : substitutedFont.getFontName();
String path = fontName + ".woff"; // some path sanitaze may be needed
Files.write(new File(m_basePath + path).toPath(), fontData, StandardOpenOption.CREATE);
generator.addHtml("<style>");
generator.addHtml("@font-face { ");
generator.addHtml("font-family: '" + fontName + "'; ");
generator.addHtml("src: url('" + path + "')");
generator.addHtml(" }");
generator.addHtml("</style>");
} catch (IOException ex) {
Logger.getLogger(LinkAllFontsHtmlController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation("Presentation.pptx");
try {
// Saving notes pages
pres.save("Output.html", SaveFormat.HtmlNotes);
}
finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SaveToPDFNotesWithCustomSlideSize.class);
// Instantiate a Presentation object to load source file
Presentation presentation = new Presentation(dataDir + "demo.pptx");
// Instantiate Presentation object
Presentation auxPresentation = new Presentation();
// Loading slide for cloning
ISlide slide = presentation.getSlides().get_Item(0);
// Cloning slide to Presentation at position 0 or first
auxPresentation.getSlides().insertClone(0, slide);
// Set slide size type
auxPresentation.getSlideSize().setSize(SlideSizeType.Custom,SlideSizeScaleType.DoNotScale);
// setType(SlideSizeType.Custom);
// Setting custom slide size
Dimension2D dimension = presentation.getSlideSize().getSize();
dimension.setSize(612F, 792F);
auxPresentation.getSlideSize().setSize(7,10);
// Save Presentation to disk
auxPresentation.save(dataDir + "testPDFnotes.pdf", SaveFormat.PdfNotes);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation("pres.pptx");
try{
final CustomHeaderAndFontsController htmlController = new CustomHeaderAndFontsController("styles.css");
HtmlOptions options = new HtmlOptions(){{
setHtmlFormatter(HtmlFormatter.createCustomFormatter(htmlController));
}};
pres.save("pres.html", SaveFormat.Html, options);
}
finally
{
pres.dispose();
}}}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateAPresentation.class);
// Instantiate Presentation
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = (ISlide) pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Add ITextFrame to the Rectangle
ashp.addTextFrame("Hello World");
// Change the text color to Black (which is White by default)
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);
// Change the line color of the rectangle to White
ashp.getShapeStyle().getLineColor().setColor(java.awt.Color.WHITE);
// Remove any fill formatting in the shape
ashp.getFillFormat().setFillType(FillType.NoFill);
// Save the presentation to disk
pres.save(dataDir + "HelloWorld.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingDefaultZoomValueForPresentation.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Setting View Properties of Presentation
pres.getViewProperties().getSlideViewProperties().setScale(50); //zoom value in percentages for slide view
pres.getViewProperties().getNotesViewProperties().setScale(50); //zoom value in percentages for notes view
// Write the presentation as a PPTX file
pres.save(dataDir + "Zoom.pptx", SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Opening the presentation file by passing the file path to the
// constructor of Presentation class
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Get the slide number
int firstSlideNumber = pres.getFirstSlideNumber();
// Set the slide number
pres.setFirstSlideNumber(10);
// Write the presentation to disk
pres.save(dataDir + "SlideNumber.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Creating instance of load options to set the presentation access password
com.aspose.slides.LoadOptions loadOptions = new com.aspose.slides.LoadOptions();
// Setting the access password to null
loadOptions.setPassword(null);
// Setting the access to document properties
loadOptions.setOnlyLoadDocumentProperties(true);
// Opening the presentation file by passing the file path and load
// options to the constructor of Presentation class
Presentation pres = new Presentation(dataDir + "demoPassDocument.pptx", loadOptions);
// Getting Document Properties
IDocumentProperties docProps = pres.getDocumentProperties();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectionMicrosoftPowerPoint95presentations.class);
String path = null;
//Code snippet to check whether the presentation format is old Microsoft PowerPoint 95
boolean isOldFormat = PresentationFactory.getInstance().getPresentationInfo(path).getLoadFormat() == LoadFormat.Ppt95;
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Creating instance of load options to set the presentation access password
LoadOptions loadOptions = new LoadOptions();
// Setting the access password
loadOptions.setPassword("pass");
// Opening the presentation file by passing the file path and load
// options to the constructor of Presentation class
Presentation pres = new Presentation(dataDir + "demoPassDocument.pptx", loadOptions);
// Printing the total number of slides present in the presentation
System.out.println(pres.getSlides().size());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(OpeningAPresentation.class);
// Opening the presentation file by passing the file path to the constructor of Presentation class
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Printing the total number of slides present in the presentation
System.out.println(pres.getSlides().size());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
final String pathToVeryLargePresentationFile = "veryLargePresentation.pptx";
LoadOptions loadOptions = new LoadOptions();
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked);
Presentation pres = new Presentation(pathToVeryLargePresentationFile);
try{
// the huge presentation is loaded and ready to use, but the memory consumption is still low.
// make any changes to the presentation.
pres.getSlides().get_Item(0).setName("Very large presentation");
// presentation will be saved to the other file, the memory consumptions still low during saving.
pres.save("veryLargePresentation-copy.pptx", SaveFormat.Pptx);
// can't do that! IO exception will be thrown, because the file is locked while pres objects will
// not be disposed
// new File(pathToVeryLargePresentationFile).delete();
} finally
{
pres.dispose();
}
// it's ok to do it here, the source file is not locked by pres object
new File(pathToVeryLargePresentationFile).delete();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(VerifyingThePresentationFileWithoutEvenLoading.class);
// Getting the file format using the PresentationFactory class instance
int format = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Test.pdf").getLoadFormat();
System.out.println("Format: " + format);
// It will return "LoadFormat.Unknown" or 255 if the file is other than presentation formats
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingAndModifyingCustomProperties.class);
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Create a reference to DocumentProperties object associated with Presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Access and modify custom properties
for (int i = 0; i < dp.getCountOfCustomProperties(); i++) {
// Display names and values of custom properties
System.out.println("Custom Property Name : " + dp.getCustomPropertyName(i));
System.out.println("Custom Property Value : " + dp.get_Item(dp.getCustomPropertyName(i)));
// Modify values of custom properties
dp.set_Item(dp.getCustomPropertyName(i), "New Value " + (i + 1));
}
// Save your presentation to a file
pres.save(dataDir + "CustomDemoModified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingBuiltInProperties.class);
// Instantiate the Presentation class that represents the presentation
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Create a reference to IDocumentProperties object associated with Presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Display the built-in properties
System.out.println("Category : " + dp.getCategory());
System.out.println("Current Status : " + dp.getContentStatus());
System.out.println("Creation Date : " + dp.getCreatedTime());
System.out.println("Author : " + dp.getAuthor());
System.out.println("Description : " + dp.getComments());
System.out.println("KeyWords : " + dp.getKeywords());
System.out.println("Last Modified By : " + dp.getLastSavedBy());
System.out.println("Supervisor : " + dp.getManager());
System.out.println("Modified Date : " + dp.getLastSavedTime());
System.out.println("Presentation Format : " + dp.getPresentationFormat());
System.out.println("Last Print Date : " + dp.getLastPrinted());
System.out.println("Is Shared between producers : " + dp.getSharedDoc());
System.out.println("Subject : " + dp.getSubject());
System.out.println("Title : " + dp.getTitle());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingBlobToPresentation.class);
// supposed we have the very large video file we want to include into the presentation
final String pathToVeryLargeVideo = "veryLargeVideo.avi";
// create a new presentation which will contain this video
Presentation pres = new Presentation();
try{
InputStream fileStream = new FileInputStream(pathToVeryLargeVideo);
try{
// let's add the video to the presentation - we choose KeepLocked behavior, because we not
// have an intent to access the "veryLargeVideo.avi" file.
IVideo video = pres.getVideos().addVideo(fileStream, LoadingStreamBehavior.KeepLocked);
pres.getSlides().get_Item(0).getShapes().addVideoFrame(0, 0, 480, 270, video);
// save the presentation. Despite that the output presentation will be very large, the memory
// consumption will be low the whole lifetime of the pres object
pres.save("presentationWithLargeVideo.pptx", SaveFormat.Pptx);
}finally {
fileStream.close();
}
}finally {
pres.dispose();
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingCustomDocumentProperties.class);
Presentation presPPTX = new Presentation();
// Getting Document Properties
IDocumentProperties dProps = presPPTX.getDocumentProperties();
// Adding Custom properties
dProps.set_Item("New Custom", 12);
dProps.set_Item("My Name", "Mudassir");
dProps.set_Item("Custom", 124);
// Getting property name at particular index
String getPropertyName = dProps.getCustomPropertyName(2);
// Removing selected property
dProps.removeCustomProperty(getPropertyName);
// Saving presentation
presPPTX.save(dataDir + "CustomDemo.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getSharedDataDir(AdvancedDocumentProperties.class) + "Properties/";
readAndUpdateDocumentProperties(dataDir);
usePropertiesOfAPresentationAsATemplateToUpdateOtherPresentations(dataDir);
createNewTemplateAndUpdateMultiplePresentations(dataDir);
}
public static void readAndUpdateDocumentProperties(String dataDir) {
// read the info of presentation
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "presentation.pptx");
// obtain the current properties
IDocumentProperties props = info.readDocumentProperties();
// set the new values of Author and Title fields
props.setAuthor("New Author");
props.setTitle("New Title");
// update the presentation with a new values
info.updateDocumentProperties(props);
info.writeBindedPresentation(dataDir + "presentation.pptx");
}
/*
* There's an another way to use properties of a particular presentation as
* a template to update properties in other presentations:
*/
public static void usePropertiesOfAPresentationAsATemplateToUpdateOtherPresentations(String dataDir) {
DocumentProperties template;
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "template.pptx");
template = (DocumentProperties) info.readDocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate(dataDir + "doc1.pptx", template);
updateByTemplate(dataDir + "doc2.odp", template);
updateByTemplate(dataDir + "doc3.ppt", template);
}
/*
* A new template can be created from scratch and then used to update
* multiple presentations
*/
public static void createNewTemplateAndUpdateMultiplePresentations(String dataDir) {
DocumentProperties template = new DocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate(dataDir + "doc1.pptx", template);
updateByTemplate(dataDir + "doc2.odp", template);
updateByTemplate(dataDir + "doc3.ppt", template);
}
private static void updateByTemplate(String path, IDocumentProperties template) {
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path);
toUpdate.updateDocumentProperties(template);
toUpdate.writeBindedPresentation(path);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CheckPresentationModified.class);
IPresentationInfo info=PresentationFactory.getInstance().getPresentationInfo( dataDir+"props.pptx");
IDocumentProperties props = info.readDocumentProperties();
String app = props.getNameOfApplication();
String ver = props.getAppVersion();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation class that represents a PPTX file
Presentation p=new Presentation(dataDir+"ppt.pptx");
ISlide slide = p.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 100, 100);
Paragraph para1 = new Paragraph();
para1.getPortions().add(new Portion("Sample Text"));
Paragraph para2 = new Paragraph();
para2.getPortions().add(new Portion("Sample Text2"));
PortionFormat endParagraphPortionFormat = new PortionFormat();
endParagraphPortionFormat.setFontHeight(40);
endParagraphPortionFormat.setLatinFont(new FontData("Times New Roman"));
para2.setEndParagraphPortionFormat(endParagraphPortionFormat);
shape.getTextFrame().getParagraphs().add(para1);
shape.getTextFrame().getParagraphs().add(para2);
p.save(dataDir+"result.pptx",SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// supposed the presentation contains a multiple audios and videos and it size is huge.
final String hugePresentationWithAudiosAndVideosFile = "Large_Video_File_Test1.pptx";
LoadOptions loadOptions = new LoadOptions();
// lock the source file and don't load it into memory
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked);
// create the Presentation's instance, lock the "hugePresentationWithAudiosAndVideos.pptx" file.
Presentation pres = new Presentation(hugePresentationWithAudiosAndVideosFile, loadOptions);
try{
// let's save each video to a file. to prevent memory usage we need a buffer which will be used
// to exchange tha data from the presentation's video stream to a stream for newly created video file.
byte[] buffer = new byte[8 * 1024];
// iterate through the videos
for (int index = 0; index < pres.getVideos().size() ; index++)
{
IVideo video = pres.getVideos().get_Item(index);
// open the presentation video stream. Please note that we intentionally avoid accessing properties
// like video.BinaryData - this property returns a byte array containing full video, and that means
// this bytes will be loaded into memory. We will use video.GetStream, which will return Stream and
// that allows us to not load the whole video into memory.
InputStream presVideoStream = video.getStream();
try{
OutputStream outputFileStream = new FileOutputStream("video"+index+".avi");
try{
int bytesRead;
while ((bytesRead = presVideoStream.read(buffer, 0, buffer.length)) > 0)
{
outputFileStream.write(buffer, 0, bytesRead);
}
}finally {
outputFileStream.close();
}
}finally {
presVideoStream.close();
}
// memory consumption will stay low no matter what size the videos or presentation is.
}
// do the same for audios if needed.
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ModifyingBuiltInProperties.class);
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Create a reference to IDocumentProperties object associated with Presentation
IDocumentProperties dp = pres.getDocumentProperties();
// Set the built-in properties
dp.setAuthor("Aspose.Slides for Java");
dp.setTitle("Modifying Presentation Properties");
dp.setSubject("Aspose Subject");
dp.setComments("Aspose Description");
dp.setManager("Aspose Manager");
// Save your presentation to a file
pres.save(dataDir + "DocProps.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SupportForAddingEMZFilesIntoImagesCollection.class);
String imagePath="";
Presentation presentation = new Presentation();
try{
FileInputStream imageFile = new FileInputStream(imagePath);
try {
IPPImage image = presentation.getImages().addImage(imageFile);
presentation.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, (float) presentation.getSlideSize().getSize().getWidth(), (float) presentation.getSlideSize().getSize().getHeight(), image);
} finally {
imageFile.close();
}
}
finally {
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
final InterruptionTokenSource tokenSource = new InterruptionTokenSource();
Runnable interruption = new Runnable() {
public void run() {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setInterruptionToken(tokenSource.getToken());
Presentation pres = new Presentation("pres.pptx", loadOptions);
try{
pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720));
pres.save("pres.ppt", SaveFormat.Ppt);
}
finally {
pres.dispose();
}
}
};
Thread thread = new Thread(interruption);// run action in a separate thread
thread.start();
Thread.sleep(5000); // some work
tokenSource.interrupt();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatePresentationProperties.class);
// read the info of presentation
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Presentation.pptx");
// obtain the current properties
IDocumentProperties props = info.readDocumentProperties();
// set the new values of Author and Title fields
props.setAuthor("New Author");
props.setTitle("New Title");
// update the presentation with a new values
info.updateDocumentProperties(props);
info.writeBindedPresentation(dataDir + "Presentation.pptx");
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public static void main(String args[]) {
updateByTemplate();
}
private static void updateByTemplate() {
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatePresentationPropertiesUsingNewTemplate.class);
DocumentProperties template = new DocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate(dataDir + "doc1.pptx", template);
updateByTemplate(dataDir + "doc2.odp", template);
updateByTemplate(dataDir + "doc3.ppt", template);
}
private static void updateByTemplate(String path, IDocumentProperties template) {
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path);
toUpdate.updateDocumentProperties(template);
toUpdate.writeBindedPresentation(path);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public static void main(String args[]) {
updateByTemplate();
}
private static void updateByTemplate() {
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatePresPropsUsingAnotherPresentationAsTemplate.class);
DocumentProperties template;
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Presentation.pptx");
template = (DocumentProperties) info.readDocumentProperties();
template.setAuthor("Template Author");
template.setTitle("Template Title");
template.setCategory("Template Category");
template.setKeywords("Keyword1, Keyword2, Keyword3");
template.setCompany("Our Company");
template.setComments("Created from template");
template.setContentType("Template Content");
template.setSubject("Template Subject");
updateByTemplate(dataDir + "doc1.pptx", template);
updateByTemplate(dataDir + "doc2.odp", template);
updateByTemplate(dataDir + "doc3.ppt", template);
}
private static void updateByTemplate(String path, IDocumentProperties template) {
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path);
toUpdate.updateDocumentProperties(template);
toUpdate.writeBindedPresentation(path);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemovingWriteProtectionFromAPresentation.class);
// Opening the presentation file
Presentation pres = new Presentation(dataDir + "demoWriteProtected.pptx");
// Checking if presentation is write protected
if (pres.getProtectionManager().isWriteProtected())
// Removing Write protection
pres.getProtectionManager().removeWriteProtection();
// Saving presentation
pres.save(dataDir + "newDemo.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(RenderComments.class);
Presentation pres = new Presentation(dataDir+"testexample.pptx");
BufferedImage image = new BufferedImage(740, 960, BufferedImage.TYPE_INT_ARGB);
java.awt.Graphics graphics = image.createGraphics();
try
{
pres.getSlides().get_Item(0).renderToGraphics(true, (Graphics2D) graphics);
}
finally
{
if (graphics != null) graphics.dispose();
}
ImageIO.write(image, "png", new java.io.File(dataDir+"OutPresBitmap123.png"));
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SavePresentationWithPredefinedViewType.class);
// Opening the presentation file
Presentation pres = new Presentation();
// Setting view type
pres.getViewProperties().setLastView((byte) ViewType.SlideMasterView);
// Saving presentation
pres.save(dataDir + "newDemo.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();
// ....do some work here.....
// Setting access to document properties in password protected mode
pres.getProtectionManager().setEncryptDocumentProperties(false);
// Setting Password
pres.getProtectionManager().encrypt("pass");
// Save your presentation to a file
pres.save(dataDir + "demoPassDocument.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SavingAPasswordProtectedPresentation.class);
// Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();
// ....do some work here.....
// Setting Password
pres.getProtectionManager().encrypt("pass");
// Save your presentation to a file
pres.save(dataDir + "demoPass.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SavingAPresentation.class);
// Saving a Presentation to File
// Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();
// ...do some work here...
// Save your presentation to a file
pres.save(dataDir + "demoPass.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();
// ....do some work here.....
// Setting Write protection Password
pres.getProtectionManager().setWriteProtection("test");
// Save your presentation to a file
pres.save(dataDir + "demoWriteProtected.pptx", com.aspose.slides.SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheBackgroundColorOfAMasterSlide.class);
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation();
// Set the background color of the Master ISlide to Forest Green
pres.getMasters().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getMasters().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid);
pres.getMasters().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
// Write the presentation to disk
pres.save(dataDir + "MasterBG.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheBackgroundColorOfANormalSlide.class);
// Instantiate the PFresentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "MasterBG.pptx");
// Set the background color of the first ISlide to Blue
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
pres.save(dataDir + "ContentBG.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheBackgroundColorToAGradientToSlides.class);
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "MasterBG.pptx");
// Apply Gradient effect to the Background
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Gradient);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getGradientFormat().setTileFlip(TileFlip.FlipBoth);
// Write the presentation to disk
pres.save(dataDir + "ContentBG_Grad.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheImageAsBackgroundToSlides.class);
// Instantiate the Presentation class that represents the presentation file
Presentation pres = new Presentation();
// Set the background with Image
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground);
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Picture);
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat()
.setPictureFillMode(PictureFillMode.Stretch);
// Set the picture
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File("Desert.jpg")));
} catch (IOException e) {
}
// Add image to presentation's images collection
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
// Write the presentation to disk
pres.save(dataDir + "ContentBG_Img.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(AddDoughnutCallout.class);
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Doughnut, 10, 10, 500, 500, false);
IChartDataWorkbook workBook = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
chart.setLegend(false);
int seriesIndex = 0;
while (seriesIndex < 15)
{
IChartSeries series = chart.getChartData().getSeries().add(workBook.getCell(0, 0, seriesIndex + 1, "SERIES " + seriesIndex), chart.getType());
series.setExplosion(0);
series.getParentSeriesGroup().setDoughnutHoleSize((byte)20);
series.getParentSeriesGroup().setFirstSliceAngle(351);
seriesIndex++;
}
int categoryIndex = 0;
while (categoryIndex < 15)
{
chart.getChartData().getCategories().add(workBook.getCell(0, categoryIndex + 1, 0, "CATEGORY " + categoryIndex));
int i = 0;
while (i < chart.getChartData().getSeries().size())
{
IChartSeries iCS = chart.getChartData().getSeries().get_Item(i);
IChartDataPoint dataPoint = iCS.getDataPoints().addDataPointForDoughnutSeries(workBook.getCell(0, categoryIndex + 1, i + 1, 1));
dataPoint.getFormat().getFill().setFillType(FillType.Solid);
dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
dataPoint.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.awt.Color.WHITE);
dataPoint.getFormat().getLine().setWidth(1);
dataPoint.getFormat().getLine().setStyle(LineStyle.Single);
dataPoint.getFormat().getLine().setDashStyle(LineDashStyle.Solid);
if (i == chart.getChartData().getSeries().size() - 1)
{
IDataLabel lbl = dataPoint.getLabel();
lbl.getTextFormat().getTextBlockFormat().setAutofitType(TextAutofitType.Shape);
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setFontBold(NullableBool.True);
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("DINPro-Bold"));
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(12);
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.LIGHT_GRAY);
lbl.getDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.awt.Color.WHITE);
lbl.getDataLabelFormat().setShowValue(false);
lbl.getDataLabelFormat().setShowCategoryName(true);
lbl.getDataLabelFormat().setShowSeriesName(false);
//lbl.getDataLabelFormat().setShowLabelAsDataCallout(true);
lbl.getDataLabelFormat().setShowLeaderLines(true);
lbl.getDataLabelFormat().setShowLabelAsDataCallout(false);
chart.validateChartLayout();
lbl.setX((float) lbl.getX()+ (float)0.5);
lbl.setY((float)lbl.getY()+ (float)0.5);
}
i++;
}
categoryIndex++;
}
pres.save("chart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingChartSeriesOverlapForCharts.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Adding chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400, true);
IChartSeriesCollection series = chart.getChartData().getSeries();
if (series.get_Item(0).getOverlap() == 0) {
// Setting series overlap
series.get_Item(0).getParentSeriesGroup().setOverlap((byte) -30);
}
// Saving presentation
pres.save(dataDir + "ErrorBars.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Creating empty presentation//Creating empty presentation
Presentation pres = new Presentation();
// Creating a clustered column chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 400);
// Adding exponential trend line for chart series 1
ITrendline tredLinep = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Exponential);
tredLinep.setDisplayEquation(false);
tredLinep.setDisplayRSquaredValue(false);
// Adding Linear trend line for chart series 1
ITrendline tredLineLin = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Linear);
tredLineLin.setTrendlineType(TrendlineType.Linear);
tredLineLin.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
tredLineLin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
// Adding Logarithmic trend line for chart series 2
ITrendline tredLineLog = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Logarithmic);
tredLineLog.setTrendlineType(TrendlineType.Logarithmic);
tredLineLog.addTextFrameForOverriding("New log trend line");
// Adding MovingAverage trend line for chart series 2
ITrendline tredLineMovAvg = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.MovingAverage);
tredLineMovAvg.setTrendlineType(TrendlineType.MovingAverage);
tredLineMovAvg.setPeriod((byte) 3);
tredLineMovAvg.setTrendlineName("New TrendLine Name");
// Adding Polynomial trend line for chart series 3
ITrendline tredLinePol = chart.getChartData().getSeries().get_Item(2).getTrendLines().add(TrendlineType.Polynomial);
tredLinePol.setTrendlineType(TrendlineType.Polynomial);
tredLinePol.setForward(1);
tredLinePol.setOrder((byte) 3);
// Adding Power trend line for chart series 3
ITrendline tredLinePower = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Power);
tredLinePower.setTrendlineType(TrendlineType.Power);
tredLinePower.setBackward(1);
// Saving presentation
pres.save(dataDir + "ChartTrendLines.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingCustomErrorBarValueForChart.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Creating a bubble chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 400, 300, true);
// Adding custom Error bars and setting its format
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IErrorBarsFormat errBarX = series.getErrorBarsXFormat();
IErrorBarsFormat errBarY = series.getErrorBarsYFormat();
errBarX.isVisible();
errBarY.isVisible();
errBarX.setValueType((byte) ErrorBarValueType.Custom);
errBarY.setValueType((byte) ErrorBarValueType.Custom);
// Accessing chart series data point and setting error bars values for
// individual point
IChartDataPointCollection points = series.getDataPoints();
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForXPlusValues((byte) DataSourceType.DoubleLiterals);
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForXMinusValues((byte) DataSourceType.DoubleLiterals);
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForYPlusValues((byte) DataSourceType.DoubleLiterals);
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForYMinusValues((byte) DataSourceType.DoubleLiterals);
// Setting error bars for chart series points
for (int i = 0; i < points.size(); i++) {
points.get_Item(i).getErrorBarsCustomValues().getXMinus().setAsLiteralDouble(i + 1);
points.get_Item(i).getErrorBarsCustomValues().getXPlus().setAsLiteralDouble(i + 1);
points.get_Item(i).getErrorBarsCustomValues().getYMinus().setAsLiteralDouble(i + 1);
points.get_Item(i).getErrorBarsCustomValues().getYPlus().setAsLiteralDouble(i + 1);
}
// Saving presentation
pres.save(dataDir + "ErrorBarsCustomValues.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingFixedErrorBarValueForChart.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Creating a bubble chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 400, 300, true);
// Adding Error bars and setting its format
IErrorBarsFormat errBarX = chart.getChartData().getSeries().get_Item(0).getErrorBarsXFormat();
IErrorBarsFormat errBarY = chart.getChartData().getSeries().get_Item(0).getErrorBarsYFormat();
errBarX.isVisible();
errBarY.isVisible();
errBarX.setValueType((byte) ErrorBarValueType.Fixed);
errBarX.setValue(0.1f);
errBarY.setValueType((byte) ErrorBarValueType.Percentage);
errBarY.setValue(5);
errBarX.setType((byte) ErrorBarType.Plus);
errBarY.getFormat().getLine().setWidth(2.0f);
errBarX.hasEndCap();
// Saving presentation
pres.save(dataDir + "ErrorBars.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AnimatingACategory.class);
// Load a presentation
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
IChart chart = (IChart) shapes.get_Item(0);
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
pres.save(dataDir + "Sample_Animation_C.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AnimatingASeries.class);
// Instantiate Presentation class that represents a presentation file
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
IChart chart = (IChart) shapes.get_Item(0);
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious);
pres.save(dataDir + "Sample_Animating.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(AnimatingCategoriesElements.class) + "Charts/";
// Load a presentation
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
IChart chart = (IChart) shapes.get_Item(0);
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
pres.save(dataDir + "AnimatingCategoriesElements_out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AnimatingSeriesElements.class);
// Load a presentation
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
IChart chart = (IChart) shapes.get_Item(0);
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 0, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 1, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 2, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 3, EffectType.Appear, EffectSubtype.None,
EffectTriggerType.AfterPrevious);
pres.save(dataDir + "Sample_Element.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(BoxChart.class);
Presentation pres = new Presentation();
try{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.BoxAndWhisker, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
chart.getChartData().getCategories().add(wb.getCell(0, "A1", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A2", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A3", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A4", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A5", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A6", "Category 1"));
IChartSeries series = chart.getChartData().getSeries().add(ChartType.BoxAndWhisker);
series.setQuartileMethod(QuartileMethodType.Exclusive);
series.setShowMeanLine(true);
series.setShowMeanMarkers(true);
series.setShowInnerPoints(true);
series.setShowOutlierPoints(true);
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B1", 15));
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B2", 41));
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B3", 16));
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B4", 10));
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B5", 23));
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B6", 16));
pres.save("BoxAndWhisker.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangeColorOfCategories.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
IChartDataPoint point = chart.getChartData().getSeries().get_Item(0).getDataPoints().get_Item(0);
point.getFormat().getFill().setFillType(FillType.Solid);
point.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE);
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
}
finally {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangeTypeOfChartsCategoryAxis.class);
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
try {
IChart chart = (IChart) pres.getSlides().get_Item(0).getShapes().get_Item(0);
chart.getAxes().getHorizontalAxis().setCategoryAxisType(CategoryAxisType.Date);
chart.getAxes().getHorizontalAxis().setAutomaticMajorUnit(false);
chart.getAxes().getHorizontalAxis().setMajorUnit(1);
chart.getAxes().getHorizontalAxis().setMajorUnitScale(TimeUnitType.Months);
pres.save(dataDir + "Sample.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingNormalCharts.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
// Setting chart Title
// chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title";
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle();
// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();
// Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"),chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"),chart.getType());
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));
// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED);
// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));
// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.GREEN);
// create custom labels for each of categories for new series
// first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);
lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);
// Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator("/");
// Save presentation with chart
pres.save(dataDir + "AsposeChart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingScatteredChartWithMultipleSeriesAndDifferentSeriesMarkers.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide slide = pres.getSlides().get_Item(0);
// Creating the default chart
IChart chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400);
// Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete demo series
chart.getChartData().getSeries().clear();
// Add new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.getType());
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Add new point (1:3) there.
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 1), fact.getCell(defaultWorksheetIndex, 2, 2, 3));
// Add new point (2:10)
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 2), fact.getCell(defaultWorksheetIndex, 3, 2, 10));
// Edit the type of series
series.setType(ChartType.ScatterWithStraightLinesAndMarkers);
// Changing the chart series marker
series.getMarker().setSize(10);
series.getMarker().setSymbol(MarkerStyleType.Star);
// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Add new point (5:2) there.
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 5), fact.getCell(defaultWorksheetIndex, 2, 4, 2));
// Add new point (3:1)
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 3), fact.getCell(defaultWorksheetIndex, 3, 4, 1));
// Add new point (2:2)
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 4, 3, 2), fact.getCell(defaultWorksheetIndex, 4, 4, 2));
// Add new point (5:1)
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 5, 3, 5), fact.getCell(defaultWorksheetIndex, 5, 4, 1));
// Changing the chart series marker
series.getMarker().setSize(10);
series.getMarker().setSymbol(MarkerStyleType.Circle);
// Save presentation with chart
pres.save(dataDir + "AsposeScatterChart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DataSourceTypePropertyAdded.class);
final Presentation pres = new Presentation("pres.pptx");
try
{
ISlide slide = pres.getSlides().get_Item(1);
IChart chart = (IChart)slide.getShapes().get_Item(0);
/*ChartDataSourceType*/ int sourceType = chart.getChartData().getDataSourceType();
if (sourceType == ChartDataSourceType.ExternalWorkbook)
{
String path = chart.getChartData().getExternalWorkbookPath();
}
}
finally { ((IDisposable)pres).dispose(); }
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DisplayChartLabelsAsCallouts.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400);
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowLabelAsDataCallout(true);
chart.getChartData().getSeries().get_Item(0).getLabels().get_Item(2).getDataLabelFormat().setShowLabelAsDataCallout(false);
pres.save(dataDir + "DisplayCharts.pptx", SaveFormat.Pptx);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(DisplayingPercentageAsLabels.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Access first slide
ISlide slide = pres.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 20, 20, 400, 400);
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
IChartCategory cat;
double total_value = 0.0f;
double[] total_for_Cat = new double[chart.getChartData().getCategories().size()];
for (int k = 0; k < chart.getChartData().getCategories().size(); k++) {
cat = chart.getChartData().getCategories().get_Item(k);
for (int i = 0; i < chart.getChartData().getSeries().size(); i++) {
total_for_Cat[k] = total_for_Cat[k] + (double) (chart.getChartData().getSeries().get_Item(i).getDataPoints().get_Item(k).getValue().getData());
}
}
double dataPontPercent = 0f;
for (int x = 0; x < chart.getChartData().getSeries().size(); x++) {
series = chart.getChartData().getSeries().get_Item(x);
series.getLabels().getDefaultDataLabelFormat().setShowLegendKey(false);
for (int j = 0; j < series.getDataPoints().size(); j++) {
IDataLabel lbl = series.getDataPoints().get_Item(j).getLabel();
dataPontPercent = (double) ((series.getDataPoints().get_Item(j).getValue().getData())) / (double) (total_for_Cat[j]) * 100;
IPortion port = new Portion();
port.setText(String.format("{0:F2} %.2f", dataPontPercent));
port.getPortionFormat().setFontHeight(8f);
lbl.getTextFrameForOverriding().setText("");
IParagraph para = lbl.getTextFrameForOverriding().getParagraphs().get_Item(0);
para.getPortions().add(port);
lbl.getDataLabelFormat().setShowSeriesName(false);
lbl.getDataLabelFormat().setShowPercentage(false);
lbl.getDataLabelFormat().setShowLegendKey(false);
lbl.getDataLabelFormat().setShowCategoryName(false);
lbl.getDataLabelFormat().setShowBubbleSize(false);
}
}
// Save presentation with chart
pres.save(dataDir + "test.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(FontPropertiesForInvidualLegend.class);
Presentation pres = new Presentation(dataDir+"test.pptx");
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
IChartTextFormat tf = chart.getLegend().getEntries().get_Item(1).getTextFormat();
tf.getPortionFormat().setFontBold(NullableBool.True);
tf.getPortionFormat().setFontHeight(20);
tf.getPortionFormat().setFontItalic(NullableBool.True);
tf.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
tf.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
pres.save(dataDir+"output.pptx", SaveFormat.Pptx);
}
finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(FontSizeLegend.class);
Presentation pres = new Presentation();
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(20);
chart.getAxes().getVerticalAxis().setAutomaticMinValue(false);
chart.getAxes().getVerticalAxis().setMinValue(-5);
chart.getAxes().getVerticalAxis().setAutomaticMaxValue(false);
chart.getAxes().getVerticalAxis().setMaxValue(10);
pres.save("output.pptx", SaveFormat.Pptx);
}
finally
{
pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FormattingChartEntities.class);
// Instantiating presentation
Presentation pres = new Presentation();
// Accessing the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Adding the sample chart
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 50, 50, 500, 400);
// Setting Chart Title
chart.hasTitle();
chart.getChartTitle().addTextFrameForOverriding("");
IPortion chartTitle = chart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
chartTitle.setText("Sample Chart");
chartTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
chartTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
chartTitle.getPortionFormat().setFontHeight(20);
chartTitle.getPortionFormat().setFontBold(NullableBool.True);
chartTitle.getPortionFormat().setFontItalic(NullableBool.True);
// Setting Major grid lines format for value axis
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setWidth(5);
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setDashStyle(LineDashStyle.DashDot);
// Setting Minor grid lines format for value axis
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().setWidth(3);
// Setting value axis number format
chart.getAxes().getVerticalAxis().isNumberFormatLinkedToSource();
chart.getAxes().getVerticalAxis().setDisplayUnit(DisplayUnitType.Thousands);
chart.getAxes().getVerticalAxis().setNumberFormat("0.0%");
// Setting chart maximum, minimum values
chart.getAxes().getVerticalAxis().isAutomaticMajorUnit();
chart.getAxes().getVerticalAxis().isAutomaticMaxValue();
chart.getAxes().getVerticalAxis().isAutomaticMinorUnit();
chart.getAxes().getVerticalAxis().isAutomaticMinValue();
chart.getAxes().getVerticalAxis().setMaxValue(15f);
chart.getAxes().getVerticalAxis().setMinValue(-2f);
chart.getAxes().getVerticalAxis().setMinorUnit(0.5f);
chart.getAxes().getVerticalAxis().setMajorUnit(2.0f);
// Setting Value Axis Text Properties
IChartPortionFormat txtVal = chart.getAxes().getVerticalAxis().getTextFormat().getPortionFormat();
txtVal.setFontBold(NullableBool.True);
txtVal.setFontHeight(16);
txtVal.setFontItalic(NullableBool.True);
txtVal.getFillFormat().setFillType(FillType.Solid);
txtVal.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkGreen));
txtVal.setLatinFont(new FontData("Times New Roman"));
// Setting value axis title
chart.getAxes().getVerticalAxis().hasTitle();
chart.getAxes().getVerticalAxis().getTitle().addTextFrameForOverriding("");
IPortion valtitle = chart.getAxes().getVerticalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
valtitle.setText("Primary Axis");
valtitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
valtitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
valtitle.getPortionFormat().setFontHeight(20);
valtitle.getPortionFormat().setFontBold(NullableBool.True);
valtitle.getPortionFormat().setFontItalic(NullableBool.True);
// Setting Major grid lines format for Category axis
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().setWidth(5);
// Setting Minor grid lines format for Category axis
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.YELLOW);
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().setWidth(3);
// Setting Category Axis Text Properties
IChartPortionFormat txtCat = chart.getAxes().getHorizontalAxis().getTextFormat().getPortionFormat();
txtCat.setFontBold(NullableBool.True);
txtCat.setFontHeight(16);
txtCat.setFontItalic(NullableBool.True);
txtCat.getFillFormat().setFillType(FillType.Solid);
txtCat.getFillFormat().getSolidFillColor().setColor(Color.BLUE);
txtCat.setLatinFont(new FontData("Arial"));
// Setting Category Title
chart.getAxes().getHorizontalAxis().hasTitle();
chart.getAxes().getHorizontalAxis().getTitle().addTextFrameForOverriding("");
IPortion catTitle = chart.getAxes().getHorizontalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0);
catTitle.setText("Sample Category");
catTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
catTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
catTitle.getPortionFormat().setFontHeight(20);
catTitle.getPortionFormat().setFontBold(NullableBool.True);
catTitle.getPortionFormat().setFontItalic(NullableBool.True);
// Setting category axis label position
chart.getAxes().getHorizontalAxis().setTickLabelPosition(TickLabelPositionType.Low);
// Setting category axis label rotation angle
chart.getAxes().getHorizontalAxis().setTickLabelRotationAngle(45);
// Setting Legends Text Properties
IChartPortionFormat txtleg = chart.getLegend().getTextFormat().getPortionFormat();
txtleg.setFontBold(NullableBool.True);
txtleg.setFontHeight(16);
txtleg.setFontItalic(NullableBool.True);
txtleg.getFillFormat().setFillType(FillType.Solid);
txtleg.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkRed));
// Set show chart legends without overlapping chart
chart.getLegend().setOverlay(true);
// chart.ChartData.Series[0].PlotOnSecondAxis=true;
chart.getChartData().getSeries().get_Item(0).setPlotOnSecondAxis(true);
// Setting secondary value axis
chart.getAxes().getSecondaryVerticalAxis().isVisible();
chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setStyle(LineStyle.ThickBetweenThin);
chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setWidth(20);
// Setting secondary value axis Number format
chart.getAxes().getSecondaryVerticalAxis().isNumberFormatLinkedToSource();
chart.getAxes().getSecondaryVerticalAxis().setDisplayUnit(DisplayUnitType.Hundreds);
chart.getAxes().getSecondaryVerticalAxis().setNumberFormat("0.0%");
// Setting chart maximum, minimum values
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMajorUnit();
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMaxValue();
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinorUnit();
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinValue();
chart.getAxes().getSecondaryVerticalAxis().setMaxValue(20f);
chart.getAxes().getSecondaryVerticalAxis().setMinValue(-5f);
chart.getAxes().getSecondaryVerticalAxis().setMinorUnit(0.5f);
chart.getAxes().getSecondaryVerticalAxis().setMajorUnit(2.0f);
// Setting chart back wall color
chart.getBackWall().setThickness(1);
chart.getBackWall().getFormat().getFill().setFillType(FillType.Solid);
chart.getBackWall().getFormat().getFill().getSolidFillColor().setColor(Color.ORANGE);
chart.getFloor().getFormat().getFill().setFillType(FillType.Solid);
chart.getFloor().getFormat().getFill().getSolidFillColor().setColor(Color.RED);
// Setting Plot area color
chart.getPlotArea().getFormat().getFill().setFillType(FillType.Solid);
chart.getPlotArea().getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.LightCyan));
// Save Presentation
pres.save(dataDir + "FormattedChart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FunnelChart.class);
Presentation pres = new Presentation();
try{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Funnel, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
chart.getChartData().getCategories().add(wb.getCell(0, "A1", "Category 1"));
chart.getChartData().getCategories().add(wb.getCell(0, "A2", "Category 2"));
chart.getChartData().getCategories().add(wb.getCell(0, "A3", "Category 3"));
chart.getChartData().getCategories().add(wb.getCell(0, "A4", "Category 4"));
chart.getChartData().getCategories().add(wb.getCell(0, "A5", "Category 5"));
chart.getChartData().getCategories().add(wb.getCell(0, "A6", "Category 6"));
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Funnel);
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B1", 50));
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B2", 100));
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B3", 200));
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B4", 300));
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B5", 400));
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B6", 500));
pres.save("Funnel.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(GetChartImage.class);
Presentation pres = new Presentation();
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
BufferedImage img = chart.getThumbnail();
ImageIO.write(img, "png",new File(dataDir+"result.png"));
}
finally {
pres.dispose();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetPositionOfChartDataLabel.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400);
for (IChartSeries series : chart.getChartData().getSeries())
{
series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.OutsideEnd);
series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
}
chart.validateChartLayout();
for (IChartSeries series : chart.getChartData().getSeries())
{
for (IChartDataPoint point : series.getDataPoints())
{
if (point.getValue().toDouble() > 4)
{
float x = point.getLabel().getActualX();
float y = point.getLabel().getActualY();
float w = point.getLabel().getActualWidth();
float h = point.getLabel().getActualHeight();
IAutoShape shape = chart.getUserShapes().getShapes().addAutoShape(ShapeType.Ellipse, x, y, w, h);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setColor(new java.awt.Color(0, 255, 0, 100));
}
}
}
pres.save("chartDataLabel.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetValuesAndUnitScaleFromAxis.class);
final Presentation pres = new Presentation();
try
{
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Area, 100, 100, 500, 350);
chart.validateChartLayout();
double maxValue = chart.getAxes().getVerticalAxis().getActualMaxValue();
double minValue = chart.getAxes().getVerticalAxis().getActualMinValue();
double majorUnit = chart.getAxes().getHorizontalAxis().getActualMajorUnit();
double minorUnit = chart.getAxes().getHorizontalAxis().getActualMinorUnit();
}
finally { ((IDisposable)pres).dispose(); }
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetWidthHeightFromChartPlotArea.class);
final Presentation pres = new Presentation();
try {
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350);
chart.validateChartLayout();
double x = chart.getPlotArea().getActualX();
double y = chart.getPlotArea().getActualY();
double w = chart.getPlotArea().getActualWidth();
double h = chart.getPlotArea().getActualHeight();
}
finally { ((IDisposable)pres).dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Histogram, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Histogram);
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A1", 15));
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A2", -41));
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A3", 16));
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A4", 10));
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A5", -23));
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A6", 16));
chart.getAxes().getHorizontalAxis().setAggregationType(AxisAggregationType.Automatic);
pres.save("Histogram.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(IActualLayoutAdded.class);
final Presentation pres = new Presentation();
try {
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350);
chart.validateChartLayout();
double x = chart.getPlotArea().getActualX();
double y = chart.getPlotArea().getActualY();
double w = chart.getPlotArea().getActualWidth();
double h = chart.getPlotArea().getActualHeight();
}
finally { ((IDisposable)pres).dispose(); }
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(InvertIfNegativeForIndividualSeries.class);
Presentation pres = new Presentation(dataDir+"test.pptx");
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400, true);
IChartSeriesCollection series = chart.getChartData().getSeries();
chart.getChartData().getSeries().clear();
series.add(chart.getChartData().getChartDataWorkbook().getCell(0, "B1"), chart.getType());
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B2",-5));
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B3",3));
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B4",-2));
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B5",1));
series.get_Item(0).setInvertIfNegative(false);
series.get_Item(0).getInvertIfNegative();
series.get_Item(0).getDataPoints().get_Item(2).setInvertIfNegative(true);
pres.save("output.pptx", SaveFormat.Pptx);
} finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(MultiCategoryChart.class);
Presentation pres = new Presentation(dataDir+"test.pptx");
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart ch = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
ch.getChartData().getSeries().clear();
ch.getChartData().getCategories().clear();
IChartDataWorkbook fact=ch.getChartData().getChartDataWorkbook();
fact.clear(0);
int defaultWorksheetIndex = 0;
IChartCategory category = ch.getChartData().getCategories().add(fact.getCell(0, "c2", "A"));
category.getGroupingLevels().setGroupingItem(1, "Group1");
category = ch.getChartData().getCategories().add(fact.getCell(0, "c3", "B"));
category = ch.getChartData().getCategories().add(fact.getCell(0, "c4", "C"));
category.getGroupingLevels().setGroupingItem(1, "Group2");
category = ch.getChartData().getCategories().add(fact.getCell(0, "c5", "D"));
category = ch.getChartData().getCategories().add(fact.getCell(0, "c6", "E"));
category.getGroupingLevels().setGroupingItem(1, "Group3");
category = ch.getChartData().getCategories().add(fact.getCell(0, "c7", "F"));
category = ch.getChartData().getCategories().add(fact.getCell(0, "c8", "G"));
category.getGroupingLevels().setGroupingItem(1, "Group4");
category = ch.getChartData().getCategories().add(fact.getCell(0, "c8", "H"));
IChartSeries series = ch.getChartData().getSeries().add(fact.getCell(0, "D1", "Series 1"),
ChartType.ClusteredColumn);
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D2", 10));
// AddDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, "D2", 10));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D3", 20));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D4", 30));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D5", 40));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D6", 50));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D7", 60));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D8", 70));
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D9", 80));
pres.save(dataDir+"AsposeChart.pptx", SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(OrganizationChart.class);
Presentation pres = new Presentation();
{
ISmartArt smartArt = pres.getSlides().get_Item(0).getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.PictureOrganizationChart);
pres.save("OrganizationChart.pptx", SaveFormat.Pptx);
}
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Second plot options for Pie of Pie and Bar of Pie chart
// Instantiate Presentation object
Presentation pres = new Presentation();
// Add Pie chart on first slide
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.PieOfPie, 50, 50, 500, 400);
// Getting chart data
IChartData chartData = chart.getChartData();
// Accessing first chart series
IChartSeries series = chartData.getSeries().get_Item(0);
// Setting series properties
series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
series.getParentSeriesGroup().setSecondPieSize(149);
series.getParentSeriesGroup().setPieSplitBy(PieSplitType.ByPercentage);
series.getParentSeriesGroup().setPieSplitPosition((double) 53);
// Saving presentation to disk
pres.save(dataDir + "pieOFpie.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SetChartDataFromWorkBook.class);
Presentation pres = new Presentation();
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400);
byte[] msln =chart.getChartData().readWorkbookStream();
chart.getChartData().getChartDataWorkbook().clear(0);
com.aspose.cells.Workbook workbook=null;
try {
workbook = new com.aspose.cells.Workbook(dataDir+"a1.xlsx");
} catch (Exception ex) {
Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex);
}
java.io.ByteArrayOutputStream mem = new java.io.ByteArrayOutputStream();
try {
workbook.save(mem,com.aspose.cells.SaveFormat.XLSX);
} catch (Exception ex) {
java.util.logging.Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex);
}
chart.getChartData().getChartDataWorkbook();
chart.getChartData().writeWorkbookStream(mem.toByteArray());
chart.getChartData().setRange("Sheet1!$A$1:$B$9");
IChartSeries series=chart.getChartData().getSeries().get_Item(0);
series.getParentSeriesGroup().setColorVaried(true);
pres.save(dataDir+"response2.pptx",SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SetDataRangeForChart.class) + "Charts/";
// Instantiate Presentation class that represents PPTX file
Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx");
// Access first slideMarker
ISlide sld = presentation.getSlides().get_Item(0);
// Add chart with default data
IChart chart = (IChart)sld.getShapes().get_Item(0);
chart.getChartData().setRange("Sheet1!A1:B4");
presentation.save(dataDir + "SetDataRangeForChart_Out.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Color inverColor = Color.red;
Color seriesColor;
final Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 400, 300);
IChartDataWorkbook workBook = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new series
chart.getChartData().getSeries().add(workBook.getCell(0, 0, 1, "Series 1"), chart.getType());
// Adding new categories
chart.getChartData().getCategories().add(workBook.getCell(0, 1, 0, "Category 1"));
chart.getChartData().getCategories().add(workBook.getCell(0, 2, 0, "Category 2"));
chart.getChartData().getCategories().add(workBook.getCell(0, 3, 0, "Category 3"));
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 1, 1, -20));
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 3, 1, -30));
seriesColor = series.getAutomaticSeriesColor();
series.setInvertIfNegative(true);
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(seriesColor);
series.getInvertedSolidFillColor().setColor(inverColor);
pres.save(dataDir + "SetInvertFillColorForChartSeries_Out.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingAutomaticSeriesFillColor.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Creating a clustered column chart
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 50, 600, 400);
// Setting series fill format to automatic
for (int i = 0; i < chart.getChartData().getSeries().size(); i++) {
chart.getChartData().getSeries().get_Item(i).getAutomaticSeriesColor();
}
// Saving presentation
pres.save(dataDir + "AutoFillSeries.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SettingAutomicPieChartSliceColors.class) + "Charts/";
// Instantiate Presentation class that represents PPTX file
Presentation presentation = new Presentation();
// Access first slide
ISlide slides = presentation.getSlides().get_Item(0);
// Add chart with default data
IChart chart = slides.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400);
// Setting chart Title
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText (NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle();
// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));
// Adding new series
IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
// Now populating series data
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));
series.getParentSeriesGroup().setColorVaried(true);
presentation.save(dataDir + "PieChartSlice_Out.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingCustomLocationAndSizeForChartLegend.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Get reference of the slide
ISlide slide = pres.getSlides().get_Item(0);
// Add a clustered column chart on the slide
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 500);
// Set Legend Properties
chart.getLegend().setX(50 / chart.getWidth());
chart.getLegend().setY(50 / chart.getHeight());
chart.getLegend().setWidth(100 / chart.getWidth());
chart.getLegend().setHeight(100 / chart.getHeight());
// Write presentation to disk
pres.save(dataDir + "Legend.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SettingDateFormatForCategoryAxis.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Area, 50, 50, 450, 300);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().add(wb.getCell(0, "A2", convertToOADate(new Date(2015, 1, 1))));
chart.getChartData().getCategories().add(wb.getCell(0, "A3", convertToOADate(new Date(2016, 1, 1))));
chart.getChartData().getCategories().add(wb.getCell(0, "A4", convertToOADate(new Date(2017, 1, 1))));
chart.getChartData().getCategories().add(wb.getCell(0, "A5", convertToOADate(new Date(2018, 1, 1))));
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Line);
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B2", 1));
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B3", 2));
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B4", 3));
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B5", 4));
chart.getAxes().getHorizontalAxis().setCategoryAxisType(CategoryAxisType.Date);
chart.getAxes().getHorizontalAxis().setNumberFormatLinkedToSource(false);
chart.getAxes().getHorizontalAxis().setNumberFormat("yyyy");
pres.save(dataDir, SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
}
public static String convertToOADate(Date date) throws ParseException {
double oaDate;
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
java.util.Date baseDate = myFormat.parse("30 12 1899");
Long days = TimeUnit.DAYS.convert(date.getTime()- baseDate.getTime(), TimeUnit.MILLISECONDS);
oaDate = (double) days + ((double) date.getHours() / 24) + ((double) date.getMinutes() / (60 * 24))+ ((double) date.getSeconds() / (60 * 24 * 60));
return String.valueOf(oaDate);
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SettingFontPropertiesForTable.class);
Presentation pres = new Presentation();
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
chart.setDataTable(true);
chart.getChartDataTable().getTextFormat().getPortionFormat().setFontBold(NullableBool.True);
chart.getChartDataTable().getTextFormat().getPortionFormat().setFontHeight(20);
pres.save("output.pptx", SaveFormat.Pptx);
}
finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingNumberFormatForChartDataCell.class);
// Instantiate the presentation
Presentation pres = new Presentation();
// Access the first presentation slide
ISlide slide = pres.getSlides().get_Item(0);
// Adding a default clustered column chart
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400);
// Accessing the chart series collection
IChartSeriesCollection series = chart.getChartData().getSeries();
// Setting the preset number format
// Traverse through every chart series
for (IChartSeries ser : series) {
// Traverse through every data cell in series
for (IChartDataPoint cell : ser.getDataPoints()) {
// Setting the number format
cell.getValue().getAsCell().setPresetNumberFormat((byte) 10); // 0.00%
}
}
// Saving presentation
pres.save(dataDir + "PresetNumberFormat.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingPieChartSectorColors.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400);
// Setting chart Title
chart.getChartTitle().addTextFrameForOverriding("Sample Title");
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight(20);
chart.hasTitle();
// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr"));
// Adding new series
IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
// Now populating series data
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));
// Not working in new version
// Adding new points and setting sector color
// series.IsColorVaried = true;
chart.getChartData().getSeriesGroups().get_Item(0).isColorVaried();
IChartDataPoint point = series.getDataPoints().get_Item(0);
point.getFormat().getFill().setFillType(FillType.Solid);
point.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN);
// Setting Sector border
point.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
point.getFormat().getLine().setWidth(3.0);
point.getFormat().getLine().setStyle(LineStyle.ThinThick);
point.getFormat().getLine().setDashStyle(LineDashStyle.DashDot);
IChartDataPoint point1 = series.getDataPoints().get_Item(1);
point1.getFormat().getFill().setFillType(FillType.Solid);
point1.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Brown));
// Setting Sector border
point1.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
point1.getFormat().getLine().setWidth(3.0);
point1.getFormat().getLine().setStyle(LineStyle.Single);
point1.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot);
IChartDataPoint point2 = series.getDataPoints().get_Item(2);
point2.getFormat().getFill().setFillType(FillType.Solid);
point2.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Coral));
// Setting Sector border
point2.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED);
point2.getFormat().getLine().setWidth(2.0);
point2.getFormat().getLine().setStyle(LineStyle.ThinThin);
point2.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot);
// Create custom labels for each of categories for new series
IDataLabel lbl1 = series.getDataPoints().get_Item(0).getLabel();
// lbl.ShowCategoryName = true;
lbl1.getDataLabelFormat().setShowValue(true);
IDataLabel lbl2 = series.getDataPoints().get_Item(1).getLabel();
lbl2.getDataLabelFormat().setShowValue(true);
lbl2.getDataLabelFormat().setShowLegendKey(true);
lbl2.getDataLabelFormat().setShowPercentage(true);
IDataLabel lbl3 = series.getDataPoints().get_Item(2).getLabel();
lbl3.getDataLabelFormat().setShowSeriesName(true);
lbl3.getDataLabelFormat().setShowPercentage(true);
// Showing Leader Lines for Chart
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true);
// Setting Rotation Angle for Pie Chart Sectors
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180);
// Save presentation with chart
pres.save(dataDir + "AsposePieChart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SettingPositionAxis.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300);
chart.getAxes().getHorizontalAxis().setAxisBetweenCategories(true);
pres.save(dataDir+"test.pptx",SaveFormat.Pptx);
}
finally
{
if (pres != null) pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Creating empty presentation
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.StackedColumn3D, 0, 0, 500, 500);
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new series
chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Series 2"), chart.getType());
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "Caetegoty 3"));
// Set Rotation3D properties
chart.getRotation3D().setRightAngleAxes(true);
chart.getRotation3D().setRotationX((byte) 40);
chart.getRotation3D().setRotationY((byte) 270);
chart.getRotation3D().setDepthPercents(150);
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 1, 30));
// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 2, 60));
// Save presentation with chart
pres.save(dataDir + "3Drotation.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SettingRotationAngle.class);
Presentation pres = new Presentation(dataDir+"Test.pptx");
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300);
chart.getAxes().getVerticalAxis().setTitle(true);
chart.getAxes().getVerticalAxis().getTitle().getTextFormat().getTextBlockFormat().setRotationAngle(90);
} finally
{
if (pres != null) pres.dispose();
}
pres.save(dataDir+"test.pptx",SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheAutomaticSeriesColorForChartSeries.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
// Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();
// Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType());
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));
// Setting automatic fill color for series
series.getFormat().getFill().setFillType(FillType.NotDefined);
// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));
// Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.GRAY);
// Save presentation with chart
pres.save(dataDir + "AutomaticColor.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheChartMarkerOptionsOnDataPointsLevel.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Access first slide
ISlide slide = pres.getSlides().get_Item(0);
// Creating the default chart
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 0, 0, 400, 400);
// Getting the default chart data WorkSheet index
int defaultWorksheetIndex = 0;
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete demo series
chart.getChartData().getSeries().clear();
// Add new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType());
IPPImage imgx1 = null;
try {
imgx1 = pres.getImages().addImage(new FileInputStream(new File("Desert.jpg")));
} catch (IOException e) {
}
// Set the picture
IPPImage imgx2 = null;
try {
imgx2 = pres.getImages().addImage(new FileInputStream(new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg")));
} catch (IOException e) {
}
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Add new point (1:3) there.
IChartDataPoint point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 1, 1, (double) 4.5));
point.getMarker().getFormat().getFill().setFillType(FillType.Picture);
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx1);
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 2, 1, (double) 2.5));
point.getMarker().getFormat().getFill().setFillType(FillType.Picture);
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx2);
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 3, 1, (double) 3.5));
point.getMarker().getFormat().getFill().setFillType(FillType.Picture);
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx1);
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 4, 1, (double) 4.5));
point.getMarker().getFormat().getFill().setFillType(FillType.Picture);
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx2);
// Changing the chart series marker
series.getMarker().setSize(15);
// Save presentation with chart
pres.save(dataDir + "AsposeScatterChart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheGapWidthPropertyOfChartSeries.class);
// Creating empty presentation
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.StackedColumn3D, 0, 0, 500, 500);
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new series
chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Series 2"), chart.getType());
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "Caetegoty 1"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "Caetegoty 2"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "Caetegoty 3"));
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 1, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 1, 30));
// Take second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 2, 60));
// Set GapWidth value
series.getParentSeriesGroup().setGapWidth(75);
// Save presentation with chart
pres.save(dataDir + "3Drotation.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheLabelDistanceFromCategoryAxis.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Get reference of the slide
ISlide sld = pres.getSlides().get_Item(0);
// Adding a chart on slide
IChart ch = sld.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300);
// Setting the position of label from axis
ch.getAxes().getHorizontalAxis().setLabelOffset(500);
// Write the presentation to disk
pres.save(dataDir + "Position.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ShowingDisplayUnitLabel.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300);
chart.getAxes().getVerticalAxis().setDisplayUnit(DisplayUnitType.Millions);
} finally {
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SpecifyingDoughnutChartHoleSize.class);
Presentation pres = new Presentation();
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Doughnut, 50, 50, 400, 400);
chart.getChartData().getSeriesGroups().get_Item(0).setDoughnutHoleSize((byte) 90);
pres.save(dataDir + "ChartSeries.API.DoughnutHoleSize.pptx", SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation();
try{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Sunburst, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
//branch 1
IChartCategory leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C1", "Leaf1"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem1");
leaf.getGroupingLevels().setGroupingItem(2, "Branch1");
chart.getChartData().getCategories().add(wb.getCell(0, "C2", "Leaf2"));
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C3", "Leaf3"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem2");
chart.getChartData().getCategories().add(wb.getCell(0, "C4", "Leaf4"));
//branch 2
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C5", "Leaf5"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem3");
leaf.getGroupingLevels().setGroupingItem(2, "Branch2");
chart.getChartData().getCategories().add(wb.getCell(0, "C6", "Leaf6"));
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C7", "Leaf7"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem4");
chart.getChartData().getCategories().add(wb.getCell(0, "C8", "Leaf8"));
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Sunburst);
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D1", 4));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D2", 5));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D3", 3));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D4", 6));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D5", 9));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D6", 9));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D7", 4));
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D8", 3));
pres.save("Sunburst.pptx", SaveFormat.Pptx);
}finally{
pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SupportForBubbleChartScaling.class);
Presentation pres = new Presentation(dataDir+"Test.pptx");
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 100, 100, 400, 300);
chart.getChartData().getSeriesGroups().get_Item(0).setBubbleSizeScale(150);
pres.save(dataDir+"Result.pptx", SaveFormat.Pptx);
}
finally {
if (pres != null) pres.dispose();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SupportForChangingSeriesColor.class);
Presentation pres = new Presentation(dataDir+"Test.pptx");
try
{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 600, 400);
IChartDataPoint point = chart.getChartData().getSeries().get_Item(0).getDataPoints().get_Item(1);
point.setExplosion(30);
point.getFormat().getFill().setFillType(FillType.Solid);
point.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE);
pres.save("output.pptx", SaveFormat.Pptx);
}
finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SupportForChartAreaRoundedBorders.class);
Presentation presentation = new Presentation(dataDir+"Test.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 100, 600, 400);
chart.setRoundedCorners(true);
presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(SupportForPrecisionOfData.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Line, 50, 50, 450, 300);
chart.setDataTable(true);
chart.getChartData().getSeries().get_Item(0).setNumberFormatOfValues("#,##0.00");
pres.save(dataDir+"test.pptx",SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation(dataDir+"Test.pptx");
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.OpenHighLowClose, 50, 50, 600, 400, false);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
chart.getChartData().getCategories().add(wb.getCell(0, 1, 0, "A"));
chart.getChartData().getCategories().add(wb.getCell(0, 2, 0, "B"));
chart.getChartData().getCategories().add(wb.getCell(0, 3, 0, "C"));
chart.getChartData().getSeries().add(wb.getCell(0, 0, 1, "Open"), chart.getType());
chart.getChartData().getSeries().add(wb.getCell(0, 0, 2, "High"), chart.getType());
chart.getChartData().getSeries().add(wb.getCell(0, 0, 3, "Low"), chart.getType());
chart.getChartData().getSeries().add(wb.getCell(0, 0, 4, "Close"), chart.getType());
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 1, 72));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 1, 25));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 1, 38));
series = chart.getChartData().getSeries().get_Item(1);
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 2, 172));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 2, 57));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 2, 57));
series = chart.getChartData().getSeries().get_Item(2);
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 3, 12));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 3, 12));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 3, 13));
series = chart.getChartData().getSeries().get_Item(3);
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 4, 25));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 4, 38));
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 4, 50));
chart.getChartData().getSeriesGroups().get_Item(0).getUpDownBars().setUpDownBars(true);
chart.getChartData().getSeriesGroups().get_Item(0).getHiLowLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid);
for(IChartSeries ser : chart.getChartData().getSeries())
{
ser.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
}
pres.save("output.pptx", SaveFormat.Pptx);
} finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SwitchChartRowColumns.class);
Presentation pres = new Presentation();
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 400, 300);
chart.getChartData().switchRowColumn();
pres.save(dataDir +"SwitchChartRowColumns_out.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(TreeMapChart.class);
Presentation pres = new Presentation();
try{
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Treemap, 50, 50, 500, 400);
chart.getChartData().getCategories().clear();
chart.getChartData().getSeries().clear();
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
//branch 1
IChartCategory leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C1", "Leaf1"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem1");
leaf.getGroupingLevels().setGroupingItem(2, "Branch1");
chart.getChartData().getCategories().add(wb.getCell(0, "C2", "Leaf2"));
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C3", "Leaf3"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem2");
chart.getChartData().getCategories().add(wb.getCell(0, "C4", "Leaf4"));
//branch 2
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C5", "Leaf5"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem3");
leaf.getGroupingLevels().setGroupingItem(2, "Branch2");
chart.getChartData().getCategories().add(wb.getCell(0, "C6", "Leaf6"));
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C7", "Leaf7"));
leaf.getGroupingLevels().setGroupingItem(1, "Stem4");
chart.getChartData().getCategories().add(wb.getCell(0, "C8", "Leaf8"));
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Treemap);
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D1", 4));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D2", 5));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D3", 3));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D4", 6));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D5", 9));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D6", 9));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D7", 4));
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D8", 3));
series.setParentLabelLayout(ParentLabelLayoutType.Overlapping);
pres.save("Treemap.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(UpdatingExistingChart.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx");
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add chart with default data
IChart chart = (IChart) sld.getShapes().get_Item(0);
// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
// Getting the chart data WorkSheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Changing chart Category Name
fact.getCell(defaultWorksheetIndex, 1, 0, "Modified Category 1");
fact.getCell(defaultWorksheetIndex, 2, 0, "Modified Category 2");
// Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
// Now updating series data
fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1");
// modifying series name
series.getDataPoints().get_Item(0).getValue().setData(90);
series.getDataPoints().get_Item(1).getValue().setData(123);
series.getDataPoints().get_Item(2).getValue().setData(44);
// Take Second chart series
series = chart.getChartData().getSeries().get_Item(1);
// Now updating series data
fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2");
// modifying series name
series.getDataPoints().get_Item(0).getValue().setData(23);
series.getDataPoints().get_Item(1).getValue().setData(67);
series.getDataPoints().get_Item(2).getValue().setData(99);
// Now, Adding a new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"),chart.getType());
// Take 3rd chart series
series = chart.getChartData().getSeries().get_Item(2);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 3, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 30));
chart.setType(ChartType.ClusteredCylinder);
// Save presentation with chart
pres.save(dataDir + "AsposeChartModified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(UsingWorkBookChartCellAsDatalabel.class);
String lbl0 = "Label 0 cell value";
String lbl1 = "Label 1 cell value";
String lbl2 = "Label 2 cell value";
Presentation pres = new Presentation(dataDir+"Test.pptx");
try {
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 600, 400, true);
IChartSeriesCollection series = chart.getChartData().getSeries();
series.get_Item(0).getLabels().getDefaultDataLabelFormat().setShowLabelValueFromCell(true);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
series.get_Item(0).getLabels().get_Item(0).setValueFromCell(wb.getCell(0, "A10", lbl0));
series.get_Item(0).getLabels().get_Item(1).setValueFromCell(wb.getCell(0, "A11", lbl1));
series.get_Item(0).getLabels().get_Item(2).setValueFromCell(wb.getCell(0, "A12", lbl2));
} finally {
pres.dispose();
}
// Saving presentation
pres.save(dataDir + "TestResult.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ValidateChartLayoutAdded.class);
final Presentation pres = new Presentation();
try {
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350);
chart.validateChartLayout();
double x = chart.getPlotArea().getActualX();
double y = chart.getPlotArea().getActualY();
double w = chart.getPlotArea().getActualWidth();
double h = chart.getPlotArea().getActualHeight();
}
finally { ((IDisposable)pres).dispose(); }
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingSlideByID.class);
// Instantiate a Presentation object that represents a presentation file
Presentation presentation = new Presentation(dataDir + "demo.pptx");
// Getting Slide ID
int id = (int) presentation.getSlides().get_Item(0).getSlideId();
// Accessing Slide by ID
IBaseSlide slide = presentation.getSlideById(id);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingSlideByIndex.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Accessing a slide using its slide index
ISlide slide = pres.getSlides().get_Item(0);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingSlidesToPresentation.class);
// Instantiate Presentation class that represents the presentation file
Presentation pres = new Presentation();
// Instantiate SlideCollection calss
ISlideCollection slds = pres.getSlides();
for (int i = 0; i < pres.getLayoutSlides().size(); i++) {
// Add an empty slide to the Slides collection
slds.addEmptySlide(pres.getLayoutSlides().get_Item(i));
}
// Do some work on the newly added slide
// Save the PPTX file to the Disk
pres.save(dataDir + "EmptySlide.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddNotesSlideWithNotesStyle.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
IMasterNotesSlide notesMaster = pres.getMasterNotesSlideManager().getMasterNotesSlide();
if (notesMaster != null)
{
// Get MasterNotesSlide text style
ITextStyle notesStyle = notesMaster.getNotesStyle();
//Set symbol bullet for the first level paragraphs
IParagraphFormat paragraphFormat = notesStyle.getLevel(0);
paragraphFormat.getBullet().setType(BulletType.Symbol);
}
pres.save(dataDir + "NotesSlideWithNotesStyle.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangingThePositionOfASlide.class);
// Instantiate Presentation class to load the source presentation file
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Get the slide whose position is to be changed
ISlide sld = pres.getSlides().get_Item(0);
// Set the new position for the slide
sld.setSlideNumber(2);
// Write the presentation to disk
pres.save(dataDir + "helloworld_Pos.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class to load the source presentation file
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx");
// Instantiate Presentation class for destination presentation (where slide is to be cloned)
Presentation destPres = new Presentation();
// Instantiate ISlide from the collection of slides in source presentation along with master slide
ISlide sourceSlide = srcPres.getSlides().get_Item(0);
// Clone the desired master slide from the source presentation to the collection of masters in the destination presentation
IMasterSlideCollection masters = destPres.getMasters();
IMasterSlide SourceMaster = sourceSlide.getLayoutSlide().getMasterSlide();
IMasterSlide iSlide = masters.addClone(SourceMaster);
ISlideCollection slds = destPres.getSlides();
slds.addClone(sourceSlide, iSlide, true);
// Save the destination presentation to disk
destPres.save(dataDir + "helloworld_dest3.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloningASlideFromOnePositionToAnotherWithinSamePresentation.class);
// Instantiate Presentation class that represents a presentation file
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Clone the desired slide to the end of the collection of slides in the
// same presentation
ISlideCollection slds = pres.getSlides();
// Clone the desired slide to the specified index in the same presentation
slds.insertClone(2, pres.getSlides().get_Item(1));
// Write the modified presentation to disk
pres.save(dataDir + "helloworld_clonedPost.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloningASlideFromOnePositionToTheEndWithinSamePresentation.class);
// Instantiate Presentation class that represents a presentation file
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
// Clone the desired slide to the end of the collection of slides in the same presentation
ISlideCollection slds = pres.getSlides();
slds.addClone(pres.getSlides().get_Item(0));
// Write the modified presentation to disk
pres.save(dataDir + "helloworld_cloned.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloningASlideFromOnePresentationToAnotherAtASpecifiedPosition.class);
// Instantiate Presentation class to load the source presentation file
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx");
// Instantiate Presentation class for destination presentation (where slide is to be cloned)
Presentation destPres = new Presentation(dataDir + "demo.pptx");
ISlideCollection slds = destPres.getSlides();
// Clone the desired slide from the source presentation to the specified position in destination presentation
slds.insertClone(0, srcPres.getSlides().get_Item(1));
// Write the destination presentation to disk
destPres.save(dataDir + "demo.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloningASlideFromOnePresentationToAnotherAtTheEnd.class);
// Instantiate Presentation class to load the source presentation file
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx");
// Instantiate Presentation class for destination PPTX (where slide is to be cloned)
Presentation destPres = new Presentation();
// Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation
ISlideCollection slds = destPres.getSlides();
slds.addClone(srcPres.getSlides().get_Item(0));
// Write the destination presentation to disk
destPres.save(dataDir + "helloworld_dest2.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(InsertSvgIntoSlide.class);
int svgPath=0;
Presentation p = new Presentation();
{
String svgContent = ReadAllTextFromFile(dataDir);
IPPImage emfImage = p.getImages().addFromSvg(svgContent);
p.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, emfImage.getWidth(), emfImage.getHeight(), emfImage);
p.save(dataDir+"", SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ISectionCollection.class);
Presentation pres=new Presentation(dataDir+"Presentation1.pptx");
ISection section = (ISection) pres.getSections().get_Item(2);
//pres.getSections().reorderSectionWithSlides((section, 0);
pres.getSections().removeSectionWithSlides(pres.getSections().get_Item(0));
pres.getSections().appendEmptySection("Last empty section");
pres.getSections().addSection("First empty", pres.getSlides().get_Item(0));
pres.save(dataDir+"Result.pptx",SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemoveASlideUsingSlideIndex.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Removing a slide using its slide index
pres.getSlides().removeAt(0);
// Writing the presentation file
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemoveASlideUsingSlideReference.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
// Accessing a slide using its index in the slides collection
ISlide slide = pres.getSlides().get_Item(0);
// Removing a slide using its reference
pres.getSlides().remove(slide);
// Writing the presentation file
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public static void main(String[] args) {
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingHeaderAndFooters.class);
// Load Presentation
Presentation pres = new Presentation(dataDir + "headerTest.pptx");
// Setting Footer
pres.getHeaderFooterManager().setAllFootersText("My Footer text");
pres.getHeaderFooterManager().setAllFootersVisibility(true);
// Access and Update Header
IMasterNotesSlide masterNotesSlide = pres.getMasterNotesSlideManager().getMasterNotesSlide();
if (null != masterNotesSlide) {
updateHeaderFooterText(masterNotesSlide);
}
// Save presentation
pres.save(dataDir + "HeaderFooterJava.pptx", SaveFormat.Pptx);
}
// Method to set Header/Footer Text
public static void updateHeaderFooterText(IBaseSlide master) {
for (IShape shape : master.getShapes()) {
if (shape.getPlaceholder() != null) {
if (shape.getPlaceholder().getType() == PlaceholderType.Header) {
((IAutoShape) shape).getTextFrame().setText("HI there new header");
}
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingLayoutSlidesToPresentation.class);
String presName = "demo.pptx";
// Instantiate Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + presName);
// Try to search by layout slide type
IMasterLayoutSlideCollection layoutSlides = pres.getMasters().get_Item(0).getLayoutSlides();
ILayoutSlide layoutSlide = null;
if (layoutSlides.getByType(SlideLayoutType.TitleAndObject) != null)
layoutSlide = layoutSlides.getByType(SlideLayoutType.TitleAndObject);
else
layoutSlide = layoutSlides.getByType(SlideLayoutType.Title);
if (layoutSlide == null) {
// The situation when a presentation doesn't contain some type of layouts.
// Technographics.pptx presentation only contains Blank and Custom layout types.
// But layout slides with Custom types has different slide names, like "Title", "Title and Content", etc.
// And it is possible to use these names for layout slide selection.
// Also it is possible to use the set of placeholder shape types. For example,
// Title slide should have only Title placeholder type, etc.
for (ILayoutSlide titleAndObjectLayoutSlide : layoutSlides) {
if (titleAndObjectLayoutSlide.getName() == "Title and Object") {
layoutSlide = titleAndObjectLayoutSlide;
break;
}
}
if (layoutSlide == null) {
for (ILayoutSlide titleLayoutSlide : layoutSlides) {
if (titleLayoutSlide.getName() == "Title") {
layoutSlide = titleLayoutSlide;
break;
}
}
if (layoutSlide == null) {
layoutSlide = layoutSlides.getByType(SlideLayoutType.Blank);
if (layoutSlide == null) {
layoutSlide = layoutSlides.add(SlideLayoutType.TitleAndObject, "Title and Object");
}
}
}
}
// Adding empty slide with added layout slide
pres.getSlides().insertEmptySlide(0, layoutSlide);
// Save presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CheckSlidesComparison.class);
Presentation presentation1 = null;
Presentation presentation2 = null;
try {
presentation1 = new Presentation("SomePresentation1.pptx");
presentation2 = new Presentation("SomePresentation2.pptx");
for (int i = 0; i < presentation1.getMasters().size(); i++)
{
for (int j = 0; j < presentation2.getMasters().size(); j++)
{
if (presentation1.getMasters().get_Item(i).equals(presentation2.getMasters().get_Item(j)))
System.out.println("SomePresentation1 MasterSlide#" + i +" is equal to SomePresentation2 MasterSlide#" + j);
}
}
} finally {
if (presentation1 != null) {
presentation1.dispose();
presentation1 = null;
}
if (presentation2 != null) {
presentation2.dispose();
presentation2 = null;
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HeaderFooterManager.class);
Presentation presentation = new Presentation(dataDir+"presentation.ppt");
try{
IBaseSlideHeaderFooterManager headerFooterManager = presentation.getSlides().get_Item(0).getHeaderFooterManager();
if (!headerFooterManager.isFooterVisible()) // Method isFooterVisible is used for indicating that a slide footer placeholder is not present.
{
headerFooterManager.setFooterVisibility(true); // Method setFooterVisibility is used for making a slide footer placeholder visible.
}
if (!headerFooterManager.isSlideNumberVisible()) // Method isSlideNumberVisible is used for indicating that a slide page number placeholder is not present.
{
headerFooterManager.setSlideNumberVisibility(true); // Method setSlideNumberVisibility is used for making a slide page number placeholder visible.
}
if (!headerFooterManager.isDateTimeVisible()) // Method isDateTimeVisible is used for indicating that a slide date-time placeholder is not present.
{
headerFooterManager.setDateTimeVisibility(true); // Method setFooterVisibility is used for making a slide date-time placeholder visible.
}
headerFooterManager.setFooterText("Footer text"); // Method setFooterText is used for setting text to slide footer placeholder.
headerFooterManager.setDateTimeText("Date and time text"); // Method setDateTimeText is used for setting text to slide date-time placeholder.
}
finally
{
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SetChildFooterVisible.class);
Presentation presentation = new Presentation("presentation.ppt");
try{
IMasterSlideHeaderFooterManager headerFooterManager = presentation.getMasters().get_Item(0).getHeaderFooterManager();
headerFooterManager.setFooterAndChildFootersVisibility(true); // Method setFooterAndChildFootersVisibility is used for making a master slide and all child footer placeholders visible.
headerFooterManager.setSlideNumberAndChildSlideNumbersVisibility(true); // Method setSlideNumberAndChildSlideNumbersVisibility is used for making a master slide and all child page number placeholders visible.
headerFooterManager.setDateTimeAndChildDateTimesVisibility(true); // Method setDateTimeAndChildDateTimesVisibility is used for making a master slide and all child date-time placeholders visible.
headerFooterManager.setFooterAndChildFootersText("Footer text"); // Method setFooterAndChildFootersText is used for setting text to master slide and all child footer placeholders.
headerFooterManager.setDateTimeAndChildDateTimesText("Date and time text"); // Method setDateTimeAndChildDateTimesText is used for setting text to master slide and all child date-time placeholders.
}
finally
{
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingThePageSizeWhenGeneratingPDF.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation();
// Set SlideSize.Type Property
pres.getSlideSize().setSize(SlideSizeType.A4Paper,SlideSizeScaleType.DoNotScale);
// Set different properties of PDF Options
PdfOptions opts = new PdfOptions();
opts.setSufficientResolution(600);
// Save presentation to disk
pres.save(dataDir + "Export.pdf", SaveFormat.Pdf, opts);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation objects that represent presentation files
Presentation presentation = new Presentation(dataDir + "demo.pptx");
Presentation auxPresentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
// Set the slide size of generated presentations to that of source
auxPresentation.getSlideSize().setSize(540, 720, SlideSizeScaleType.EnsureFit);
//getType());
auxPresentation.getSlideSize().setSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize);
// Clone required slide
auxPresentation.getSlides().addClone(presentation.getSlides().get_Item(0));
auxPresentation.getSlides().removeAt(0);
// Save Presentation to disk
auxPresentation.save(dataDir + "size.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation objects that represent presentation files
Presentation presentation = new Presentation(dataDir + "demo.pptx");
Presentation auxPresentation = new Presentation(dataDir+"demo.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
Presentation pres = new Presentation("presentation.ppt");
try {
pres.getSlideSize().setSize(540, 720, SlideSizeScaleType.EnsureFit); // Method SetSize is used for set slide size with scale content to ensure fit
pres.getSlideSize().setSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize); // Method SetSize is used for set slide size with maximize size of content
}
finally {
pres.dispose();
}
// Save Presentation to disk
auxPresentation.save(dataDir + "size.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExportingMediaFilesIntoHtmlFile.class);
// Loading a presentation
Presentation pres = new Presentation(dataDir + "LineExample.pptx");
try {
final String path = "path";
final String fileName = "video.html";
final String baseUri = "http://www.example.com/";
VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path, fileName, baseUri);
// Setting HTML options
HtmlOptions htmlOptions = new HtmlOptions(controller);
SVGOptions svgOptions = new SVGOptions(controller);
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller));
htmlOptions.setSlideImageFormat(SlideImageFormat.svg(svgOptions));
// Saving the file
pres.save(dataDir + fileName, SaveFormat.Html, htmlOptions);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtractFlashObjects.class);
Presentation pres = new Presentation(dataDir+"withFlash.pptm");
IControlCollection controls = pres.getSlides().get_Item(0).getControls();
Control flashControl = null;
for (IControl control : controls){
if (control.getName() == "ShockwaveFlash1")
{
flashControl = (Control)control;
}
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtractingAudioUsedInSlideShowTransitions.class);
String presName = "AudioSlide.pptx";
// Instantiate Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + presName);
// Access the desired slide
ISlide slide = pres.getSlides().get_Item(0);
// Get the slideshow transition effects for slide
ISlideShowTransition transition = slide.getSlideShowTransition();
//Extract sound in byte array
byte[] audio = transition.getSound().getBinaryData();
System.out.println("Length: " + audio.length);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExtractingVideoFromASlide.class);
Presentation template = new Presentation(dataDir + "VideoSample.pptx");
for (ISlide slide : template.getSlides()) {
for (IShape shape : template.getSlides().get_Item(0).getShapes()) {
if (shape instanceof VideoFrame) {
IVideoFrame vf = (IVideoFrame) shape;
String type = vf.getEmbeddedVideo().getContentType();
int ss = type.lastIndexOf('-');
byte[] buffer = vf.getEmbeddedVideo().getBinaryData();
//Get File Extension
int charIndex = type.indexOf("/");
type = type.substring(charIndex + 1);
FileOutputStream fop = new FileOutputStream(dataDir + "testing2." + type);
fop.write(buffer);
fop.flush();
fop.close();
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation presentation = new Presentation("presentation.pptx");
{
// Change Header and Footer settings for notes master and all notes slides
IMasterNotesSlide masterNotesSlide = presentation.getMasterNotesSlideManager().getMasterNotesSlide();
if (masterNotesSlide != null)
{
IMasterNotesSlideHeaderFooterManager headerFooterManager = masterNotesSlide.getHeaderFooterManager();
headerFooterManager.setHeaderAndChildHeadersVisibility(true); // make the master notes slide and all child Footer placeholders visible
headerFooterManager.setFooterAndChildFootersVisibility(true); // make the master notes slide and all child Header placeholders visible
headerFooterManager.setSlideNumberAndChildSlideNumbersVisibility(true); // make the master notes slide and all child SlideNumber placeholders visible
headerFooterManager.setDateTimeAndChildDateTimesVisibility(true); // make the master notes slide and all child Date and time placeholders visible
headerFooterManager.setHeaderAndChildHeadersText("Header text"); // set text to master notes slide and all child Header placeholders
headerFooterManager.setFooterAndChildFootersText("Footer text"); // set text to master notes slide and all child Footer placeholders
headerFooterManager.setDateTimeAndChildDateTimesText("Date and time text"); // set text to master notes slide and all child Date and time placeholders
}
// Change Header and Footer settings for first notes slide only
INotesSlide notesSlide = presentation.getSlides().get_Item(0).getNotesSlideManager().getNotesSlide();
if (notesSlide != null)
{
INotesSlideHeaderFooterManager headerFooterManager = notesSlide.getHeaderFooterManager();
if (!headerFooterManager.isHeaderVisible())
headerFooterManager.setHeaderVisibility(true); // make this notes slide Header placeholder visible
if (!headerFooterManager.isFooterVisible())
headerFooterManager.setFooterVisibility(true); // make this notes slide Footer placeholder visible
if (!headerFooterManager.isSlideNumberVisible())
headerFooterManager.setSlideNumberVisibility(true); // make this notes slide SlideNumber placeholder visible
if (!headerFooterManager.isDateTimeVisible())
headerFooterManager.setDateTimeVisibility(true); // make this notes slide Date-time placeholder visible
headerFooterManager.setHeaderText("New header text"); // set text to notes slide Header placeholder
headerFooterManager.setFooterText("New footer text"); // set text to notes slide Footer placeholder
headerFooterManager.setDateTimeText("New date and time text"); // set text to notes slide Date-time placeholder
}
presentation.save("result.ppt",SaveFormat.Ppt);
}
presentation.dispose();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemovingNotesOfAllSlides.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "presWithNotes.pptx");
// Removing notes of all slides
INotesSlideManager mgr = null;
for (int i = 0; i < pres.getSlides().size(); i++) {
mgr = pres.getSlides().get_Item(i).getNotesSlideManager();
mgr.removeNotesSlide();
}
// Saving presentation to disk
pres.save(dataDir + "test.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemovingNotesOfASpecificSlide.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "presWithNotes.pptx");
// Removing notes of first slide
INotesSlideManager mgr = pres.getSlides().get_Item(0).getNotesSlideManager();
mgr.removeNotesSlide();
// Saving presentation to disk
pres.save(dataDir + "test.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
private int m_shapeIndex;
public CustomSvgShapeFormattingController() {
m_shapeIndex = 0;
}
public CustomSvgShapeFormattingController(int shapeStartIndex)
{
m_shapeIndex = shapeStartIndex;
}
public void formatShape(ISvgShape svgShape, IShape shape)
{
svgShape.setId("shape-" + m_shapeIndex++);
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingSVGImageFromSlide.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "ThumbnailFromSlide.pptx");
// Getting last slide index
int lastSlidePosition = pres.getSlides().size();
ISlide slide = null;
// Iterating through every presentation slide and generating SVG image
for (int i = 0; i < lastSlidePosition; i++) {
// Accessing Slides
slide = pres.getSlides().get_Item(i);
// Getting and saving the slide SVG image
try {
slide.writeAsSvg(new FileOutputStream(dataDir + "SvgImage" + i + ".svg"));
} catch (IOException e) {
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(GeneratingSVGImageWithCustomIDS.class);
Presentation pres = new Presentation(dataDir+"pptxFileName.pptx");
try
{
FileOutputStream stream = null;
try
{
stream = new FileOutputStream(new java.io.File(dataDir));
SVGOptions svgOptions = new SVGOptions();
svgOptions.setShapeFormattingController(new CustomSvgShapeFormattingController());
pres.getSlides().get_Item(0).writeAsSvg(stream, svgOptions);
}
finally {
if (stream != null) stream.close();
}
}
finally
{
if (pres != null) pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlide.class);
// Instantiate a Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "Sample.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Create a full scale image
BufferedImage image = sld.getThumbnail(1f, 1f);
// Save the image to disk in JPEG format
try {
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (IOException e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlideInNotesSlidesView.class);
// Instantiate a Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "ThumbnailFromSlideInNotes.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// User defined dimension
int desiredX = 1200;
int desiredY = 800;
// Getting scaled value of X and Y
float ScaleX = (float) (1.0 / pres.getSlideSize().getSize().getWidth()) * desiredX;
float ScaleY = (float) (1.0 / pres.getSlideSize().getSize().getHeight()) * desiredY;
// Create a full scale image
BufferedImage image = sld.getNotesSlideManager().getNotesSlide().getThumbnail(ScaleY, ScaleY);
// getThumbnail(ScaleX, ScaleY);
// Save the image to disk in JPEG format
try {
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (IOException e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlideWithUserDefinedDimensions.class);
// Instantiate a Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "ThumbnailWithUserDefinedDimensions.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// User defined dimension
int desiredX = 1200;
int desiredY = 800;
// Getting scaled value of X and Y
float ScaleX = (float) (1.0 / pres.getSlideSize().getSize().getWidth()) * desiredX;
float ScaleY = (float) (1.0 / pres.getSlideSize().getSize().getHeight()) * desiredY;
// Create a full scale image
BufferedImage image = sld.getThumbnail(ScaleX, ScaleY);
// Save the image to disk in JPEG format
try {
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (IOException e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingThumbnailOfUserDefinedWindowFromSlide.class);
// Instantiate a Presentation class that represents the presentation file
Presentation pres = new Presentation(dataDir + "ThumbnailWithUserDefinedDimensions.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Create a full scale image
BufferedImage image = sld.getThumbnail(1f, 1f);
// Getting the image of desired window inside generated slide Thumbnail
// BufferedImage window = image.getSubimage(windowX, windowY, windowsWidth, windowHeight);
BufferedImage windowImage = image.getSubimage(100, 100, 200, 200);
// Save the image to disk in JPEG format
try {
ImageIO.write(windowImage, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (IOException e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(RenderEmoji.class);
Presentation pres = new Presentation();
pres.save("Emoji.pptx", SaveFormat.Pdf);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingAnOLEObjectFrameFromASlide.class);
// Load the PPTX to PresentationEx object
Presentation pres = new Presentation(dataDir + "AccessingOLEObjectFrame.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Cast the shape to OleObjectFrameEx
IOleObjectFrame oof = (IOleObjectFrame) sld.getShapes().get_Item(0);
// Read the OLE Object and write it to disk
if (oof != null) {
FileOutputStream fstr;
fstr = new FileOutputStream(dataDir + "book1.xlsx");
byte[] buf = oof.getObjectData();
fstr.write(buf, 0, buf.length);
fstr.flush();
fstr.close();
System.out.println("Excel OLE Object written as excel1.xls file");
}
// Write the PPTX to disk
pres.save(dataDir + "OleEmbed.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(Add3DRotationEffectOnShape.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);
// Add a shape on slide
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Ellipse, 30, 30, 100, 100);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setColor(Color.GREEN);
ILineFillFormat format = shape.getLineFormat().getFillFormat();
format.setFillType(FillType.Solid);
format.getSolidFillColor().setColor(Color.ORANGE);
shape.getLineFormat().setWidth(2.0);
// Set ThreeDFormat properties of shape
shape.getThreeDFormat().setDepth(4);
shape.getThreeDFormat().getBevelTop().setBevelType(BevelPresetType.Circle);
shape.getThreeDFormat().getBevelTop().setHeight(6);
shape.getThreeDFormat().getBevelTop().setWidth(6);
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.ThreePt);
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
// Write the presentation as a PPTX file
pres.save(dataDir + "Bavel.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(Adding3DBavelEffectsToShape.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);
// Add a shape on slide
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Ellipse, 30, 30, 100, 100);
shape.getFillFormat().setFillType(FillType.Solid);
shape.getFillFormat().getSolidFillColor().setColor(Color.GREEN);
ILineFillFormat format = shape.getLineFormat().getFillFormat();
format.setFillType(FillType.Solid);
format.getSolidFillColor().setColor(Color.ORANGE);
shape.getLineFormat().setWidth(2.0);
// Set ThreeDFormat properties of shape
shape.getThreeDFormat().setDepth(4);
shape.getThreeDFormat().getBevelTop().setBevelType(BevelPresetType.Circle);
shape.getThreeDFormat().getBevelTop().setHeight(6);
shape.getThreeDFormat().getBevelTop().setWidth(6);
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.ThreePt);
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
// Write the presentation as a PPTX file
pres.save(dataDir + "Bavel.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingAnEmbeddedVideoFrameToSlide.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
try {
// Embed video inside presentation
IVideo vid = pres.getVideos().addVideo(new FileInputStream(new File(dataDir + "Wildlife.mp4")));
// Add Video Frame
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 350, vid);
// Set video to Video Frame
vf.setEmbeddedVideo(vid);
// Set Play Mode and Volume of the Video
vf.setPlayMode(VideoPlayModePreset.Auto);
vf.setVolume(AudioVolumeMode.Loud);
// Write the PPTX file to disk
pres.save(dataDir + "VideoFrame.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingAnOLEObjectFrameToASlide.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Load an Excel file to Array of Bytes
File file = new File(dataDir + "book1.xlsx");
int length = (int) file.length();
FileInputStream fstro = new FileInputStream(file);
byte[] buf = new byte[length];
fstro.read(buf, 0, length);
// Add an Ole Object Frame shape
IOleObjectFrame oof = sld.getShapes().addOleObjectFrame((float) 0, (float) 0,
(float) pres.getSlideSize().getSize().getWidth(),
(float) pres.getSlideSize().getSize().getHeight(),
"Excel.Sheet.8", buf);
// Write the PPTX to disk
pres.save(dataDir + "OleEmbed.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingArrowShapedLineToSlide.class);
// Instantiate PresentationEx class that represents the PPTX file
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add an AutoShape of type line
IAutoShape shp = sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0);
// Apply some formatting on the line
shp.getLineFormat().setStyle(LineStyle.ThickBetweenThin);
shp.getLineFormat().setWidth(10);
shp.getLineFormat().setDashStyle(LineDashStyle.DashDot);
shp.getLineFormat().setBeginArrowheadLength(LineArrowheadLength.Short);
shp.getLineFormat().setBeginArrowheadStyle(LineArrowheadStyle.Oval);
shp.getLineFormat().setEndArrowheadLength(LineArrowheadLength.Long);
shp.getLineFormat().setEndArrowheadStyle(LineArrowheadStyle.Triangle);
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Maroon));
// Write the PPTX to Disk
pres.save(dataDir + "LineShape2.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingAudioFrameToSlide.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Load the wav sound file to stream
try {
FileInputStream fstr = new FileInputStream(new File(dataDir + "audio.wav"));
// Add Audio Frame
IAudioFrame af = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr);
// Set Play Mode and Volume of the Audio
af.setPlayMode(AudioPlayModePreset.Auto);
af.setVolume(AudioVolumeMode.Loud);
} catch (Exception e) {
}
// Write the PPTX file to disk
pres.save(dataDir + "AudioFrameEmbed.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of ellipse type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 150, 50);
// Apply some formatting to ellipse shape
shp.getFillFormat().setFillType(FillType.Solid);
shp.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Chocolate));
// Apply some formatting to the line of Ellipse
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
shp.getLineFormat().setWidth(5);
// Write the PPTX file to disk
pres.save(dataDir + "EllipseShp1.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of ellipse type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50);
// Apply some formatting to ellipse shape
shp.getFillFormat().setFillType(FillType.Solid);
shp.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Chocolate));
// Apply some formatting to the line of Ellipse
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
shp.getLineFormat().setWidth(5);
// Write the PPTX file to disk
pres.save(dataDir + "RecShp2.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingGroupShapesToSlide.class);
// Instantiate Presentation class
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Accessing the shape collection of slides
IShapeCollection slideShapes = sld.getShapes();
// Adding a group shape to the slide
IGroupShape groupShape = slideShapes.addGroupShape();
// Adding shapes inside Added group shape
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 300, 100, 100, 100);
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 500, 100, 100, 100);
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 300, 300, 100, 100);
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 500, 300, 100, 100);
// Adding group shape frame
groupShape.setFrame(new ShapeFrame(100, 300, 500, 40, NullableBool.False, NullableBool.False, 0));
// Write the PPTX file to disk
pres.save(dataDir + "GroupShape.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingPictureFrameWithRelativeScale.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Instantiate the Image class
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg")));
} catch (IOException e) {
}
// Add Picture Frame with height and width equivalent of Picture
IPictureFrame pf = sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx);
// Setting relative scale width and height
pf.setRelativeScaleHeight(0.8f);
pf.setRelativeScaleWidth(1.35f);
// Write the PPTX file to disk
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingPlainLineToSlide.class);
// Instantiate PresentationEx class that represents the PPTX file
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add an AutoShape of type line
sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0);
// Write the PPTX to Disk
pres.save(dataDir + "LineShape1.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingSimpleEllipseInTheSlide.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of ellipse type
sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 150, 50);
// Write the PPTX file to disk
pres.save(dataDir + "EllipseShp1.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingSimplePictureFramesToSlides.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Instantiate the Image class
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg")));
} catch (IOException e) {
}
// Add Picture Frame with height and width equivalent of Picture
sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx);
// Write the PPTX file to disk
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingSimpleRectangleInTheSlide.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of ellipse type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50);
// Write the PPTX file to disk
pres.save(dataDir + "RecShp1.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingVideoFramesToSlides.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add Video Frame
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, dataDir + "Wildlife.mp4");
// Set Play Mode and Volume of the Video
vf.setPlayMode(VideoPlayModePreset.Auto);
vf.setVolume(AudioVolumeMode.Loud);
// Write the PPTX file to disk
pres.save(dataDir + "VideoFrame.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingVideoFrameWithVideoFromWebSource.class);
Presentation pres = new Presentation();
addVideoFromYouTube(pres, "Tj75Arhq5ho");
pres.save(dataDir + "out.pptx", SaveFormat.Pptx);
}
private static void addVideoFromYouTube(Presentation pres, String videoID) {
// add videoFrame
IVideoFrame videoFrame = pres.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 427, 240, "https://www.youtube.com/embed/" + videoID);
videoFrame.setPlayMode(VideoPlayModePreset.Auto);
// load thumbnail
String thumbnailUri = "http://img.youtube.com/vi/" + videoID + "/hqdefault.jpg";
URL url;
try {
url = new URL(thumbnailUri);
videoFrame.getPictureFormat().getPicture().setImage(pres.getImages().addImage(url.openStream()));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddStretchOffsetForImageFill.class);
Presentation presentation = new Presentation();
try {
// Get the first slide of presentation
ISlide slide = presentation.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
// Create image
BufferedImage img = ImageIO.read(new File("image.png"));
IPPImage imgEx = presentation.getImages().addImage(img);
// Set shape's fill type
aShape.getFillFormat().setFillType(FillType.Picture);
// Set shape's picture fill mode
aShape.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
// Set image to fill the shape
aShape.getFillFormat().getPictureFillFormat().getPicture().setImage(imgEx);
// Specify image offsets from the corresponding edge of the shape's bounding box
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetLeft(25f);
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetRight(25f);
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetTop(-20f);
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetBottom(-10f);
// Save created presentation
presentation.save(dataDir +"StretchOffsetExample_out.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangingOrderOfShapes.class);
Presentation presentation1 = new Presentation();
ISlide slide = presentation1.getSlides().get_Item(0);
IAutoShape shp3 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 365, 400, 150);
shp3.getFillFormat().setFillType(FillType.NoFill);
shp3.addTextFrame(" ");
ITextFrame txtFrame = shp3.getTextFrame();
IParagraph para = txtFrame.getParagraphs().get_Item(0);
IPortion portion = para.getPortions().get_Item(0);
portion.setText("Watermark Text Watermark Text Watermark Text");
shp3 = slide.getShapes().addAutoShape(ShapeType.Triangle, 200, 365, 400, 150);
slide.getShapes().reorder(1, shp3);
;
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloningShapesInSlides.class);
// Instantiate Presentation class
Presentation srcPres = new Presentation(dataDir + "Source Frame.pptx");
// Accessing source slide shape collection
IShapeCollection sourceShapes = srcPres.getSlides().get_Item(0).getShapes();
ILayoutSlide blankLayout = srcPres.getMasters().get_Item(0).getLayoutSlides().getByType(SlideLayoutType.Blank);
ISlide destSlide = srcPres.getSlides().addEmptySlide(blankLayout);
// Accessing destination slide shape collection
IShapeCollection destShapes = destSlide.getShapes();
// Clone shapes by using different methods
destShapes.addClone(sourceShapes.get_Item(1), 50, 150 + sourceShapes.get_Item(0).getHeight());
destShapes.addClone(sourceShapes.get_Item(2));
destShapes.addClone(sourceShapes.get_Item(3), 50, 200, 50, 50);
destShapes.addClone(sourceShapes.get_Item(4));
// destShapes.addClone(sourceShapes.get_Item(5), 300, 300, 50, 200);
destShapes.insertClone(0, sourceShapes.get_Item(0), 50, 150);
// Write the PPTX file to disk
srcPres.save(dataDir + "CloneShape.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConnectingShapesUsingConnectors.class);
// Instantiate Presentation class that represents the PPTX file
Presentation input = new Presentation();
// Accessing shapes collection for selected slide
IShapeCollection shapes = input.getSlides().get_Item(0).getShapes();
// Add Autoshape Ellipse
IAutoShape ellipse = shapes.addAutoShape(ShapeType.Ellipse, 0, 100, 100, 100);
// Add Autoshape Rectangle
IAutoShape rectangle = shapes.addAutoShape(ShapeType.Rectangle, 100, 300, 100, 100);
// Adding connector shape to slide shape collection
IConnector connector = shapes.addConnector(ShapeType.BentConnector2, 0, 0, 10, 10);
// Joining Shapes to connectors
connector.setStartShapeConnectedTo(ellipse);
connector.setEndShapeConnectedTo(rectangle);
connector.reroute();
// Saving Presentation
input.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConnectingShapeWithConnectorOnDesiredConnectionSite.class);
// Instantiate Presentation class that represents the PPTX file
Presentation input = new Presentation();
// Accessing shapes collection for selected slide
IShapeCollection shapes = input.getSlides().get_Item(0).getShapes();
// Add Autoshape Ellipse
IAutoShape ellipse = shapes.addAutoShape(ShapeType.Ellipse, 0, 100, 100, 100);
// Add Autoshape Rectangle
IAutoShape rectangle = shapes.addAutoShape(ShapeType.Rectangle, 100, 300, 100, 100);
// Adding connector shape to slide shape collection
IConnector connector = shapes.addConnector(ShapeType.BentConnector2, 0, 0, 10, 10);
// Joining Shapes to connectors
connector.setStartShapeConnectedTo(ellipse);
connector.setEndShapeConnectedTo(rectangle);
// Setting the desired connection site index of Ellipse shape for
// connector to get connected
int wantedIndex = 6;
// Checking if desired index is less than maximum site index count
if (ellipse.getConnectionSiteCount() > wantedIndex) {
// Setting the desired connection site for connector on Ellipse
connector.setStartShapeConnectionSiteIndex(wantedIndex);
}
// Saving presentation
input.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ControllingPictureFrameFormatting.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Instantiate the Image class
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg")));
} catch (IOException e) {
}
// Add Picture Frame with height and width equivalent of Picture
IPictureFrame pf = sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx);
// Apply some formatting to PictureFrameEx
pf.getLineFormat().getFillFormat().setFillType(FillType.Solid);
pf.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
pf.getLineFormat().setWidth(20);
pf.setRotation(45);
// Write the PPTX file to disk
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public static void main(String[] args) {
String dataDir = Utils.getDataDir(ExportShapeToSVG.class);
String pptxFileName = "Presentation.pptx";
Presentation pres = new Presentation(pptxFileName);
try{
OutputStream stream = new ByteArrayOutputStream();
pres.getSlides().get_Item(0).getShapes().get_Item(0).writeAsSvg(stream);
}finally {
pres.dispose();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FillingShapesWithGradient.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of ellipse type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 75, 150);
// Apply some Gradient formatting to ellipse shape
shp.getFillFormat().setFillType(FillType.Gradient);
shp.getFillFormat().getGradientFormat().setGradientShape(GradientShape.Linear);
// Set the Gradient Direction
shp.getFillFormat().getGradientFormat().setGradientDirection(GradientDirection.FromCorner2);
// Add two Gradient Stops
shp.getFillFormat().getGradientFormat().getGradientStops().add((float) 1.0, Color.pink);
shp.getFillFormat().getGradientFormat().getGradientStops().add((float) 0, Color.red);
// Write the PPTX file to disk
pres.save(dataDir + "EllipseShpGrad.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of rectangle type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150);
// Set the fill type to Pattern
shp.getFillFormat().setFillType(FillType.Pattern);
// Set the pattern style
shp.getFillFormat().getPatternFormat().setPatternStyle(PatternStyle.Trellis);
// Set the pattern back and fore colors
shp.getFillFormat().getPatternFormat().getBackColor().setColor(Color.LIGHT_GRAY);
shp.getFillFormat().getPatternFormat().getForeColor().setColor(Color.YELLOW);
// Write the PPTX file to disk
pres.save(dataDir + "RectShpPatt.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FillingShapesWithPicture.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of rectangle type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150);
// Set the fill type to Picture
shp.getFillFormat().setFillType(FillType.Picture);
// Set the picture fill mode
shp.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Tile);
// Set the picture
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File("aspose1.jpg")));
} catch (IOException e) {
}
shp.getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
// Write the PPTX file to disk
pres.save(dataDir + "RectShpPic.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FillingShapesWithSolidColor.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of rectangle type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150);
// Set the fill type to Solid
shp.getFillFormat().setFillType(FillType.Solid);
// Set the color of the rectangle
shp.getFillFormat().getSolidFillColor().setColor(Color.YELLOW);
// Write the PPTX file to disk
pres.save(dataDir + "RectShpSolid.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
public static void main(String[] args) {
// The path to the documents directory.
String dataDir = Utils.getDataDir(FindShapeInSlide.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "Source Frame.pptx");
// Accessing a slide using its slide index
ISlide slide = pres.getSlides().get_Item(0);
// Calling FindShape method and passing the slide reference with the
// alternative text of the shape to be found
IShape shape = findShape(slide, "Shape1");
}
static IShape findShape(ISlide slide, String alttext) {
// Iterating through all shapes inside the slide
for (int i = 0; i < slide.getShapes().size(); i++) {
// If the alternative text of the slide matches with the required
// one then return the shape
if (slide.getShapes().get_Item(i).getAlternativeText().compareTo(alttext) == 0)
return slide.getShapes().get_Item(i);
}
return null;
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FormattingTheJoinStyles.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add three AutoShapes of rectangle type
IShape shp1 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 100, 150, 75);
IShape shp2 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 300, 100, 150, 75);
IShape shp3 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 250, 150, 75);
// Set the fill color of the rectangle shape
shp1.getFillFormat().setFillType(FillType.Solid);
shp1.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
shp2.getFillFormat().setFillType(FillType.Solid);
shp2.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
shp3.getFillFormat().setFillType(FillType.Solid);
shp3.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// Set the line width
shp1.getLineFormat().setWidth(15);
shp2.getLineFormat().setWidth(15);
shp3.getLineFormat().setWidth(15);
// Set the color of the line of rectangle
shp1.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp1.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
shp2.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp2.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
shp3.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp3.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
// Set the Join Style
shp1.getLineFormat().setJoinStyle(LineJoinStyle.Miter);
shp2.getLineFormat().setJoinStyle(LineJoinStyle.Bevel);
shp3.getLineFormat().setJoinStyle(LineJoinStyle.Round);
// Add text to each rectangle
((IAutoShape) shp1).getTextFrame().setText("This is Miter Join Style");
((IAutoShape) shp2).getTextFrame().setText("This is Bevel Join Style");
((IAutoShape) shp3).getTextFrame().setText("This is Round Join Style");
// Write the PPTX file to disk
pres.save(dataDir + "RectShpLnJoin.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(FormattingTheLinesOfShapes.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of rectangle type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 75);
// Set the fill color of the rectangle shape
shp.getFillFormat().setFillType(FillType.Solid);
shp.getFillFormat().getSolidFillColor().setColor(Color.WHITE);
// Apply some formatting on the line of the rectangle
shp.getLineFormat().setStyle(LineStyle.ThickThin);
shp.getLineFormat().setWidth(7);
shp.getLineFormat().setDashStyle(LineDashStyle.Dash);
// set the color of the line of rectangle
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
// Write the PPTX file to disk
pres.save(dataDir + "RectShpLn.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingAShapeThumbnailInTheBoundsOfAShapesAppearance.class);
// Instantiate a Presentation class that represents the presentation file
Presentation p = new Presentation(dataDir + "Thumbnail.pptx");
// Create a Appearance bound shape image
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail(ShapeThumbnailBounds.Appearance, 1, 1);
try {
ImageIO.write(image, "jpeg", new File(dataDir + "PPTX_thumbnail.jpg"));
} catch (IOException e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingAThumbnailFromASlideWithUserDefinedScalingFactor.class);
// Instantiate a Presentation class that represents the presentation file
Presentation p = new Presentation(dataDir + "Thumbnail.pptx");
// Create a full scale image
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail(ShapeThumbnailBounds.Shape, 1, 1);
try {
// Save the image to disk in PNG format
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (Exception e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingAThumbnailOfSmartArtChildNode.class);
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.BasicCycle);
// Obtain the reference of a node by using its Index
ISmartArtNode node = smart.getNodes().get_Item(1);
// Generating SmartArt node thumbnail
BufferedImage image = node.getShapes().get_Item(0).getThumbnail();
try {
// Save the image to disk in PNG format
ImageIO.write(image, "png", new File(dataDir + "NodeImage.png"));
} catch (Exception e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GeneratingShapeThumbnailFromASlide.class);
// Instantiate a Presentation class that represents the presentation file
Presentation p = new Presentation(dataDir + "Thumbnail.pptx");
// Create a full scale image
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail();
try {
// Save the image to disk in PNG format
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
} catch (Exception e) {
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GettingPositionCoordinatesOfPortion.class);
// Creating new object
Presentation pres = new Presentation(dataDir + "HelloWorld.pptx");
// Reshaping the context of presentation
IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0);
ITextFrame textFrame = (ITextFrame) shape.getTextFrame();
for (IParagraph paragraph : textFrame.getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
Point2D.Float point = portion.getCoordinates();
System.out.println("X: " + point.x + " Y: " + point.y);
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GettingRectangularCoordinatesOfParagraph.class);
// Paragragh bounds in rectangle
Presentation pres = new Presentation(dataDir + "HelloWorld.pptx");
IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0);
ITextFrame textFrame = (ITextFrame) shape.getTextFrame();
Rectangle2D.Float rect = ((IParagraph) textFrame.getParagraphs().get_Item(0)).getRect();
System.out.println("X: " + rect.x + " Y: " + rect.y + " Width: " + rect.width + " Height: " + rect.height);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(HidingTheShapesFromSlide.class);
Presentation presentation1 = new Presentation();
ISlide slide = presentation1.getSlides().get_Item(0);
for (int i = 0; i < slide.getShapes().size(); i++) {
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(i);
ashp.setHidden(true);
}
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Workbook book = new Workbook(dataDir + "chart.xlsx");
Worksheet sheet = book.getWorksheets().get(0); //or get_Item()
com.aspose.cells.ImageOrPrintOptions options = new com.aspose.cells.ImageOrPrintOptions();
options.setHorizontalResolution (200);
options.setVerticalResolution(200);
options.setImageFormat(ImageFormat.getEmf());// <- check this
//Save the workbook to stream
SheetRender sr = new SheetRender(sheet, options);
Presentation pres = new Presentation();
pres.getSlides().removeAt(0);
String EmfSheetName="";
for (int j = 0; j < sr.getPageCount(); j++)
{
EmfSheetName=dataDir + "test" + sheet.getName() + " Page" + (j + 1) + ".out.emf";
sr.toImage(j, EmfSheetName);
Path path = Paths.get(EmfSheetName);
byte[] bytes = Files.readAllBytes(path);
com.aspose.slides.IPPImage emfImage = pres.getImages().addImage(bytes);
ISlide slide= pres.getSlides().addEmptySlide(pres.getLayoutSlides().getByType(com.aspose.slides.SlideLayoutType.Blank));
IShape m = slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0,
(float)pres.getSlideSize().getSize().getWidth(), (float)pres.getSlideSize().getSize().getHeight(), emfImage);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(InterLopShapeId.class);
Presentation presentation = new Presentation("Presentation.pptx");
try{
// Getting unique shape identifier in slide scope
long officeInteropShapeId = presentation.getSlides().get_Item(0).getShapes().get_Item(0).getOfficeInteropShapeId();
}
finally {
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemovingShapeFromASlide.class);
Presentation presentation1 = new Presentation();
ISlide slide = presentation1.getSlides().get_Item(0);
String alttext = "User Defined";
int iCount = slide.getShapes().size();
for (int i = 0; i < iCount; i++) {
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(0);
if (ashp.getAlternativeText().compareTo(alttext) == 0) {
slide.getShapes().remove(ashp);
}
}
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RotatingShapes.class);
// Instantiate Presentation class that represents the PPTX
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape of rectangle type
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150);
// Rotate the shape to 90 degree
shp.setRotation(90);
// Write the PPTX file to disk
pres.save(dataDir + "RectShpRot.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingImageOnAVideoFrame.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Get the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add Video Frame
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, dataDir + "Wildlife.mp4");
// Set Image
IPPImage img = null;
img = pres.getImages().addImage(new FileInputStream(new File(dataDir + "Sample.jpg")));
vf.getPictureFormat().getPicture().setImage(img);
// Write the PPTX file to disk
pres.save(dataDir + "Test.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheAlternativeTextPropertyOfShapes.class);
Presentation presentation1 = new Presentation();
ISlide slide = presentation1.getSlides().get_Item(0);
IAutoShape shp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 40, 150, 50);
IAutoShape shp1 = slide.getShapes().addAutoShape(ShapeType.Moon, 160, 40, 150, 50);
shp.getFillFormat().setFillType(FillType.Solid);
shp.getFillFormat().getSolidFillColor().setColor(Color.GRAY);
for (int i = 0; i < slide.getShapes().size(); i++) {
if (slide.getShapes().get_Item(i) instanceof IAutoShape) {
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(i);
ashp.setAlternativeText("User Defind");
}
}
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessAnExistingTableInSlide.class);
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation(dataDir + "table.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Initialize null Table
ITable tbl = null;
// Iterate through the shapes and set a reference to the table found
for (IShape shp : sld.getShapes()) {
if (shp instanceof ITable) {
tbl = (ITable) shp;
}
}
// Set the text of the first column of second row
tbl.getRows().get_Item(0).get_Item(1).getTextFrame().setText("New");
// Save the PPTX to Disk
pres.save(dataDir + "table1.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddAnImageInATableCell.class);
// Instantiate Presentation class Object
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights
double[] dblCols = { 150, 150, 150, 150 };
double[] dblRows = { 100, 100, 100, 100, 90 };
// Add table shape to slide
ITable tbl = sld.getShapes().addTable(50, 50, dblCols, dblRows);
// Creating a Buffered Image object to hold the image file
BufferedImage image = null;
image = ImageIO.read(new File(dataDir + "image.jpg"));
IPPImage imgx1 = pres.getImages().addImage(image);
tbl.get_Item(0, 0).getFillFormat().setFillType(FillType.Picture);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().getPicture().setImage(imgx1);
// Save PPTX to Disk
pres.save(dataDir + "table.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddImageInTableCell.class);
//Instantiate Presentation class object
Presentation pres = new Presentation();
//Access first slide
ISlide sld = pres.getSlides().get_Item(0);
//Define columns with widths and rows with heights
double[] dblCols = { 150, 150, 150, 150 };
double[] dblRows = { 100, 100, 100, 100, 90 };
//Add table shape to slide
ITable tbl = sld.getShapes().addTable(50, 50, dblCols, dblRows);
//Creating an Image object to hold the image file
IPPImage imgx = null;
try {
imgx = pres.getImages().addImage(new FileInputStream(new File("aspose1.jpg")));
} catch (IOException e) {
}
//Create an IPPImage object using the bitmap object
IPPImage imgx1 = pres.getImages().addImage(imgx);
//Add image to first table cell
tbl.get_Item(0, 0).getFillFormat().setFillType(FillType.Picture);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropRight(-30f);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropLeft(-30f);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropBottom(-30f);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropTop(-30f);
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().getPicture().setImage(imgx);
//Save PPTX to Disk
pres.save("D:\\Data\\table.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CloneARowOrColumnInATable.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30 };
// Add table shape to slide
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// Set border format for each cell
for (int row = 0; row < tbl.getRows().size(); row++) {
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) {
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat()
.setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5);
}
}
tbl.getColumns().get_Item(0).get_Item(0).getTextFrame().setText("00");
tbl.getColumns().get_Item(0).get_Item(1).getTextFrame().setText("01");
tbl.getColumns().get_Item(0).get_Item(2).getTextFrame().setText("02");
tbl.getColumns().get_Item(0).get_Item(3).getTextFrame().setText("03");
tbl.getColumns().get_Item(1).get_Item(0).getTextFrame().setText("10");
tbl.getColumns().get_Item(2).get_Item(0).getTextFrame().setText("20");
tbl.getColumns().get_Item(1).get_Item(1).getTextFrame().setText("11");
tbl.getColumns().get_Item(2).get_Item(1).getTextFrame().setText("21");
// AddClone adds a row in the end of the table
tbl.getRows().addClone(tbl.getRows().get_Item(0), false);
// AddClone adds a column in the end of the table
tbl.getColumns().addClone(tbl.getColumns().get_Item(0), false);
// InsertClone adds a row at specific position in a table
tbl.getRows().insertClone(2, tbl.getRows().get_Item(0), false);
// InsertClone adds a row at specific position in a table
tbl.getColumns().insertClone(2, tbl.getColumns().get_Item(0), false);
// Save PPTX to Disk
pres.save(dataDir + "Cloning.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreateATableFromScratchInASlide.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };
// Add table shape to slide
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// Set border format for each cell
for (int row = 0; row < tbl.getRows().size(); row++) {
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) {
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat()
.setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor()
.setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5);
}
}
// Merge cells 1 & 2 of row 1
tbl.mergeCells(tbl.getRows().get_Item(0).get_Item(0), tbl.getRows().get_Item(1).get_Item(0), false);
// Add text to the merged cell
tbl.getRows().get_Item(0).get_Item(0).getTextFrame().setText("Merged Cells");
// Save PPTX to Disk
pres.save(dataDir + "table.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(EnableDisableFirstRowAsHeader.class);
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation(dataDir + "table.pptx");
// Access the first slide
ISlide sld = pres.getSlides().get_Item(0);
// Initialize null TableEx
ITable tbl = null;
// Iterate through the shapes and set a reference to the table found
for (IShape shp : sld.getShapes()) {
if (shp instanceof ITable) {
tbl = (ITable) shp;
}
}
//Check if the first row of a table is with header formatting
tbl.getFirstRow();
//Set the first row of a table as header with a special formatting.
tbl.setFirstRow(true);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(IdentifyingTheMergedCellsinTable.class);
Presentation pres = null;
try
{
pres = new Presentation(dataDir+"SomePresentationWithTable.pptx");
ITable table = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0); // assuming that Slide#0.Shape#0 is a table
for (int i = 0; i < table.getRows().size(); i++)
{
for (int j = 0; j < table.getColumns().size(); j++)
{
ICell currentCell = table.getRows().get_Item(i).get_Item(j);
if (currentCell.isMergedCell())
{
System.out.println("Cell " + i + ";" + j +" is a part of merged cell with RowSpan=" + currentCell.getRowSpan() +
" and ColSpan=" + currentCell.getColSpan() + " starting from Cell " + currentCell.getFirstRowIndex() +
";" + currentCell.getFirstColumnIndex() + ".");
}
}
}
} finally {
if (pres != null) {
pres.dispose();
pres = null;
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemoveARowOrColumnInATable.class);
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);
double[] colWidth = { 100, 50, 30 };
double[] rowHeight = { 30, 50, 30 };
ITable table = slide.getShapes().addTable(100, 100, colWidth, rowHeight);
table.getRows().removeAt(1, false);
table.getColumns().removeAt(1, false);
pres.save(dataDir + "TestTable.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(RemoveBordersOfATableCells.class);
// Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };
// Add table shape to slide
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// Set border format for each cell
for (int row = 0; row < tbl.getRows().size(); row++) {
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) {
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.NoFill);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat()
.setFillType(FillType.NoFill);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.NoFill);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat()
.setFillType(FillType.NoFill);
}
}
// Save PPTX to Disk
pres.save(dataDir + "table_no_border.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTextFormattingInsideTable.class);
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
ITable someTable = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0); // let's say that the first shape on the first slide is a table
// setting table cells' font height
PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(25);
someTable.setTextFormat(portionFormat);
// setting table cells' text alignment and right margin in one call
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(TextAlignment.Right);
paragraphFormat.setMarginRight(20);
someTable.setTextFormat(paragraphFormat);
// setting table cells' text vertical type
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(TextVerticalType.Vertical);
someTable.setTextFormat(textFrameFormat);
// Save the PPTX to Disk
pres.save(dataDir + "Textbox.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTextFormattingInsideTableColumn.class);
Presentation presentation=new Presentation(dataDir+"");
ISlide sld = presentation.getSlides().get_Item(0);
// ITable someTable = presentation.Slides[0].Shapes[0] as ITable;
ITable someTable = (ITable)presentation.getSlides().get_Item(0).getShapes().get_Item(0);
// setting first column cells' font height
PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(25f);
//someTable.Columns[0].SetTextFormat(portionFormat);
someTable.getColumns().get_Item(0).setTextFormat(portionFormat);
// setting first column cells' text alignment and right margin in one call
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(Right);
// paragraphFormat.MarginRight = 20;
paragraphFormat.setMarginRight(20);
someTable.getColumns().get_Item(0).setTextFormat(paragraphFormat);
// setting second column cells' text vertical type
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(Vertical);
someTable.getColumns().get_Item(0).setTextFormat(textFrameFormat);
// Save the PPTX to Disk
presentation.save(dataDir + "Textbox.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTextFormattingInsideTableRow.class);
Presentation presentation=new Presentation(dataDir+"");
ISlide sld = presentation.getSlides().get_Item(0);
// ITable someTable = presentation.Slides[0].Shapes[0] as ITable; // let's say that the first shape on the first slide is a table
ITable someTable = (ITable)presentation.getSlides().get_Item(0).getShapes().get_Item(0);
PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(25f);
someTable.getRows().get_Item(0).setTextFormat(portionFormat);
// setting first row cells' text alignment and right margin in one call
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(Right);
paragraphFormat.setMarginRight(20);
someTable.getRows().get_Item(0).setTextFormat(paragraphFormat);
// setting second row cells' text vertical type
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(Vertical);
someTable.getColumns().get_Item(0).setTextFormat(textFrameFormat);
presentation.save(dataDir + "Textbox.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(VerticallyAlignTheTextInTableCell.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Get the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights
double[] dblCols = { 120, 120, 120, 120 };
double[] dblRows = { 100, 100, 100, 100 };
// Add table shape to slide
ITable tbl = slide.getShapes().addTable(100, 50, dblCols, dblRows);
// Add text to the merged cell
tbl.getRows().get_Item(0).get_Item(1).getTextFrame().setText("10");
tbl.getRows().get_Item(0).get_Item(2).getTextFrame().setText("20");
tbl.getRows().get_Item(0).get_Item(3).getTextFrame().setText("30");
// Accessing the text frame
ITextFrame txtFrame = tbl.getRows().get_Item(0).get_Item(0).getTextFrame();
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
portion.setText("Text here");
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// Aligning the text vertically
ICell cell = tbl.getRows().get_Item(0).get_Item(0);
cell.setTextAnchorType(TextAnchorType.Center);
cell.setTextVerticalType(TextVerticalType.Vertical270);
// Save Presentation
pres.save(dataDir + "TableCellVertical.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(BetterTransition.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "BetterSlideTransitions.pptx");
// Accessing a slide using its slide position
ISlide slide = pres.getSlides().get_Item(1);
// Setting the slide transition effect to fade
slide.getSlideShowTransition().setType(TransitionType.Fade);
// Setting the speed of slide transition to slow
slide.getSlideShowTransition().setSpeed(TransitionSpeed.Slow);
// Setting the transition to advance on click
slide.getSlideShowTransition().setAdvanceOnClick(true);
// Setting the transition to advance after a specific time period
slide.getSlideShowTransition().setAdvanceAfterTime(5);
// Writing the presentation as a PPTX file
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingBetterSlideTransitions.class);
// Instantiate Presentation class that represents a presentation file
Presentation pres = new Presentation(dataDir + "BetterSlideTransitions.pptx");
// Apply circle type transition on slide 1
pres.getSlides().get_Item(0).getSlideShowTransition().setType(TransitionType.Circle);
// Set the transition time of 3 seconds
// Set the transition time of 5 seconds
pres.getSlides().get_Item(0).getSlideShowTransition().setAdvanceOnClick(true);
pres.getSlides().get_Item(0).getSlideShowTransition().setAdvanceAfterTime(3000);
// Apply comb type transition on slide 2
pres.getSlides().get_Item(1).getSlideShowTransition().setType(TransitionType.Comb);
// Set the transition time of 5 seconds
pres.getSlides().get_Item(1).getSlideShowTransition().setAdvanceOnClick(true);
pres.getSlides().get_Item(1).getSlideShowTransition().setAdvanceAfterTime(5000);
// Apply zoom type transition on slide 3
pres.getSlides().get_Item(2).getSlideShowTransition().setType(TransitionType.Zoom);
// Set the transition time of 7 seconds
pres.getSlides().get_Item(2).getSlideShowTransition().setAdvanceOnClick(true);
pres.getSlides().get_Item(2).getSlideShowTransition().setAdvanceAfterTime(7000);
// Write the presentation to disk
pres.save(dataDir + "SampleTransition.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingSimpleSlideTransitions.class);
// Instantiate Presentation class that represents a presentation file
Presentation pres = new Presentation(dataDir + "SimpleSlideTransitions.pptx");
// Apply circle type transition on slide 1
pres.getSlides().get_Item(0).getSlideShowTransition().setType(TransitionType.Circle);
// Apply comb type transition on slide 2
pres.getSlides().get_Item(1).getSlideShowTransition().setType(TransitionType.Comb);
// Apply zoom type transition on slide 3
pres.getSlides().get_Item(2).getSlideShowTransition().setType(TransitionType.Zoom);
// Write the presentation to disk
pres.save(dataDir + "SampleTransition.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SettingTheTransitionEffects.class);
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Set effect
pres.getSlides().get_Item(0).getSlideShowTransition().setType(TransitionType.Cut);
((OptionalBlackTransition) pres.getSlides().get_Item(0).getSlideShowTransition().getValue()).setFromBlack(true);
// Write the presentation to disk
pres.save(dataDir + "Test.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SimpleTransition.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "SimpleSlideTransitions.pptx");
// Accessing a slide using its slide position
ISlide slide = pres.getSlides().get_Item(1);
// Setting the slide transition effect to fade
slide.getSlideShowTransition().setType(TransitionType.Fade);
// Writing the presentation as a PPTX file
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingSmartArtShapeChildNodeAtSpecificPosition.class);
// Instantiate the presentation
Presentation pres = new Presentation();
// Accessing the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Adding the SmartArt shape in first slide
ISmartArt smart = slide.getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.StackedList);
// Accessing the SmartArt node at index 0
ISmartArtNode node = smart.getAllNodes().get_Item(0);
// Accessing the child node at position 1 in parent node
int position = 1;
SmartArtNode chNode = (SmartArtNode) ((SmartArtNodeCollection) node.getChildNodes()).get_Item(position);
// Printing the SmartArt child node parameters
System.out.print("Text = " + chNode.getTextFrame().getText() + ", Level = " + chNode.getLevel() + ", Position = " + chNode.getPosition());
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "AccessChildNodes.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Traverse through all nodes inside SmartArt
for (int i = 0; i < smart.getAllNodes().size(); i++) {
// Accessing SmartArt node at index i
SmartArtNode node0 = (SmartArtNode) smart.getAllNodes().get_Item(i);
// Traversing through the child nodes in SmartArt node at index i
for (int j = 0; j < node0.getChildNodes().size(); j++) {
// Accessing the child node in SmartArt node
SmartArtNode node = (SmartArtNode) node0.getChildNodes().get_Item(j);
// Printing the SmartArt child node parameters
System.out.print("j = " + j + ", Text = " + node.getTextFrame().getText() + ", Level = " + node.getLevel() + ", Position = " + node.getPosition());
}
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "SmartArtShape.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Traverse through all nodes inside SmartArt
for (int i = 0; i < smart.getAllNodes().size(); i++) {
// Accessing SmartArt node at index i
SmartArtNode node = (SmartArtNode) smart.getAllNodes().get_Item(i);
// Printing the SmartArt node parameters
System.out.print(node.getTextFrame().getText() + " " + node.getLevel() + " " + node.getPosition());
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "SmartArtNode.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Checking SmartArt Layout
if (smart.getLayout() == SmartArtLayoutType.BasicBlockList) {
System.out.print("Do some thing here....");
}
}
}
// Saving presentation
pres.save(dataDir + "SimpleSmartArt.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessingTheSmartArtShapeInSlide.class);
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "SimpleSmartArt.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddingSmartArtShapeNodeAtSpecificPosition.class);
// Creating a presentation instance
Presentation pres = new Presentation();
// Access the presentation slide
ISlide slide = pres.getSlides().get_Item(0);
// Add Smart Art IShape
ISmartArt smart = slide.getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.StackedList);
// Accessing the SmartArt node at index 0
ISmartArtNode node = smart.getAllNodes().get_Item(0);
// Adding new child node at position 2 in parent node
SmartArtNode chNode = (SmartArtNode) ((SmartArtNodeCollection) node.getChildNodes()).addNodeByPosition(2);
// Add Text
chNode.getTextFrame().setText("Sample Text Added");
// Save Presentation
pres.save(dataDir + "AddSmartArtNodeByPosition.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Load the desired the presentation
Presentation pres = new Presentation(dataDir + "SimpleSmartArt.pptx");
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof SmartArt) {
// Typecast shape to SmartArt
SmartArt smart = (SmartArt) shape;
// Adding a new SmartArt Node
SmartArtNode TemNode = (SmartArtNode) smart.getAllNodes().addNode();
// Adding text
TemNode.getTextFrame().setText("Test");
// Adding new child node in parent node. It will be added in the end of collection
SmartArtNode newNode = (SmartArtNode) TemNode.getChildNodes().addNode();
// Adding text
newNode.getTextFrame().setText("New Node Added");
}
}
// Saving Presentation
pres.save(dataDir + "AddSmartArtNode.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt BasicBlockList
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.BasicBlockList);
// Change LayoutType to BasicProcess
smart.setLayout(SmartArtLayoutType.BasicProcess);
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "SimpleSmartArt.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Checking SmartArt color type
if (smart.getColorStyle() == SmartArtColorType.ColoredFillAccent1) {
// Changing SmartArt color type
smart.setColorStyle(SmartArtColorType.ColorfulAccentColors);
}
}
}
// Saving presentation
pres.save(dataDir + "ChangeSmartArtColorStyle.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir + "SimpleSmartArt.pptx");
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Traverse through every shape inside first slide
for (IShape shape : slide.getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
// Checking SmartArt style
if (smart.getQuickStyle() == SmartArtQuickStyleType.SimpleFill) {
// Changing SmartArt Style
smart.setQuickStyle(SmartArtQuickStyleType.Cartoon);
}
}
}
// Saving presentation
pres.save(dataDir + "ChangeSmartArtStyle.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangingTextOnSmartArtNode.class);
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt BasicCycle
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.BasicCycle);
// Obtain the reference of a node by using its Index
// Select second root node
ISmartArtNode node = smart.getNodes().get_Item(1);
// Setting the text of the TextFrame
node.getTextFrame().setText("Second root node");
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Creating a presentation instance
Presentation pres = new Presentation(dataDir + "AddNodes.pptx");
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (SmartArt) shape;
// Traversing through all nodes of SmartArt shape
for (int i = 0; i < smart.getAllNodes().size(); i++) {
ISmartArtNode node = smart.getAllNodes().get_Item(i);
String tc = node.getTextFrame().getText();
// Check if node is Assistant node
if (node.isAssistant()) {
// Setting Assistant node to false and making it normal node
node.isAssistant();
}
}
}
}
// Save Presentation
pres.save(dataDir + "ChangeAssitantNode.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CheckingHiddenPropertyOfSmartArt.class);
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt RadialCycle
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.RadialCycle);
// Add node on SmartArt
ISmartArtNode node = smart.getAllNodes().addNode();
// Check isHidden property
boolean hidden = node.isHidden(); // returns true
if (hidden) {
// do some actions or notifications
}
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation();
// Get first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add Smart Art Shape
ISmartArt smart = slide.getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.BasicBlockList);
// Saving presentation
pres.save(dataDir + "SimpleSmartArt.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation Class
Presentation pres = new Presentation(dataDir+"SimpleSmartArt.pptx");
try{
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(20, 20, 600, 500, SmartArtLayoutType.OrganizationChart);
// Move SmartArt shape to new position
ISmartArtNode node = smart.getAllNodes().get_Item(1);
ISmartArtShape shape = node.getShapes().get_Item(1);
shape.setX(shape.getX() + shape.getWidth() * 2);
shape.setY(shape.getY() - shape.getHeight() * 2);
// Change SmartArt shape's widths
node = smart.getAllNodes().get_Item(2);
shape = node.getShapes().get_Item(1);
shape.setWidth(shape.getWidth() + shape.getWidth() * 2);
// Change SmartArt shape's height
node = smart.getAllNodes().get_Item(3);
shape = node.getShapes().get_Item(1);
shape.setHeight(shape.getHeight() + shape.getHeight() * 2);
// Change SmartArt shape's rotation
node = smart.getAllNodes().get_Item(4);
shape = node.getShapes().get_Item(1);
shape.setRotation(90);
pres.save(dataDir+ "SmartArt.pptx", SaveFormat.Pptx);
}finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt BasicProcess
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.OrganizationChart);
// Get or Set the organization chart type
smart.getNodes().get_Item(0).setOrganizationChartLayout(OrganizationChartLayoutType.LeftHanging);
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents the PPTX file
Presentation pres = new Presentation();
// Add SmartArt BasicProcess
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.BasicProcess);
// Get or Set the state of SmartArt Diagram
smart.setReversed(true);
boolean flag = smart.isReversed();
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Load the desired the presentation
Presentation pres = new Presentation(dataDir + "AddSmartArtNode.pptx");
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof ISmartArt) {
// Typecast shape to SmartArtEx
ISmartArt smart = (ISmartArt) shape;
if (smart.getAllNodes().size() > 0) {
// Accessing SmartArt node at index 0
ISmartArtNode node = smart.getAllNodes().get_Item(0);
// Removing the selected node
smart.getAllNodes().removeNode(node);
}
}
}
// Save Presentation
pres.save(dataDir + "RemoveSmartArtNode.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Load the desired the presentation
Presentation pres = new Presentation(dataDir + "AddSmartArtNode.pptx");
// Traverse through every shape inside first slide
for (IShape shape : pres.getSlides().get_Item(0).getShapes()) {
// Check if shape is of SmartArt type
if (shape instanceof SmartArt) {
// Typecast shape to SmartArt
SmartArt smart = (SmartArt) shape;
if (smart.getAllNodes().size() > 0) {
// Accessing SmartArt node at index 0
ISmartArtNode node = smart.getAllNodes().get_Item(0);
if (node.getChildNodes().size() >= 2) {
// Removing the child node at position 1
(node.getChildNodes()).removeNode(1);
}
}
}
}
// Save Presentation
pres.save(dataDir + "RemoveSmartArtNodeByPosition.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate the presentation
Presentation pres = new Presentation();
// Accessing the slide
ISlide slide = pres.getSlides().get_Item(0);
// Adding SmartArt shape and nodes
ISmartArt chevron = slide.getShapes().addSmartArt(10, 10, 800, 60, com.aspose.slides.SmartArtLayoutType.ClosedChevronProcess);
ISmartArtNode node = chevron.getAllNodes().addNode();
node.getTextFrame().setText("Some text");
// Setting node fill color
for (IShape item : node.getShapes()) {
item.getFillFormat().setFillType(FillType.Solid);
item.getFillFormat().getSolidFillColor().setColor(Color.RED);
}
// Save the presentation
pres.save(dataDir + "TestSmart.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddColumnInTextBoxes.class);
Presentation presentation = new Presentation();
{
// Get the first slide of presentation
ISlide slide = presentation.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300);
// Add TextFrame to the Rectangle
aShape.addTextFrame("All these columns are limited to be within a single text container -- " +
"you can add or delete text and the new or remaining text automatically adjusts " +
"itself to flow within the container. You cannot have text flow from one container " +
"to other though -- we told you PowerPoint's column options for text are limited!");
// Get text format of TextFrame
ITextFrameFormat format = aShape.getTextFrame().getTextFrameFormat();
// Specify number of columns in TextFrame
format.setColumnCount(3);
// Specify spacing between columns
format.setColumnSpacing(10);
// Save created presentation
presentation.save("ColumnCount.pptx", SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(AddEmbeddedFonts.class);
Presentation pres=new Presentation(dataDir+"");
IFontData[] allFonts = pres.getFontsManager().getFonts();
IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts();
for (IFontData font : except(allFonts, embeddedFonts))
{
pres.getFontsManager().addEmbeddedFont(font,EmbedFontCharacters.All);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation presentation = new Presentation();
// Get slide
ISlide slide = presentation.getSlides().get_Item(0);
// Create text box
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 200, 100);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getParagraphs().clear();
// Create paragraph for superscript text
IParagraph superPar = new Paragraph();
// Create portion with usual text
IPortion portion1 = new Portion();
portion1.setText("SlideTitle");
superPar.getPortions().add(portion1);
// Create portion with superscript text
IPortion superPortion = new Portion();
superPortion.getPortionFormat().setEscapement(30);
superPortion.setText("TM");
superPar.getPortions().add(superPortion);
// Create paragraph for subscript text
IParagraph paragraph2 = new Paragraph();
// Create portion with usual text
IPortion portion2 = new Portion();
portion2.setText("a");
paragraph2.getPortions().add(portion2);
// Create portion with subscript text
IPortion subPortion = new Portion();
subPortion.getPortionFormat().setEscapement(-25);
subPortion.setText("i");
paragraph2.getPortions().add(subPortion);
// Add paragraphs to text box
textFrame.getParagraphs().add(superPar);
textFrame.getParagraphs().add(paragraph2);
BufferedImage bi = presentation.getSlides().get_Item(0).getThumbnail(2f, 2f);
File outputfile = new File("TestOut.png");
ImageIO.write(bi, "png", outputfile);
presentation.save(dataDir +"formatText.pptx",SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ApplyingInnerShadow.class);
// Create an instance of Presentation class
Presentation Pres = new Presentation();
// Get first slide
ISlide Slide = Pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape aShp = Slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Add TextFrame to the Rectangle
aShp.addTextFrame("Aspose TextBox");
// Enable shape fill in case we want to get shadow of text.
aShp.getFillFormat().setFillType(FillType.Solid);
aShp.getFillFormat().getSolidFillColor().setColor(Color.gray);
// Add inner shadow and set all necessary parameters
aShp.getEffectFormat().enableInnerShadowEffect();
IInnerShadow Shadow = aShp.getEffectFormat().getInnerShadowEffect();
Shadow.setBlurRadius(50);
Shadow.setDirection(0);
Shadow.setDistance(0);
Shadow.getShadowColor().setColor(Color.BLUE);
// Write the presentation to disk
Pres.save(dataDir + "ShadowPres.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Create an instance of Presentation class
Presentation Pres = new Presentation();
// Get first slide
ISlide Slide = Pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape aShp = Slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Add TextFrame to the Rectangle
aShp.addTextFrame("Aspose TextBox");
// Disable shape fill in case we want to get shadow of text
aShp.getFillFormat().setFillType(FillType.NoFill);
// Add outer shadow and set all necessary parameters
aShp.getEffectFormat().enableOuterShadowEffect();
IOuterShadow Shadow = aShp.getEffectFormat().getOuterShadowEffect();
Shadow.setBlurRadius(4.0);
Shadow.setDirection(45);
Shadow.setDistance(3);
Shadow.setRectangleAlign(RectangleAlignment.TopLeft);
Shadow.getShadowColor().setColor(Color.black);
// Write the presentation to disk
Pres.save(dataDir + "OutShadow.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingATextBoxOnSlide.class);
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Add TextFrame to the Rectangle
ashp.addTextFrame(" ");
// Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
// Set Text
portion.setText("Aspose TextBox");
// Save the PPTX to Disk
pres.save(dataDir + "Textbox.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(EffectTextBoxParagraph.class);
Presentation pres = new Presentation(dataDir+"Presentation.pptx");
try
{
ISequence sequence = pres.getSlides().get_Item(0).getTimeline().getMainSequence();
IAutoShape autoShape = (IAutoShape)pres.getSlides().get_Item(0).getShapes().get_Item(0);
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs())
{
IEffect[] effects = sequence.getEffectsByParagraph(paragraph);
if (effects.length > 0)
System.out.println("Paragraph \"" + paragraph.getText() + "\" has " + effects[0].getType() + " effect.");
}
}
finally {
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(EmbedFontsInHtml.class);
// byte[] memoryFont1 = ReadAllBytesFromFile("customfonts\\CustomFont1.ttf");
// byte[] memoryFont2 = ReadAllBytesFromFile("customfonts\\CustomFont2.ttf");
Path path = Paths.get("path/to/file");
byte[] memoryFont1 = Files.readAllBytes(path);
byte[] memoryFont2 = Files.readAllBytes(path);
ILoadOptions loadOptions = new LoadOptions();
loadOptions.getDocumentLevelFontSources().setFontFolders(new String[] { "assets\\fonts", "global\\fonts" });
loadOptions.getDocumentLevelFontSources().setMemoryFonts(new byte[][] { memoryFont1, memoryFont2 });
IPresentation presentation = CreatePresentation("MyPresentation.pptx", loadOptions);
try{
//work with the presentation
//CustomFont1, CustomFont2 as well as fonts from assets\fonts & global\fonts folders and their subfolders are available to the presentation
}
finally {
presentation.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExportingParagraphsTextToHTML.class);
// Load the presentation file
Presentation pres = new Presentation(dataDir + "DemoFile.pptx");
// Access the default first slide of presentation
ISlide slide = pres.getSlides().get_Item(0);
// Desired index
int index = 0;
// Accessing the added shape
IAutoShape ashape = (IAutoShape) slide.getShapes().get_Item(index);
try {
// Creating output HTML file
OutputStream os = new FileOutputStream(dataDir + "file.html");
Writer writer = new 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 (Exception fo) {
fo.printStackTrace();
}
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String[] fontFolders = FontsLoader.getFontFolders();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(GetTextFromSmartArtNode.class);
Presentation pres = new Presentation("Presentation.pptx");
try{
ISlide slide = pres.getSlides().get_Item(0);
ISmartArt smartArt = (ISmartArt)slide.getShapes().get_Item(0);
ISmartArtNodeCollection smartArtNodes = smartArt.getAllNodes();
for(ISmartArtNode smartArtNode : smartArtNodes)
{
for (ISmartArtShape nodeShape : smartArtNode.getShapes())
{
if (nodeShape.getTextFrame() != null)
System.out.println(nodeShape.getTextFrame().getText());
}
}
}
finally
{
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ImportingHTMLTextInParagraphs.class);
// Create Empty presentation instance
Presentation pres = new Presentation();
// Access the default first slide of presentation
ISlide slide = pres.getSlides().get_Item(0);
// Adding the AutoShape to accommodate the HTML content
IAutoShape ashape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, (float) pres.getSlideSize().getSize().getWidth(), (float) pres.getSlideSize().getSize().getHeight());
ashape.getFillFormat().setFillType(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 InputStream
InputStream inputStream = new FileInputStream(dataDir + "file.html");
Reader reader = new InputStreamReader(inputStream);
int data = reader.read();
String content = ReadFile(dataDir + "file.html");
// Adding text from HTML stream reader in text frame
ashape.getTextFrame().getParagraphs().addFromHtml(content);
// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);
}
public static String ReadFile(String FileName) throws Exception {
File file = new File(FileName);
StringBuilder contents = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null) {
contents.append(text).append(System.getProperty("line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return contents.toString();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// loading presentation uses SomeFont which is not installed on the system
final Presentation pres = new Presentation("pres.pptx");
try
{
// load SomeFont from file into the byte array
Path path = Paths.get("path/to/file");
byte[] fontData = Files.readAllBytes(path);
// load font represented as byte array
FontsLoader.loadExternalFont(fontData);
// font SomeFont will be available during the rendering or other operations
}
finally { ((IDisposable)pres).dispose(); }
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// load the presentation with embedded "Calibri" font in it
Presentation pres = new Presentation(dataDir + "Pres.pptx");
try {
// render the presentation containing the text frame with the text using embedded "Calibri" font
ImageIO.write(pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720)), "PNG", new File(dataDir + "pres-1.png"));
IFontsManager fontsManager = pres.getFontsManager();
// get all embedded fonts
IFontData[] embeddedFonts = fontsManager.getEmbeddedFonts();
// find "Calibri" font
IFontData calibriEmbeddedFont = null;
for (int i = 0; i < embeddedFonts.length; i++) {
System.out.println(""+ embeddedFonts[i].getFontName());
if ("Calibri".equals(embeddedFonts[i].getFontName())) {
calibriEmbeddedFont = embeddedFonts[i];
break;
}
}
// remove "Calibri" font
fontsManager.removeEmbeddedFont(calibriEmbeddedFont);
// render the presentation after removing the "FunSized" font resulting in a font replacement from "FunSized" to an existing one
ImageIO.write(pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720)), "PNG", new File(dataDir + "pres-2.png"));
// save the presentation without embedded "Calibri" font
pres.save(dataDir + "WithoutEmbeddedFont_out.ppt", SaveFormat.Ppt);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingFontFamilyOfText.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation();
// Get first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 200, 50);
// Remove any fill style associated with the AutoShape
ashp.getFillFormat().setFillType(FillType.NoFill);
// Access the TextFrame associated with the AutoShape
ITextFrame tf = ashp.getTextFrame();
tf.setText("Aspose TextBox");
// Access the Portion associated with the TextFrame
IPortion port = tf.getParagraphs().get_Item(0).getPortions().get_Item(0);
// Set the Font for the Portion
port.getPortionFormat().setLatinFont(new FontData("Times New Roman"));
// Set Bold property of the Font
port.getPortionFormat().setFontBold(NullableBool.True);
// Set Italic property of the Font
port.getPortionFormat().setFontItalic(NullableBool.True);
// Set Underline property of the Font
port.getPortionFormat().setFontUnderline(TextUnderlineType.Single);
// Set the Height of the Font
port.getPortionFormat().setFontHeight(25);
// Set the color of the Font
port.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
port.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
// Save the presentation to disk
pres.save(dataDir + "pptxFont.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingFontRelatedProperties.class);
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "FontProperties.pptx");
// Accessing a slide using its slide position
ISlide slide = pres.getSlides().get_Item(0);
// Accessing the first and second placeholder in the slide and typecasting it as AutoShape
ITextFrame tf1 = ((IAutoShape) slide.getShapes().get_Item(0)).getTextFrame();
ITextFrame tf2 = ((IAutoShape) slide.getShapes().get_Item(1)).getTextFrame();
// Accessing the first Paragraph
IParagraph para1 = tf1.getParagraphs().get_Item(0);
IParagraph para2 = tf2.getParagraphs().get_Item(0);
// Justify the paragraph
para2.getParagraphFormat().setAlignment(TextAlignment.JustifyLow);
// Accessing the first portion
IPortion port1 = para1.getPortions().get_Item(0);
IPortion port2 = para2.getPortions().get_Item(0);
// Define new fonts
FontData fd1 = new FontData("Elephant");
FontData fd2 = new FontData("Castellar");
// Assign new fonts to portion
port1.getPortionFormat().setLatinFont(fd1);
port2.getPortionFormat().setLatinFont(fd2);
// Set font to Bold
port1.getPortionFormat().setFontBold(NullableBool.True);
port2.getPortionFormat().setFontBold(NullableBool.True);
// Set font to Italic
port1.getPortionFormat().setFontItalic(NullableBool.True);
port2.getPortionFormat().setFontItalic(NullableBool.True);
// Set font color
port1.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
port1.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
port2.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
port2.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
// Save the PPTX to disk
pres.save(dataDir + "WelcomeFont.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Loading a presentation with an AutoShape having some text in it.
Presentation pres = new Presentation(dataDir + "Paragraphs.pptx");
// Obtain a slide's reference by its index
ISlide sld = pres.getSlides().get_Item(0);
// Access the TextFrame
ITextFrame tf = ((IAutoShape) sld.getShapes().get_Item(0)).getTextFrame();
// Access the Paragraph
IParagraph para = tf.getParagraphs().get_Item(0);
// Set properties of Paragraph
para.getParagraphFormat().setSpaceWithin(80);
para.getParagraphFormat().setSpaceBefore(40);
para.getParagraphFormat().setSpaceAfter(40);
// SAVING presentation
pres.save(dataDir + "LineSpacing.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingMultipleParagraphsHavingMultiplePortions.class);
// Instantiate a Presentation class that represents a PPTX file
Presentation pres = new Presentation();
// Accessing first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 300, 150);
// Access TextFrame of the AutoShape
ITextFrame tf = ashp.getTextFrame();
// Create Paragraphs and Portions with different text formats
IParagraph para0 = tf.getParagraphs().get_Item(0);
IPortion port01 = new Portion();
IPortion port02 = new Portion();
para0.getPortions().add(port01);
para0.getPortions().add(port02);
IParagraph para1 = new Paragraph();
tf.getParagraphs().add(para1);
IPortion port10 = new Portion();
IPortion port11 = new Portion();
IPortion port12 = new Portion();
para1.getPortions().add(port10);
para1.getPortions().add(port11);
para1.getPortions().add(port12);
IParagraph para2 = new Paragraph();
tf.getParagraphs().add(para2);
IPortion port20 = new Portion();
IPortion port21 = new Portion();
IPortion port22 = new Portion();
para2.getPortions().add(port20);
para2.getPortions().add(port21);
para2.getPortions().add(port22);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).setText("Portion0" + j);
if (j == 0) {
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.RED);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontBold(NullableBool.True);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontHeight(15);
} else if (j == 1) {
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontItalic(NullableBool.True);
tf.getParagraphs().get_Item(i).getPortions().get_Item(j).getPortionFormat().setFontHeight(18);
}
}
// SavePPTX to Disk
pres.save(dataDir + "multiParaPort.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation class that represents a PPTX file
Presentation pres = new Presentation();
// Accessing first slide
ISlide slide = pres.getSlides().get_Item(0);
// Adding and accessing Autoshape
IAutoShape aShp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
// Accessing the text frame of created autoshape
ITextFrame txtFrm = aShp.getTextFrame();
// Removing the default exisiting paragraph
txtFrm.getParagraphs().removeAt(0);
// Creating a paragraph
Paragraph para = new Paragraph();
// Setting paragraph bullet style and symbol
para.getParagraphFormat().getBullet().setType(BulletType.Symbol);
para.getParagraphFormat().getBullet().setChar((char) 8226);
// Setting paragraph text
para.setText("Welcome to Aspose.Slides");
// Setting bullet indent
para.getParagraphFormat().setIndent(25);
// Setting bullet color
para.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB);
para.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK);
// set IsBulletHardColor to true to use own bullet color
para.getParagraphFormat().getBullet().isBulletHardColor();
// Setting Bullet Height
para.getParagraphFormat().getBullet().setHeight(100);
// Adding Paragraph to text frame
txtFrm.getParagraphs().add(para);
// Creating second paragraph
Paragraph para2 = new Paragraph();
// Setting paragraph bullet type and style
para2.getParagraphFormat().getBullet().setType(BulletType.Numbered);
para2.getParagraphFormat().getBullet().setNumberedBulletStyle(NumberedBulletStyle.BulletCircleNumWDBlackPlain);
// Adding paragraph text
para2.setText("This is numbered bullet");
// Setting bullet indent
para2.getParagraphFormat().setIndent(25);
para2.getParagraphFormat().getBullet().getColor().setColorType(ColorType.RGB);
para2.getParagraphFormat().getBullet().getColor().setColor(Color.BLACK);
// set IsBulletHardColor to true to use own bullet color
para2.getParagraphFormat().getBullet().isBulletHardColor();
// Setting Bullet Height
para2.getParagraphFormat().getBullet().setHeight(100);
// Adding Paragraph to text frame
txtFrm.getParagraphs().add(para2);
// saving the presentation as a PPTX file
pres.save(dataDir + "Bullet.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ManagingParagraphIndent.class);
// Instantiate Presentation Class
Presentation pres = new Presentation();
// Get first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add a Rectangle Shape
IAutoShape rect = sld.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 500, 150);
// Add TextFrame to the Rectangle
ITextFrame tf = rect.addTextFrame("This is first line \rThis is second line \rThis is third line");
// Set the text to fit the shape
tf.getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
// Hide the lines of the Rectangle
rect.getLineFormat().getFillFormat().setFillType(FillType.Solid);
// Get first Paragraph in the TextFrame and set its Indent
IParagraph para1 = tf.getParagraphs().get_Item(0);
// Setting paragraph bullet style and symbol
para1.getParagraphFormat().getBullet().setType(BulletType.Symbol);
para1.getParagraphFormat().getBullet().setChar((char) (8226));
para1.getParagraphFormat().setAlignment(TextAlignment.Left);
para1.getParagraphFormat().setDepth((short) 2);
para1.getParagraphFormat().setIndent(30);
// Get second Paragraph in the TextFrame and set its Indent
IParagraph para2 = tf.getParagraphs().get_Item(1);
para2.getParagraphFormat().getBullet().setType(BulletType.Symbol);
para2.getParagraphFormat().getBullet().setChar((char) (8226));
para2.getParagraphFormat().setAlignment(TextAlignment.Left);
para2.getParagraphFormat().setDepth((short) 2);
para2.getParagraphFormat().setIndent(40);
// Get third Paragraph in the TextFrame and set its Indent
IParagraph para3 = tf.getParagraphs().get_Item(2);
para3.getParagraphFormat().getBullet().setType(BulletType.Symbol);
para3.getParagraphFormat().getBullet().setChar((char) (8226));
para3.getParagraphFormat().setAlignment(TextAlignment.Left);
para3.getParagraphFormat().setDepth((short) 2);
para3.getParagraphFormat().setIndent(50);
// Write the Presentation to disk
pres.save(dataDir + "InOutDent.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String dataDir = Utils.getDataDir(ManagingParagraphPictureBulletsInPPTX.class);
Presentation pres = new Presentation();
try {
// Accessing the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Instantiate the image for bullets
BufferedImage img = null;
try {
img = ImageIO.read(new File(dataDir + "asp1.jpg"));
} catch (IOException e) {
}
IPPImage imgx = pres.getImages().addImage(img);
// Adding and accessing Autoshape
IAutoShape aShp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 400, 200);
// Accessing the text frame of created autoshape
ITextFrame txtFrm = aShp.getTextFrame();
// Removing the default exisiting paragraph
txtFrm.getParagraphs().removeAt(0);
// Creating new paragraph
Paragraph para = new Paragraph();
para.setText("Welcome to Aspose.Slides");
// Setting paragraph bullet style and image
para.getParagraphFormat().getBullet().setType(BulletType.Picture);
para.getParagraphFormat().getBullet().getPicture().setImage(imgx);
// Setting Bullet Height
para.getParagraphFormat().getBullet().setHeight(100);
// Adding Paragraph to text frame
txtFrm.getParagraphs().add(para);
// Writing the presentation as a PPTX file
pres.save(dataDir + "Bullet.pptx", SaveFormat.Pptx);
// Writing the presentation as a PPT file
pres.save(dataDir + "Bullet.ppt", SaveFormat.Ppt);
} finally {
if (pres != null)
pres.dispose();
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate a Presentation object that represents a PPTX file
Presentation pres = new Presentation(dataDir + "ParagraphsAlignment.pptx");
// Accessing first slide
ISlide slide = pres.getSlides().get_Item(0);
// Accessing the first and second placeholder in the slide and typecasting it as AutoShape
ITextFrame tf1 = ((IAutoShape) slide.getShapes().get_Item(0)).getTextFrame();
ITextFrame tf2 = ((IAutoShape) slide.getShapes().get_Item(1)).getTextFrame();
// Change the text in both Placeholders
tf1.setText("Center Align by Aspose");
tf2.setText("Center Align by Aspose");
// Getting the first paragraph of the Placeholders
IParagraph para1 = tf1.getParagraphs().get_Item(0);
IParagraph para2 = tf2.getParagraphs().get_Item(0);
// Aligning the text paragraph to center
para1.getParagraphFormat().setAlignment(TextAlignment.Center);
para2.getParagraphFormat().setAlignment(TextAlignment.Center);
// Writing the presentation as a PPTX file
pres.save(dataDir + "Centeralign.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Get reference of a slide
ISlide slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 400, 300);
ashp.getFillFormat().setFillType(FillType.NoFill);
// Add TextFrame to the Rectangle
ashp.addTextFrame("Aspose TextBox");
IPortion port = ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
IPortionFormat pf = port.getPortionFormat();
pf.setFontHeight(50);
// Enable InnerShadowEffect
IEffectFormat ef = pf.getEffectFormat();
ef.enableInnerShadowEffect();
// Set all necessary parameters
ef.getInnerShadowEffect().setBlurRadius(8.0);
ef.getInnerShadowEffect().setDirection(90);
ef.getInnerShadowEffect().setDistance(6.0);
ef.getInnerShadowEffect().getShadowColor().setB((byte) 189);
// Set ColorType as Scheme
ef.getInnerShadowEffect().getShadowColor().setColorType(ColorType.Scheme);
// Set Scheme Color
ef.getInnerShadowEffect().getShadowColor().setSchemeColor(SchemeColor.Accent1);
// Write the presentation as a PPTX file
pres.save(dataDir + "WordArt.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ReplacingFontsExplicitlyInsidePresentation.class);
// Load presentation
Presentation pres = new Presentation(dataDir + "PresContainsArialFont.pptx");
// Load source font to be replaced
IFontData sourceFont = new FontData("Arial");
// Load the replacing font
IFontData destFont = new FontData("Times New Roman");
// Replace the fonts
pres.getFontsManager().replaceFont(sourceFont, destFont);
// Save the presentation
pres.save(dataDir + "PresContainsTimesNoewRomanFont.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation(dataDir + "welcome.pptx");
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Iterate through shapes to find the placeholder
for (IShape shp : sld.getShapes())
if (shp.getPlaceholder() != null) {
// Change the text of each placeholder
((IAutoShape) shp).getTextFrame().setText("This is Placeholder");
}
// Save the PPTX to Disk
pres.save(dataDir + "welcome_PH.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Access the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 350, 350);
// Add TextFrame to the Rectangle
ashp.addTextFrame(" ");
ashp.getFillFormat().setFillType(FillType.NoFill);
// Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();
// Setting text Vertical type
txtFrame.getTextFrameFormat().setTextVerticalType(TextVerticalType.Vertical270);
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
portion.setText("A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog.");
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// Save Presentation
pres.save(dataDir + "VerticleText.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Load presentation
Presentation pres = new Presentation(dataDir + "Fonts.pptx");
// Load source font to be replaced
IFontData sourceFont = new FontData("SomeRareFont");
// Load the replacing font
IFontData destFont = new FontData("Arial");
// Add font rule for font replacement
IFontSubstRule fontSubstRule = new FontSubstRule(sourceFont, destFont, FontSubstCondition.WhenInaccessible);
// Add rule to font substitute rules collection
IFontSubstRuleCollection fontSubstRuleCollection = new FontSubstRuleCollection();
fontSubstRuleCollection.add(fontSubstRule);
// Add font rule collection to rule list
pres.getFontsManager().setFontSubstRuleList(fontSubstRuleCollection);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
Presentation pres = new Presentation();
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 300);
IChartSeries series = chart.getChartData().getSeries().get_Item(0);
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true);
series.getLabels().getDefaultDataLabelFormat().getTextFormat().getTextBlockFormat().setRotationAngle(65);
chart.hasTitle();
chart.getChartTitle().addTextFrameForOverriding("Custom title").getTextFrameFormat().setRotationAngle(-30);
pres.save(dataDir + "out.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CreatingATextBoxOnSlide.class);
// Instantiate Presentation class that represents PPTX
Presentation pres = new Presentation();
// Access first slide
ISlide sld = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);
// Add TextFrame to the Rectangle
ashp.addTextFrame(" ");
// Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
// Set Text
portion.setText("Aspose TextBox");
//Setting Language
portion.getPortionFormat().setLanguageId("en-EN");
// Save the PPTX to Disk
pres.save(dataDir + "SettingLanguage.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Access the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 350, 350);
// Add TextFrame to the Rectangle
ashp.addTextFrame(" ");
ashp.getFillFormat().setFillType(FillType.NoFill);
// Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();
// Setting text anchoring to bottom
txtFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Bottom);
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
portion.setText("A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog.");
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// Save Presentation
pres.save(dataDir + "AnchorText.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Create an instance of Presentation class
Presentation pres = new Presentation();
// Access the first slide
ISlide slide = pres.getSlides().get_Item(0);
// Add an AutoShape of Rectangle type
IAutoShape ashp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 350, 350);
// Add TextFrame to the Rectangle
ashp.addTextFrame(" ");
ashp.getFillFormat().setFillType(FillType.NoFill);
// Accessing the text frame
ITextFrame txtFrame = ashp.getTextFrame();
// Setting text autofit type
txtFrame.getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
// Create the Paragraph object for text frame
IParagraph para = txtFrame.getParagraphs().get_Item(0);
// Create Portion object for paragraph
IPortion portion = para.getPortions().get_Item(0);
portion.setText("A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog.");
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
// Save Presentation
pres.save(dataDir + "formatText.pptx", SaveFormat.Pptx);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(SmartArtNodeAlternativeText.class);
Presentation presentation = new Presentation("testalt.pptx");
ISlide slide = presentation.getSlides().get_Item(0);
IShapeCollection shapes = slide.getShapes();
for(int i = 0; i < shapes.size(); i++)
{
SmartArt shape = (SmartArt) shapes.get_Item(i);
ISmartArtNodeCollection nodes = shape.getAllNodes();
for(ISmartArtNode smartArtNode : nodes)
{
ISmartArtShapeCollection smartshapes = smartArtNode.getShapes();
for(ISmartArtShape smartshape : smartshapes){
if(smartshape.getShapeType() == ShapeType.Rectangle)
System.out.println(smartshape.getAlternativeText());
}
}
}
presentation.save("test2.pptx", com.aspose.slides.SaveFormat.Pptx);
}
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
String[] _fontDir = new String[] { "Sample Fonts" };
// Load the custom font directory fonts
FontsLoader.loadExternalFonts(_fontDir);
// Do Some work and perform presentation/slides rendering
Presentation presentation = new Presentation(dataDir + "DemoFile.pptx");
// Save the presentation
presentation.save(dataDir + "output.pptx", SaveFormat.Pptx);
// Clear Font Cache
FontsLoader.clearCache();
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Use load options to define the default regualr and asian fonts
LoadOptions lo = new LoadOptions(LoadFormat.Auto);
lo.setDefaultRegularFont("Wingdings");
lo.setDefaultAsianFont("Wingdings");
// Do Some work and perform presentation/slides rendering
Presentation presentation = new Presentation(dataDir + "DemoFile.pptx");
// Generate slide thumbnail
BufferedImage image = presentation.getSlides().get_Item(0).getThumbnail(1, 1);
ImageIO.write(image, "png", new File("output.png"));
// Generate PDF
presentation.save(dataDir + "output.pdf", SaveFormat.Pdf);
// Generate XPS
presentation.save(dataDir + "output.xps", SaveFormat.Xps);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Instantiate Presentation
Presentation pres = new Presentation();
// Create new VBA Project
pres.setVbaProject(new VbaProject());
// Add empty module to the VBA project
IVbaModule module = pres.getVbaProject().getModules().addEmptyModule("Module");
// Set module source code
module.setSourceCode("Sub Test(oShape As Shape)MsgBox Test End Sub");
// Create reference to <stdole>
VbaReferenceOleTypeLib stdoleReference = new VbaReferenceOleTypeLib("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
// Create reference to Office
VbaReferenceOleTypeLib officeReference = new VbaReferenceOleTypeLib("Office",
"*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library");
// Add references to the VBA project
pres.getVbaProject().getReferences().add(stdoleReference);
pres.getVbaProject().getReferences().add(officeReference);
pres.save(dataDir + "test.pptm", SaveFormat.Pptm);
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java
// Load Presentation
Presentation pres = new Presentation(dataDir + "VBA.pptm");
// Access the Vba module and remove
pres.getVbaProject().getModules().remove(pres.getVbaProject().getModules().get_Item(0));
// Save Presentation
pres.save(dataDir + "test.pptm", SaveFormat.Pptm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment