Forum at OOoForum.orgThe Forum
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Java Servlet : upload and converter un ppt to pdf

Post new topic   Reply to topic Forum Index -> Macros and API
View previous topic :: View next topic  
Author Message

Joined: 18 Jan 2012
Posts: 1

PostPosted: Wed Jan 18, 2012 4:34 pm    Post subject: Java Servlet : upload and converter un ppt to pdf Reply with quote

To upload and convert a ppt to pdf i use this servlet

package servlet;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;

import session.BeanSessionFichierRemote;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

import entity.Fichier;
import entity.User;

 * Servlet implementation class ajout
public class ajout extends HttpServlet {
   private static final long serialVersionUID = 1L;

    * @see HttpServlet#HttpServlet()
   public ajout() {


    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
    *      response)
   protected void doGet(HttpServletRequest request,
         HttpServletResponse response) throws ServletException, IOException {

      doPost(request, response);

    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
    *      response)
   protected void doPost(HttpServletRequest request,
         HttpServletResponse response) throws ServletException, IOException {

      String nom = null, login = null ,chemin=null;

      // upload image
      boolean isMultipart = FileUpload.isMultipartContent(request);
      if (!isMultipart) {
         request.setAttribute("msg", "Request was not multipart!");
         request.getRequestDispatcher("msg.jsp").forward(request, response);

      DiskFileUpload upload = new DiskFileUpload();
      List items = null;
      try {
         items = upload.parseRequest(request);
      } catch (FileUploadException e) {
         // TODO Auto-generated catch block
      Iterator itr = items.iterator();

      while (itr.hasNext()) {
         FileItem item = (FileItem);
         if (item.isFormField()) {
            String fieldName = item.getFieldName();
            if (fieldName.equals("nom"))
               nom = item.getString();

            if (fieldName.equals("login"))
               login = item.getString();


         else {

            File fullFile = new File(item.getName());
            String ch=System.getenv("user.home"+"/projet_pad/MyProj/Library/");
            File savedFile = new File("C:\\Users\\Administrateur\\projet_pad\\webs\\WebContent\\PptFile", fullFile.getName());
            chemin = fullFile.getName();
            try {
            } catch (Exception e) {
               // TODO Auto-generated catch block
      //**********************Ajout dans la base de donnée*************************************************************//
      Hashtable<String, String> h = new Hashtable<String, String>();
      h.put("java.naming.provider.url", "rmi://localhost:1099");
      h.put("java.naming.factory.url.pkgs", "org.objectweb.jonas.naming");
      Context ctx;
      try {
         ctx = new InitialContext(h);
         String JNDI_NAME = "session.BeanSessionFichier" + "_"
               + BeanSessionFichierRemote.class.getName() + "@Remote";
         BeanSessionFichierRemote ref = (BeanSessionFichierRemote) ctx
         User u=new User();
         Fichier f=new Fichier();

      } catch (NamingException e) {

      System.out.println("le nom de slide est :" + chemin);
      // String newm = nom.substring(nom.lastIndexOf("."));

      String newname = chemin.substring(0, chemin.length() - 4);

      // String nom = "cours";

      System.out.println("le nouveau nom apré l'exctarction est :" + newname);

      // partie convetion au pdf
       File inputFile = new File("C:\\Users\\Administrateur\\projet_pad\\webs\\WebContent\\PptFile\\"+newname+".ppt");
       System.out.println("Jointure de ppt en cours ...");
       File outputFile = new File("C:\\Users\\Administrateur\\projet_pad\\webs\\WebContent\\PdfFile\\"+newname+".pdf");
       System.out.println("Creation de pdf en cours ...");

       // connect to an instance running on port 8100
       OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
       System.out.println("Connexion avec OOo (localhost:8100) en cours ...");
       try {
           connection.connect(); // 170
           System.out.println("Connexion éffectuée ... ");
       } catch (ConnectException e) {
           // TODO Auto-generated catch block
       } catch (InterruptedException e) {
         // TODO Auto-generated catch block

       // convert
       DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
       converter.convert(inputFile, outputFile);
       System.out.println("Convertion en cours ...");

       // close the connection
       System.out.println("Deconnexion en cours ...");



i got this errors :

com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1

i run the OOe on localhost and 8100,
i have add the jobconverter jars to the buikdpath
i dont know what is the matter !!!

Tagged code part - floris v, moderator
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic Forum Index -> Macros and API All times are GMT - 8 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group