Cannot export to ppt using MS Powerpoint-only opens with Open Office

Hi,

I am not able to use Aspose slides with MS powerpoint,it well works fine with Open Office.Attached is the sample working code.Can any body provide me the complete code where i can render an image which resides in my server to Aspose Slides using java servlets.

Please do help me atleast in Modifying the attached code.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpSession;
import com.alphablox.blox.repository.Log;
import com.alphablox.blox.ChartBlox;
import com.alphablox.blox.PresentBlox;
import com.alphablox.blox.uimodel.PresentBloxModel;
import com.alphablox.blox.uimodel.core.Static;
import com.alphablox.server.Server;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.awt.Color;

import com.aspose.slides.*;

import java.net.URL;

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

Hi Rajesh,

Thanks for your interest in Aspose.Slides.

I have tried to understand the code shared by you. The portion where you are adding the image in presentation is fine and it does not seem to have any issue. However, I am not able to execute the code shared. Please share the exact issue that you are facing and it will be really nice if you may please share some working code that can work in our environment as well. Please also share the source and generated output for reference as well.

Thanks and Regards,

Hi Mudassir,

Thanks,for taking time in reviewing my code.The above error reported by me is fixed and i am able to export to ppt now both in MS powerpoint and Open Office.

Last,but not the least i just wanted to know that since iam using the apose jars in my workspace and even i am planning to get a licencse for it but just wanted to know how to enable to full version once i get the license,can you [please provide me the exact code which i need to execute to make this full version and is it necesarry to call the license code every time i run the previous code posted earlier.

Please,share your comments on this.

Thanks&Regards,

Rajesh

Hi Rajesh,

There is no difference between the evolutionary version and licensed version in terms of functionality. Only the watermark will be available in case of evolutionary version. Please visit this link for information about setting the license.

Thanks and Regards,

Hi Rajesh,

Thanks for sharing the information about the Recovery PowerPoint. Please let us know if there is any thing that we may provide help to you.

Thanks and Regards,