Create Different Pages across Mimetypes Using InputStream

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.

Hi @andrey.potapov

No, i will have multiple mime types as input to convert to pdf. One such example is a ppt.

i have to convert a ppt of say n number of slides to a pdf, but i have to do it per slide. I do not want to convert entire ppt to a pdf at once.

similarly i will have a word doc of n pages which i need to convert to a pdf document and so on.

But with this post, i want to understand how can I convert each slide to a pdf in a n number slides ppt.

Hi ,
Can I please get an update on this ?

@sushma1509,
Thank you for the additional information.

Could you please clarify what exactly the currentInputStream contains?

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.

@sushma1509,

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.

Hi @amjad.sahi
Thank you for the response.

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");

@sushma1509,

I have given details about Aspose.Cells API only.

@andrey.potapov will assist you regarding Aspose.Slides API.

@sushma1509,

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.

@andrey.potapov
I have two questions here:

  1. There is no way as of now to load input stream containing ppt format to a ISlide object? It has to be a Presentation only?

  2. Is there a possibility to expose an API to accept java. awt.printable object or java.awt.print.PageFormat object as input?

@sushma1509,
Thank you for posting the questions. I will get back to you as soon as possible.

@sushma1509,

Yes, it has to be a presentation only.

Unfortunately no, such objects cannot be used as input data.