Hi,
here is the code we used for the servlet. You have to deploy the servlet in the same container as the adobe-lifecycle. Otherwise it won't work.
Regards,
Luc
SampleCode:
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.UserTransaction;
import com.adobe.document.pdf.ANNOTATION_CREATE;
import com.adobe.document.pdf.ANNOTATION_MODIFY;
import com.adobe.document.pdf.Credential;
import com.adobe.document.pdf.PDFDocument;
import com.adobe.document.pdf.PDFFactory;
import com.adobe.document.pdf.PDFFactoryHelper;
import com.adobe.service.ConnectionFactory;
import com.adobe.service.DataBuffer;
import com.adobe.service.DataManager;
import com.adobe.service.DataManagerHelper;
import com.adobe.service.FileDataBuffer;
import java.io.IOException;
import java.io.OutputStream;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.UserTransaction;
import com.adobe.document.pdf.ANNOTATION_CREATE;
import com.adobe.document.pdf.ANNOTATION_MODIFY;
import com.adobe.document.pdf.Credential;
import com.adobe.document.pdf.PDFDocument;
import com.adobe.document.pdf.PDFFactory;
import com.adobe.document.pdf.PDFFactoryHelper;
import com.adobe.service.ConnectionFactory;
import com.adobe.service.DataBuffer;
import com.adobe.service.DataManager;
import com.adobe.service.DataManagerHelper;
import com.adobe.service.FileDataBuffer;
public class PDFConvertor extends HttpServlet {
>
>/**
>* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
>*/
>public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
>>doPost(req, resp);
>}
>/**
>* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
>*/
>public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
>>String fileUrl = req.getParameter("file");
>>
>>OutputStream outputStream = resp.getOutputStream();
>>try{
>>>ConnectionFactory pdfConnectionFactory = null;
>>>ConnectionFactory dmConnectionFactory = null;
>>>InitialContext namingContext = new InitialContext();
>>>Object pdfObject = namingContext.lookup("PDFManipulation");
>>>Object dmObject = namingContext.lookup("DataManagerService");
>>>pdfConnectionFactory = (ConnectionFactory) PortableRemoteObject.narrow(pdfObject,ConnectionFactory.class);
>>>dmConnectionFactory = (ConnectionFactory) PortableRemoteObject.narrow(dmObject,ConnectionFactory.class);
>>>UserTransaction userTransaction = (UserTransaction) namingContext.lookup("java:comp/UserTransaction");
>>>try {
>>>>userTransaction.begin();
>>>>PDFFactory mPDFFactory = PDFFactoryHelper.narrow((org.omg.CORBA.Object)pdfConnectionFactory.getConnection());
>>>>DataManager mDataManager = DataManagerHelper.narrow((org.omg.CORBA.Object)dmConnectionFactory.getConnection());
>>>>FileDataBuffer pdfFile = mDataManager.createFileDataBufferFromUrl(fileUrl);
>>>>PDFDocument pdf = mPDFFactory.openPDF(pdfFile);
>>>>String[] formRights = new String[] {ANNOTATION_CREATE.value, ANNOTATION_MODIFY.value};//, ANNOTATION_IMPORT.value, ANNOTATION_EXPORT.value, ANNOTATION_DELETE.value, ANNOTATION_COPY.value };
>>>>Credential cred = new Credential();
>>>>cred.alias = "myUser";
>>>>cred.password = "myPassword".getBytes("UTF-8");
>>>>pdf.linearize();
>>>>pdf.setUsageRights(cred, formRights, "", false);
>>>>DataBuffer buffer = pdf.save();
>>>>byte[] bs = buffer.getBytes(0,buffer.getBufLength());
>>>>outputStream.write(bs);
>>>>pdf.close();
>>>>userTransaction.commit();
>>>}catch (Throwable t) {
>>>>userTransaction.rollback();
>>>>t.printStackTrace();
>>>}
>>} catch (Throwable t){
>>>t.printStackTrace();
>>}
>>outputStream.flush();
>>outputStream.close();
>}
}