Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.Slides for Java
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.

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

Gist for Aspose.Slides for Java
// 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.
}
// 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);
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);
// 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);
// 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.setHtmlFormatter(HtmlFormatter.createCustomFormatter(new CustomFormattingController()));
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// 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) {
}
}
// 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);
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertingODPToPPTX.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "AccessOpenDoc.odp");
// Save the presentation to PDF
pres.save(dataDir + "AccessOpenDoc.pptx", SaveFormat.Pptx);
// 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);
String dataDir = Utils.getDataDir(ConvertingPresentationInNotesSlideViewToPDF.class);
//Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "demo.pptx");
PdfOptions opts = new PdfOptions();
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
//Saving the presentation to PDF notes
pres.save(dataDir + "TestNotes.pdf", SaveFormat.Pdf,opts);
// 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");
TiffOptions opts = new TiffOptions();
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
//Saving the presentation to TIFF notes
pres.save(dataDir + "TestNotes.tiff", SaveFormat.Tiff,opts);
// 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 + "Presentation.pptx");
HtmlOptions htmlOpt = new HtmlOptions();
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
INotesCommentsLayoutingOptions options = htmlOpt.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Saving the presentation to HTML
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt);
String dataDir = Utils.getDataDir(ConvertingPresentationToHTMLWithComments.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
HtmlOptions htmlOpt = new HtmlOptions();
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
INotesCommentsLayoutingOptions options = htmlOpt.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Saving the presentation to HTML
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt);
String dataDir = Utils.getSharedDataDir(ConvertingPresentationToHtmlWithEmbedAllFontsHtmlController.class) + "Conversion/";
Presentation pres = new Presentation(dataDir+"presentation.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();
}
// 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();
}
Presentation pres = new Presentation(dataDir + "presentation.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(dataDir+ "input-PFDinDisplayPro-Regular-installed.html", SaveFormat.Html, htmlOptionsEmbed);
} finally {
if (pres != null) pres.dispose();
}
// 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);
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();
// 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();
// 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);
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Save the presentation to PDF with specified options
pres.save(dataDir + "demo.pdf", SaveFormat.Pdf, opts);
}
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);
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();
}
// 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.setViewerIncluded(false);
INotesCommentsLayoutingOptions options = swfOptions.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Saving presentation
pres.save(dataDir + "Sample.swf", SaveFormat.Swf, swfOptions);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (pres != null)
pres.dispose();
}
}
// 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);
// 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();
// 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));
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Save the presentation to TIFF with specified image size
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff, opts);
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);
// 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);
// 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);
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertNotesSlideViewToPDF.class);
// Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation(dataDir + "NotesFile.pptx");
PdfOptions pdfOptions = new PdfOptions();
INotesCommentsLayoutingOptions options = pdfOptions.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Save the presentation to PDF
pres.save(dataDir + "Pdf_Notes_out.pdf", SaveFormat.Pdf, pdfOptions);
// The path to the documents directory.
String dataDir = Utils.getDataDir(CovertToPDFWithProgressUpdate.class);
Presentation presentation = new Presentation(dataDir + "ConvertToPDF.pptx");
try
{
ISaveOptions saveOptions = new PdfOptions();
saveOptions.setProgressCallback((IProgressCallback) new ExportProgressHandler());
presentation.save(dataDir + "ConvertToPDF.pdf", SaveFormat.Pdf, saveOptions);
}finally {
presentation.dispose();
}
class ExportProgressHandler implements IProgressCallback {
public void reporting(double progressValue) {
// Use progress percentage value here
}
}
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);
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(ExportToHTMLWithResponsiveLayout.class);
Presentation presentation = new Presentation(dataDir + "SomePresentation.pptx");
HtmlOptions saveOptions = new HtmlOptions();
saveOptions.setSvgResponsiveLayout(true);
presentation.save(dataDir +"SomePresentation-out.html", SaveFormat.Html, saveOptions);
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);
}
}
}
Presentation pres = new Presentation(dataDir + "Presentation.pptx");
try {
HtmlOptions opts = new HtmlOptions();
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Saving notes pages
pres.save(dataDir + "Output.html", SaveFormat.Html,opts);
}
finally {
pres.dispose();
}
// 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);
PdfOptions pdfOptions = new PdfOptions();
INotesCommentsLayoutingOptions options = pdfOptions.getNotesCommentsLayouting();
options.setNotesPosition(NotesPositions.BottomFull);
// Save Presentation to disk
auxPresentation.save(dataDir + "testPDFnotes.pdf", SaveFormat.Pdf,pdfOptions);
Presentation pres = new Presentation(dataDir+"pres.pptx");
try{
final CustomHeaderAndFontsController htmlController = new CustomHeaderAndFontsController("styles.css");
HtmlOptions options = new HtmlOptions(){{
setHtmlFormatter(HtmlFormatter.createCustomFormatter(htmlController));
}};
pres.save(dataDir+"pres.html", SaveFormat.Html, options);
}
finally
{
pres.dispose();
}}}
// 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);
//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation();
//Create a License object
License license = new License();
//Set the license of Aspose.Slides for Java to avoid the evaluation limitations
license.setLicense("Aspose.Slides.lic");
//Adding an empty slide to the presentation and getting the reference of
//that empty slide
Slide slide = pres.addEmptySlide();
//Adding a rectangle (X=2400, Y=1800, Width=1000 & Height=500) to the slide
com.aspose.slides.Rectangle rect = slide.getShapes().addRectangle(2400, 1800, 1000, 500);
//Hiding the lines of rectangle
rect.getLineFormat().setShowLines(false);
//Adding a text frame to the rectangle with "Hello World" as a default text
rect.addTextFrame("Hello World");
//Removing the first slide of the presentation which is always added by
//Aspose.Slides for Java by default while creating the presentation
pres.getSlides().removeAt(0);
//Writing the presentation as a PPT file
pres.write("C:\\hello.ppt");
// 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);
}
// 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);
//Accessing the presentation
String path = "D:\\Aspose Data\\";
//Accessing the presentation
Presentation pres = new Presentation(path + "ExtractImages.pptx");
com.aspose.slides.IPPImage img = null;
com.aspose.slides.IPPImage Backimg = null;
int slideIndex = 0;
String ImageType = "";
boolean ifImageFound = false;
for (int i = 0; i < pres.getSlides().size(); i++)
{
slideIndex++;
//Accessing the first slide
ISlide sl = pres.getSlides().get_Item(i);
//Accessing the first slide Slide sl = pres.getSlideByPosition(i);
if (sl.getBackground().getFillFormat().getFillType() == FillType.Picture)
{
//Getting the back picture
Backimg = sl.getBackground().getFillFormat().getPictureFillFormat().getPicture().getImage();
//Saving picture
BufferedImage image=Backimg.getSystemImage();
ImageType = Backimg.getContentType();
//ImageType = ImageType.s.substring(0, ImageType.indexOf("/") + 1);
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length());
String ImagePath = path + "BackImage_";
try {
ImageIO.write(image,ImageType, new File(ImagePath + "Slide_" + slideIndex+ "." +ImageType.toString()));
//Setting the desired picture format
} catch (IOException ex) {
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex);
}
}
else
{
if (sl.getLayoutSlide().getBackground().getFillFormat().getFillType() == FillType.Picture)
{
//Getting the back picture
Backimg = sl.getLayoutSlide().getBackground().getFillFormat().getPictureFillFormat().getPicture().getImage();
BufferedImage image=Backimg.getSystemImage();
ImageType = Backimg.getContentType();
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length());
String ImagePath = path + "BackImage_";
try {
ImageIO.write(image,ImageType, new File(ImagePath + "LayoutSlide_" + slideIndex+ "." +ImageType.toString()));
//Setting the desired picture format
} catch (IOException ex) {
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
for (int j = 0; j < sl.getShapes().size(); j++)
{
// Accessing the shape with picture
IShape sh = sl.getShapes().get_Item(j);
if (sh instanceof IAutoShape)
{
IAutoShape ashp = (IAutoShape)sh;
if (ashp.getFillFormat().getFillType() == FillType.Picture)
{
img = ashp.getFillFormat().getPictureFillFormat().getPicture().getImage();
ImageType = img.getContentType();
ImageType = ImageType.substring(0, ImageType.indexOf("/") + 1);
ifImageFound = true;
}
}
else if (sh instanceof IPictureFrame)
{
IPictureFrame pf = (IPictureFrame)sh;
// if (pf.getFillFormat().getFillType() == FillType.Picture)
{
img = pf.getPictureFormat().getPicture().getImage();
ImageType = img.getContentType();
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length());
ifImageFound = true;
}
}
//
//Setting the desired picture format
if (ifImageFound)
{
//Format = GetImageFormat(ImageType);
String ImagePath = path + "Slides\\Image_";
try {
ImageIO.write(img.getSystemImage(),ImageType, new File(ImagePath + "Slide_" + slideIndex + "_Shape_" + j + "." + ImageType));
} catch (IOException ex) {
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex);
}
}
ifImageFound = false;
}
}
try {
//Instantiate the presentation
Presentation presentation = new Presentation("presentation.pptx");
//The first method
File file = new File("image1.png");
byte[]data = new byte[(int) file.length()];
InputStream inputStream = null;
try
{
inputStream = new FileInputStream(file);
inputStream.read(data);
}
finally
{
inputStream.close();
}
IPPImage oldImage = presentation.getImages().get_Item(0);
oldImage.replaceImage(data);
//The second method
BufferedImage newImage = ImageIO.read(new File("image0.jpeg"));
IPPImage imageToReplace= presentation.getImages().addImage(newImage);
oldImage = presentation.getImages().get_Item(1);
oldImage.replaceImage(imageToReplace);
//The third method
oldImage = presentation.getImages().get_Item(2);
oldImage.replaceImage(presentation.getImages().get_Item(3));
//Save the presentation
presentation.save("presentation_out.pptx", SaveFormat.Pptx);
} catch (Exception e) {
}
//Set the picture
IPPImage imgx=null;
try{
imgx = pres.getImages().addImage(new FileInputStream(new File( "aspose1.jpg")));
}
catch(IOException e){}
//Assigning the picture Id of newly added picture to the Picture Id of
//OleObjectFrame where oof represents an OleObjectFrame
oof.getSubstitutePictureFormat().getPicture().setImage(imgx);
// 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();
// The path to the documents directory.
String dataDir = Utils.getDataDir(DetectionMicrosoftPowerPoint95presentations.class);
String path = dataDir +"PowerPoint95.ppt";
//Code snippet to check whether the presentation format is old Microsoft PowerPoint 95
boolean isOldFormat = PresentationFactory.getInstance().getPresentationInfo(path).getLoadFormat() == LoadFormat.Ppt95;
class ImageLoadingHandler implements IResourceLoadingCallback {
public int resourceLoading(IResourceLoadingArgs args) {
if (args.getOriginalUri().endsWith(".jpg")) {
try // load substitute image
{
// The path to the documents directory.
String dataDir = Utils.getDataDir(LoadPresentation.class);
byte[] imageBytes = java.nio.file.Files.readAllBytes(new File(dataDir + "aspose-logo.jpg").toPath());
args.setData(imageBytes);
return ResourceLoadingAction.UserProvided;
} catch (RuntimeException ex) {
return ResourceLoadingAction.Skip;
} catch (IOException ex) {
Logger.getLogger(ImageLoadingHandler.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (args.getOriginalUri().endsWith(".png")) {
// set substitute url
args.setUri("http://www.google.com/images/logos/ps_logo2.png");
return ResourceLoadingAction.Default;
}
// skip all other images
return ResourceLoadingAction.Skip;
}
}
// The path to the documents directory.
String dataDir = Utils.getDataDir(LoadPresentation.class);
LoadOptions opts = new LoadOptions();
opts.setResourceLoadingCallback(new ImageLoadingHandler());
Presentation presentation = new Presentation(dataDir + "presentation.pptx", opts);
// 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());
// 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());
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();
}
// 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
// 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);
// 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());
// The path to the documents directory.
String dataDir = Utils.getDataDir(AccessLayoutFormats.class);
Presentation pres = new Presentation(dataDir + "pres.pptx");
for (ILayoutSlide layoutSlide : pres.getLayoutSlides())
{
IFillFormat[] fillFormats = new IFillFormat[layoutSlide.getShapes().size()];
int i =0;
for (IShape shape : layoutSlide.getShapes()){
fillFormats[i] = shape.getFillFormat();
i++;
}
ILineFormat[] lineFormats = new ILineFormat[layoutSlide.getShapes().size()];
int j =0;
for (IShape shape : layoutSlide.getShapes()){
lineFormats[j] = shape.getLineFormat();
j++;
}
}
// 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();
}
}
}
// 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);
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);
}
// 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();
System.out.println("Application Name: " + app);
System.out.println("Application Version: " + ver);
// 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);
}
// 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();
}
// 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);
String dataDir = Utils.getDataDir(SupportForAddingEMZFilesIntoImagesCollection.class);
String imagePath= dataDir + "2.emz";
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();
}
final InterruptionTokenSource tokenSource = new InterruptionTokenSource();
Runnable interruption = new Runnable() {
public void run() {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setInterruptionToken(tokenSource.getToken());
String dataDir = Utils.getDataDir(SupportForInterrupt.class);
Presentation pres = new Presentation(dataDir +"pres.pptx", loadOptions);
try{
pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720));
pres.save(dataDir +"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();
// 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");
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);
}
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);
}