Out Of Memory Error Converting PowerPoint 2010 to PDF

We have a fully licensed Aspose Total for Java software suite and we are using Aspose.Slides version 14.8.0.



The PowerPoint file does have 90+ slides with embedded images, spreadsheets, and uses slide animations and speaker notes, however the total file size is only 4.2MB prior to conversion.



Are there size limits and/or features in PowerPoint 2010 which Aspose.Slides 14.8.0 does not support?



Are there options which can be set to ignore PowerPoint 2010 features during conversion to PDF?



Any assistance would be greatly appreciated.



Here are the Steps Taken when the Error was encountered:



1) Instantiate a Presentation object that represents a presentation with an absolute path and filename.

2) Instantiate the PdfOptions class

3) Set Jpeg quality

4) Define behavior of metafiles

5) Define the PDF standard as PdfCompliance.Pdf15

6) Set password protect = false

7) Use custom options when saving the presentation object as PDF

8) Delete temporary file used during conversion



Here is the trace for the ERROR Encountered:

canBeConverted(): Powerpoint to PDF conversion will FAIL (format is supported, but OUT-OF-MEMORY problem encountered)

java.lang.OutOfMemoryError: allocLargeObjectOrArray - Object size: 24963920, Num elements: 6240976

at com.aspose.slides.pa5e0ff62.pbdb106a0.p6a2feef8.pa2137a2a.a.(Unknown Source)

at com.aspose.slides.pa5e0ff62.pf4dd765c.pa5e0ff62.pa2137a2a.a.do(Unknown Source)

at com.aspose.slides.pa5e0ff62.pf4dd765c.pa5e0ff62.pf4dd765c.b.do(Unknown Source)

at com.aspose.slides.pa5e0ff62.pbdb106a0.p6a2feef8.b.do(Unknown Source)

