Free Support Forum - aspose.com

Export doesnot render images on ppt

Hi,

Is there a bug in Aspose 2.4.2 java,as sometimes it renders the reports to ppt and some times i do get an empty slide.i do image rendering to ppt slides from my server.

Below is the code i have used:-

public class PptServlet extends HttpServlet {

public void destroy () {
super.destroy ();
}


//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session = request.getSession();
Presentation pres;
FileInputStream source = null;
FileOutputStream destination = null;
PrintStream dataOut = null;
DataInputStream dataIn;

try
{
// Log.sendMessage(Log.MESSAGE_LEVEL_DEBUG, "inside try", " ");
//determine title of image
PresentBlox pb = null;
if (request.getParameter("batch") != null)
{
String batch = (String) request.getParameter("batch");
if (batch.equalsIgnoreCase("TRUE"))
{
pb = (PresentBlox) session.getAttribute("batchReportBlox");
}
else
{
pb = (PresentBlox) session.getAttribute("mainReportBlox");
}
}
else
{
pb = (PresentBlox) session.getAttribute("mainReportBlox");
}
ChartBlox chart = pb.getChartBlox();
String oldTitle = chart.getTitle();
PresentBloxModel model = pb.getPresentBloxModel();
Static titleBlox = (Static) model.searchForComponent("customTitle");

if (titleBlox != null)
{
chart.setTitle(titleBlox.getTitle() + "\\n" + oldTitle);
}

//create temp file
String timeStamp = new java.util.Date().getTime() + "";
String filePath = Server.getServer().getRepositoryRoot() + "temp" + File.separatorChar + session.getId() + File.separatorChar;
String fileName = filePath + timeStamp + "temp";

try
{
chart.writeChartToFile(fileName, 800, 600, com.alphablox.blox.form.FormBlox.RENDER_DHTML);
fileName += ".png";
}
catch (Exception e)
{

String pathFrom = Server.getServer().getRepositoryRoot() + File.separatorChar + "temp.png";
fileName += ".png";
String pathTo = fileName;
copy(pathFrom, pathTo);
}

ServletContext context = request.getSession().getServletContext();
String realContextPath = context.getRealPath(request.getContextPath());

int pos = realContextPath.lastIndexOf("\\");
realContextPath = realContextPath.substring(0, pos);

String pptPath = realContextPath + "\\" + "demo.ppt";
String destPath = realContextPath + "\\" + "demo_new.ppt";

Log.sendMessage(Log.MESSAGE_LEVEL_DEBUG, "pptServlet.java", "pptPath: " + pptPath);

source = new FileInputStream(pptPath);
destination = new FileOutputStream(destPath);

pres = new Presentation(source);
Slide slide = pres.getSlideByPosition(1);
slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(FillType.PICTURE);
InputStream iStream = new BufferedInputStream(new FileInputStream(fileName));
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);
}

bis.close();
bos.flush();
bos.close();

response.flushBuffer();

}
catch (Exception e)
{
Log.sendMessage(Log.MESSAGE_LEVEL_DEBUG, "pptServlet.java", "Exception: " + e.getMessage().toString());
}

}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request,response);

}

private void copy(String src, String dst) throws IOException
{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
in.close();
out.close();
}
public void init (ServletConfig config) throws ServletException

{
System.out.println("hi init");
super.init(config);
System.out.println("hi init");

}

}

Thanks&regards,

Rajesh

Please suggest............

Thanks&regards,

Rajesh

Hi Rajesh,

Thanks for your interest in Aspose.Slides.

I have tried to understand your problem statement but unfortunately I have not completely understand your issue. Please explain your problem in detail. We are really keen to help you but need some more information from your side.
Please check your issue with latest version of Aspose.Slides for Java 2.6.0.2 and let me know if you still face any issue.

Hi ,

What i meean to say is when i have the same code run on the server and try for the exports,what happens is when i get the Dialog box to save the exported ppt in my local i find the images rendered in the slides as expected but some times i do get an empty slide with none of my exported images.

So,just wanted to confirm whether its an bug with the code i had send in my post or its related something to Aspose 2.4.2 version.My client does have an license for Aspose 2.4.2 but not 2.6.2

Please advise.

Thanks&Regards,

Rajesh

Hi Rajesh,

I have used the following code related to Aspose.Slides from your code and it works fine with Aspose.Slides 2.4.2. Please find the generated ppt file in attachment.

String pptPath = “c:/demo.ppt”;
String destPath = “c:/demo_new.ppt”;

FileInputStream source = new FileInputStream(pptPath);
FileOutputStream destination = new FileOutputStream(destPath);

Presentation pres = new Presentation(source);
Slide slide = pres.getSlideByPosition(1);
slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(FillType.PICTURE);
InputStream iStream = new BufferedInputStream(new FileInputStream(“c:/Chrysanthemum.jpg”));
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();

Hi,

Thats true even i do get the image rendered on the ppt,but as said after some continuous exports i do get an empty slide with no images.

Thanks&Regards,

Rajesh

Hi Rajesh,

I have tested Aspose.Slides for Java 2.4.2 with shared code many times and it works fine. Please check following line of code, I think there may be null value is saving in
iStream variable so PPT file with empty slide is creating.

InputStream iStream = new BufferedInputStream(new FileInputStream(fileName));