Re:-Multiple image render by creating new slides

Hi,

I have written the below code to add multiple slides and render the image to their background from the server.
when i execute the code i do get an error "Read error".can you please help me on this,if possible can i get a piece of code which helps in redering multiple images
by creating new slides.

int count=Integer.parseInt(session.getAttribute("counter").toString());

String serFilePath=session.getAttribute("filePath").toString();

String[] filesToppt = new String[count];

//store files in string
for(int i = 0; i < (count); i++)
{
filesToppt[i] = serFilePath + (i + 1) + "temp.png";
}


for (int i = 0; i < filesToppt.length; i++)
{
pres = new Presentation(source);
// Slide slide = pres.getSlideByPosition(1);
Slide slide = pres.addEmptySlide();
slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(FillType.PICTURE);
InputStream iStream = new BufferedInputStream(new FileInputStream(filesToppt[i]));
Picture pic = new com.aspose.slides.Picture(pres, iStream);
int picId = pres.getPictures().add(pic);
slide.getBackground().getFillFormat().setPictureId(picId);


pres.write(destination);
source.close();
destination.close();

}

String servletPath = request.getRequestURL().toString();
pos = servletPath.lastIndexOf("/");
String pptDemoPath = servletPath.substring(0, pos) + "/" + "demo_new.ppt";

ServletOutputStream out = response.getOutputStream();

response.setContentType("application/vnd.ms-powerpoint");
response.addHeader("Content-Disposition", "attachment; filename=demo_new.ppt");

BufferedInputStream bis = null;
BufferedOutputStream bos = null;

URL url = new URL(pptDemoPath);

// Use Buffered Stream for reading/writing.
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);

byte[] buff = new byte[2048];
int bytesRead;

// Simple read/write loop.
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
Thanks&regards,

Rajesh

Hi Rajesh,

Thanks for your interest in Aspose.Slide.

Please visit documentation of Aspose.Slides for
Setting the Background to an Image. Please let us know If you still face any problem after using this documentation code.

Hi Rajesh,

I have checked your code in detail and found that your code seems correct. I will use your code and will send you a sample code snippet with modifications soon.

We apologize for your inconvenience.

Hi Rajesh,

The code related to Aspose.Slides works fine. Your code in for loop is correct. I have used the following code to set background of slide with image.

com.aspose.slides.Slide slide = pres.addEmptySlide();
slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(com.aspose.slides.FillType.PICTURE);
java.io.InputStream iStream = new java.io.BufferedInputStream(new java.io.FileInputStream(filesToppt[i]));
com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, iStream);
int picId = pres.getPictures().add(pic);
slide.getBackground().getFillFormat().setPictureId(picId);
pres.write(“d:\test.ppt”);

Hi Tahir,

Thanks,for the quick update.Now the code works but out of many images being fetched from the server only 1 image is getting rendered.So,can u plz suggest me any modified code which would help render all the images

Thanks&regards,

Rajesh

Adding more information,as seen from the code a new slide would be created with setting different images in their background,but for my case only one slide and one image is rendered.

Hi Rajesh,

I have tried to understand the problem specified by you but unfortunately, I am not able to completely understand your problem statement. Please share some more details about your issue.

let me explain my requirement first.I do have many jpg images in my server,i want all of them to be rendered into ppt in diferent slides for which i have written the above code,but instead of all getting rendered all the images only 1 slide is created and only 1 image is rendered.

But i need new slides to be created for different images.

-Rajesh

Hi Rajesh,

I am working on your issue and will update you soon about your issue.

We apologize for your inconvenience.

Hi Rajesh,

Please use the following code snippet to add background in slides.

String[] filesToppt = new String[4];

filesToppt[0] = “D:\pics\Chrysanthemum.jpg”;
filesToppt[1] = “D:\pics\Desert.jpg”;
filesToppt[2] = “D:\pics\Hydrangeas.jpg”;
filesToppt[3] = “D:\pics\Jellyfish.jpg”;

Presentation pres = new Presentation(“d:\demo.ppt”);

for (int i = 0; i < filesToppt.length; i++)
{
com.aspose.slides.Slide slide = pres.addEmptySlide();
slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(com.aspose.slides.FillType.PICTURE);
java.io.InputStream iStream = new java.io.BufferedInputStream(new java.io.FileInputStream(filesToppt[i]));
com.aspose.slides.Picture pic = new com.aspose.slides.Picture(pres, iStream);
int picId = pres.getPictures().add(pic);
slide.getBackground().getFillFormat().setPictureId(picId);
}
pres.getSlides().removeAt(0);
pres.save(“D:\demo-out.ppt”, SaveFormat.PPT);
Hope this answers your query.