Hi,
I have a scenario where my input stream can be a ppt, email, excel, doc, jpg … practically anything.
For example, lets stick to slides. I have a file which will be a PPT of 30 slides, I get a inputstream which has a particular slide data and I need to create a slide with that content in aspose , do this for all 30 slides, at the end convert the entire Presentation object to a PDF.
I am following the below way. This seems to be slow. Can you suggest a better way ?
Also, I could not figure out creating only slides and adding content to it from inputstream , hence I am creating presentation object always. Ideally, I would want to create one presentation object and add multiple slides to the same and add content to it from inputstream (which will have each slide’s data)
Note : I am aware of converting the entire PPT to a PDF once , but I need to do it page by page.
Sample file uploaded1005_Construction_Site_Induction.7z (12.3 KB)
Code:
int numPages = book.getNumberOfPages(); (say 15)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int pageId = 0; pageId < numPages; pageId++)
{
Printable page = book.getPrintable(pageId);
jiPrintablePage currentPage = (jiPrintablePage) page;
InputStream currentInputStream =
currentPage.document.currentLocalFile(pageId).getInputStream(); //each page inputstream
//ideally want to add only to slide and not create a new presentation always
Presentation presentation = new Presentation(currentInputStream);
//save the current slide presentation to the output stream in PDF format. keep adding to output stream for all pages
presentation.save(baos,com.aspose.slides.SaveFormat.Pdf);
}
//Finally write to a document from the output stream as PDF(which will be entire PPT as PDF)
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(baos.toByteArray());
pdfDocument.save("C:/temp/ImagetoPDF.pdf");
return pdfDocument;
@sushma1509,
Thank you for contacting support. If I understand correctly, you have input data in many formats, and you want to get a PDF document at the end. I think you should not use PowerPoint presentations as intermediate containers.
My colleagues from the Aspose.Pdf team will help you achieve your goals soon.
This will be inputstream of a particular slide.
I basically need to know if I can add inputstream to a slide object instead of creating new Presentation for each slide.
Regarding Aspose.Cells to render Excel spreadsheets to PDF, you cannot add InputStream to Worksheet object as we have to create the whole Workbook into our object model first. By the way, do you find any issue with rendering Excel spreadsheet to PDF, any performance issue? If so, kindly do provide complete details with your sample file(s) and sample code to reproduce the issue. We will check your issue soon.
So you are saying, using aspose slides package, if I have to convert 10 slides to 10 pdfs, I need to create 10 presentation objects ?
Is my code sample correct below for the use case?
for (int i = 0; i < 10; i++)
{
Presentation presentation = new Presentation(currentSlideInputStream);
presentation.save("C:/temp/output.pdf")
}
I have not found any performance issue, I just wanted to confirm, since I felt creating multiple presentation objects would be heavier. Instead, if I could create one presentation and only multiple slides it would be lighter.
Also, I will be creating 10 output PDFs , ideally all of them belong to a single file. So now I have to write to an outputstream and then write to PDF. Like below:
for (int i = 0; i < 10; i++)
{
Presentation presentation = new Presentation(currentSlideInputStream);
presentation.save(baos, com.aspose.slides.SaveFormat.Pdf);
}
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(baos.toByteArray());
pdfDocument.save("C:/temp/ImagetoPDF.pdf");
Aspose.Slides allows you to load a presentation from a file or InputStream object, and both must present data in PowerPoint document format (PPT/PPTX, PPS/PPSX, еtс.) or OpenDocument Presentation format (ODP, OTP). If you explain what data structure/format is presented in the currentSlideInputStream, we will consider implementing a feature to append the slide to a presentation created before.