at com.aspose.slides.pa5e0ff62.pbdb106a0.p6a2feef8.b.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p883e881b.a.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.p2cbca448.a.if(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.p2cbca448.a.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.p2cbca448.a.for(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.p2cbca448.a.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.ar.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.ar.if(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.al.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.m.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.s.do(Unknown Source)

at com.aspose.slides.p6a2feef8.p390e9825.p6a2feef8.an.do(Unknown Source)

at com.aspose.slides.ass.if(Unknown Source)

at com.aspose.slides.Presentation.do(Unknown Source)

at com.aspose.slides.Presentation.save(Unknown Source)

at validation.AsposeSlides.canBeConverted(AsposeSlides.java:417)

at comment_book_support.SortSupportingDocuments.filterRES_SUPPORTING_DOCS(SortSupportingDocuments.java:900)



Here is a SNIPPET of the JAVA CODE Used:

protected boolean passwordProtect = false;

protected boolean useDefaultOptions = false;



public boolean canBeConverted(String fileName, String dataDir) {

String newFile = fileName.substring(0, fileName.lastIndexOf(".")) + “.pdf”;

Presentation presentation = null;

boolean canBeConverted = false;



try {

@Cleanup File myFile = File.createTempFile(newFile.substring(0, newFile.lastIndexOf(".")), “.pdf”);

@Cleanup BufferedOutputStream out = null;



try {

// Instantiate a Presentation Object that represents a presentation file

presentation = new Presentation(dataDir + fileName);



// Instantiate the PdfOptions Class for save options

PdfOptions options = new PdfOptions();



// Set Jpeg quality

options.setJpegQuality((byte) 90);



// Define behavior of metafiles

options.setSaveMetaFilesAsPng(true);



// Set Text compression level

options.setTextCompression (PdfTextCompression.Flates);



// Define the PDF standard (ex. pdf15 or PdfA1)

options.setCompliance(PdfCompliance.Pdf15);



// Save the presentation and decide whether to password protect

if (passwordProtect) options.setPassword(“password”);



try {

out = new BufferedOutputStream(new FileOutputStream(myFile));



if (useDefaultOptions) {

// Save the presentation to PDF using default options

presentation.save(out, SaveFormat.Pdf);

}// end if

else {

// Save the presentation to PDF with specified (custom) options

presentation.save(out, SaveFormat.Pdf, options);

}// end else

}// end try

finally {

if (out != null) out.close();

myFile.delete();

}// end finally



canBeConverted = true;



}// end try

catch (OutOfMemoryError err) {

// Print message

err.printStackTrace(System.out);

if (presentation != null) presentation.dispose();

myFile.delete();

canBeConverted = false;

}// end catch

}// end try

catch (Exception e) {

e.printStackTrace(System.out);

if (presentation != null) presentation.dispose();

canBeConverted = false;

}// end catch

finally {

if (presentation != null) presentation.dispose();

}// end finally



return canBeConverted;

}// end canBeConverted



Thanks.

Ed

Hi Edwin,


I have observed the requirements shared by you and like to share that there is no option to enable or disable features in exported PDF using Aspose.Slides. Whatever is available in presentation will get exported to PDF. At present the 3D effects and Shadows are not supported in Aspose.Slides. As far as the issue of exception is concerned, I request you to please try using Aspose.Slides for Java 14.9.0 on your end. If there is still an issue then please share the sample presentation with us and I will investigate the issue further on my end. Also, for OutOf Memory exception issues, you need to increase the stack size as well.

Many Thanks,

Mudassir,



Thank you for responding. As suggested, I downloaded Aspose.Slides 14.9.0 and increased my JVM heap size



(-Xms1024 -Xmx1024m -XX:MaxPermSize=256m)



but still encounter the OUT-OF-MEMORY exception. I will admit that it took longer and I monitored my resource usage on my server.



Sharing the PowerPoint presentation which is causing this exception is not an option. I am contemplating a manual process to try and determine which slide is causing the problem or what the Presentation object limitations actually are. I am considering after creating the Presentation object and getting the ISlidesCollection, saving each individual slide to a separate Presentation and then converting each to PDF. After converting each individual slide, merging them back into a single PDF. Essentially, this is what the Presentation.save() should be performing. I am open to any other suggestions and/or recommendations.



Thanks.

Ed

Hi ED,

I have observed the comments shared by you and like to share that setting heap size is dependent on presentation that you are using. If you want to save the presentation slides individually to PDF, it will work as it will reduce the memory consumption and thus avoiding the OutOfMemory exception. The solution is to increase the heap size further. Also, Aspose.Slides now offers to generate the PDF file per page. Please try using the sample code share over this documentation link as well for reference.

Many Thanks,

So I increased my heap size to -Xms2048 -Xmx2048 -XX:MaxPermSize=512m and still get the OUT-OF-MEMORY error.



I also created functionality to convert each individual slide to an individual PDF and then concatenate all of the individual PDFs into a single PDF. For the most part this works except when the slide contains an embedded image (non Clip Art), an embedded XLSX worksheet, or an embedded PDF. When the exception is thrown, I try to gracefully generate an error PDF as a place-holder. Even using this logic and increased heap size, the application throws an OUT-OF-MEMORY exception and then aborts execution.



It’s interesting that if I open the original 70 slide PPTX and use Adobe to create a PDF, I don’t have any issues.



What am I missing? Do the slides containing the embedded objects need to be flattened, or can the troublesome objects be detected and/or ignored?



Here are the methods I am using:



public void convertPowerpoint2PDF(Presentation presentation) {

Vector filesToConcatenate = new Vector();



try {

int i = 0;

try {

ISlidesCollection slidesCollection = presentation.getSlides();

int numSlides = slidesCollection.size();

int[] slides = null;

int[] badSlides = null;



for (i = 1; i
// Setting array of slides positions

sldies = new int[] { i };

try {

// Save the presentation to PDF

presentation.save(“C:/Temp/demo_”+i+".pdf", slides, SaveFormat.Pdf);

}// end try

catch (OutOfMemoryError err) {

try {

badSlides = new int[] { 1 };

Presentation badPresentation = new Presentation(“C:/Temp/BAD Slide PDF.pptx”);

// Save the presentation to PDF

badPresentation.save(“C:/Temp/demo_”+i+".pdf", badSlides, SaveFormat.Pdf);

if (badPresntation != null) badPresentation.dispose();

}// end try

catch (Exception e) {

if (presentation != null) presentation.dispose();

e.printStackTrace(System.out);

}// end catch

// err.printStackTrace(System.out);

}// end catch

catch (Exception e) { e.printStackTrace(System.out); }// end catch



filesToConcatenate.addElement(“demo_”+i+".pdf");



}// end for loop

concatenatePDFs(filesToConcatenate, “test_consolidated.pdf”, “C:/Temp/”);

}// end try

finally { ; }// end finally

}// end try

catch (Exception e) { e.printStackTrace(System.out); }// end catch

finally ( if (presentation != null) presentation.dispose(); }// end finally

}// end convertPowerpoint2PDF



public void concatenatePDFs(Vector filesToConcatenate, String destinationPDF, String dataDir) {

String sourcePDF = “”;

try {

// Open the destination document

com.aspose.pdf.Document pdfDestination = new com.aspose.pdf.Document(dataDir + destinationPDF);



for (int i = 0; i < filesToConcatenate.size(); i++) {

sourcePDF = (String) filesToConcatenate.elementAt(i);



// open source document

com.aspose.pdf.Document pdfSource = new com.aspose.pdf.Document(dataDir + sourcePDF);



// add the page(s) of the source document to the destination document

pdfDestination.getPages().add(pdfSource.getPages());

}// end for loop



// Save the concatenated output file (the destination document)

pdfDestination.save(dataDir + destinationPDF);



// free resources

if (pdfSource != null) pdfSource.dispose();

if (pdfDestination != null) pdfDestination.dispose();

}// end try

catch (Exception e) { e.printStackTrace(System.out); }// end catch

}// end concatenatePDFs



Thanks.

Ed

Hi Ed,


Thanks for sharing your further feedback. I have observed the facts shared by you and request you to please share the sample presentation causing issue on your end. Without presentation unfortunately, it will not be possible to help you further in this regard as we need to investigate the root cause of the issue to help you further. Secondly, you can also share the presentation file privately with us by following these guidelines as well. Please share the requested information with us so that we may proceed further to help you out.

Many Thanks,

Mudassir,



As I mentioned in a previous post, that is not an option. Perhaps I can make a similar presentation. I did observe that most of the slides that fail have embedded XLSX spreadsheets. Upon further examination of the spreadsheets themselves, they appear to have values in columns not displayed on the slide.



Thanks.

Ed

Mudassir,

I created a sample presentation (see attached Demo_Presentation.zip), using MS Powerpoint 2010, which contains only four slides. Three of the slides throw the OUT-OF-MEMORY error. Slides 1, 3, and 4 throw the exception while Slide 3 is converted without the embedded PDF object (essentially a blank slide).

Slides 1 & 2 contain embedded PDFs inserted as an Adobe Acrobat Document.

Slides 3 & 4 contain embedded XLSX spreadsheets inserted as Microsoft Excel Worksheet. The data was entered by double-clicking the XLSX object.

All of the slides use a customized theme and all utilize the Fade transition.

Thanks.
Ed

Hi Ed,


I have worked with the presentation file shared by you by using sample code shared by you in a simple console application. I have not been able to reproduce the issue on my end. For your kind reference, I have also attached the generated PDF. I also request you to please try exporting to PDF using normal console application. I have used Windows 7 x64 with 8 Gb Ram and Core I7 2.6 Ghz machine.

Please share, if I may help you further in this regard.

Many Thanks,

Mudassir,

I have been testing execution of my code from my workstation. As mentioned earlier in my post, I was able to generate the PDF using standard Adobe software and thought that was a little strange that Adobe works fine and does not use system resources like Aspose.Slides apparently can.

I too am running 64-bit Windows 7 Enterprise with Service Pack 1. I have an AMD Athlon II processor running at 3.40 GHz but only 4GB RAM.

Thanks.
Ed

Hi Ed,


Thank you for sharing the details with us but I like to add here that one cannot compare Adobe Acrobat with Aspose.Slides. There is difference of implementation. As shared earlier, when working with Aspose.Slides, it loads all the presentation inside DOM and reside that in memory. Even 4 Mb presentation will take more place in memory as in DOM of presentation the loaded XML presentation values are set for different class variables.

We really wish to help you and resolve the issue on your end but need to reproduce the issue on our end as well. With the last presentation shared, I have not been able to reproduce that on my end and I have shared the generated PDF as well. I can suggest you to please try creating a simple application for exporting to PDF from scratch and test that on some other machine on your end. All you need to do is to load presentation from file and save that as PDF file on your disk.

Many Thanks,

Mudassir,

I have re-written my process to no avail. Perhaps you could share the exact code you used to test? Although you said you were using my sample, I suspect to make it work on your machine you had to tweek a little. You especially had to create an execution shell (main). Perhaps I’m overlooking something very simple.

I was mistaken thinking the file was an Office 2010 pptx. It is actually an Office 2007 pptx. I know this because prior to trying Aspose.Slides, I had written functionality to convert Office Documents to PDF using OpenOffice. Just to see what would happen, I used this functionality to convert the troublesome presentation. Knowing that my version of OpenOffice does not support Office 2010 documents, I fully expected the conversion to fail. To my surprise, it did not. In-fact, the entire document converted with no exceptions caught.

Earlier in this post you recommended increasing my Java heap size which I did on our server. I am curious what are your heap size settings. In addition, you mentioned that the entire presentation object is loaded into memory as a single XML document. I’m curious if there is a formula for estimating/calculating the footprint (amount of memory) this XML document would take based upon the original file size?

Thanks.
Ed

Hi ED,

I have created a sample Net Beans application on my end that I have tested on two machine with Core I7 processor and 8 GB Ram. I have tested using JDK1.6_45 on my end on second machine. The sample application is available for download over this download link:
https://www.dropbox.com/s/pf8rpum1nejn0kx/SampleApp.rar?dl=0
I have used the same code that has been shared by you in your very first post. Also, I have attached the snapshot for maximum memory consumption during PDF export as well. I hope this will be helpful to you. All you need to do now is to set the paths in application as per your machine and test it. I also suggest you to please try using a fresh installation or some new machine to verify the fact. I am using the default heap size that is set be application and have not increased that even.

The generated PDF is also attached for your kind reference as well.

Many Thanks,