Expand my Community achievements bar.

Problem accessing Reader Extensions

Avatar

Former Community Member
Hi,<br /><br />I 've installed Adobe Lifecycle Toolbox 7 for windows (http://www.adobe.com/devnet/livecycle/toolbox/index.html) on a Windows XP for development-purpose. But untill now I was unable to communicate with the Server.<br /><br />The servers runs fine (all admin-pages are working) and by playing with some parameters (portnbrs, urls) I know I'm connecting to it.<br /><br />We installed the program with all default features (all default options) and tried to run sample-code from WSAD (sample-code bellow). We recieve a class-cast exception when trying retrieve the ConnectionFactory.<br /><br />Following adobe-libraries have been included in our classpath as mentioned in the documentation.<br /> - PDFManipulationAPI.jar<br /> - datamanager-client.jar<br /> - jboss-common-client. jar<br /> - jnp-client.jar<br /> - gnu-regexp.jar<br /> - DocumentServiceLibrary.jar<br /><br />I need to enable on a pdf the annotation-functionality.<br /><br />Thx for your help in advance..<br /><br /><u>Sample Code:</u><br /><b><br />package com.kbc.x37.test;<br /><br />import java.io.File;<br />import java.io.FileInputStream;<br />import java.io.InputStream;<br />import java.util.Hashtable;<br />import java.util.Properties;<br /><br />import javax.naming.Context;<br />import javax.naming.InitialContext;<br />import javax.rmi.PortableRemoteObject;<br /><br />import com.adobe.document.pdf.Credential;<br />import com.adobe.document.pdf.CredentialLoginFailure;<br />import com.adobe.document.pdf.FORM_ADD;<br />import com.adobe.document.pdf.FORM_DELETE;<br />import com.adobe.document.pdf.FORM_EXPORT;<br />import com.adobe.document.pdf.FORM_FILL_IN;<br />import com.adobe.document.pdf.FORM_IMPORT;<br />import com.adobe.document.pdf.FORM_SPAWN_TEMPLATE;<br />import com.adobe.document.pdf.FORM_SUBMIT_STAND_ALONE;<br />import com.adobe.document.pdf.NotAllowedByCredential;<br />import com.adobe.document.pdf.PDFDocument;<br />import com.adobe.document.pdf.PDFFactory;<br />import com.adobe.document.pdf.PDFFactoryHelper;<br />import com.adobe.service.ConnectionFactory;<br />import com.adobe.service.DataManager;<br />import com.adobe.service.DataManagerHelper;<br />import com.adobe.service.FileDataBuffer;<br /><br />public class TestReaderExt {<br /><br /> public static void main(String[] args) throws Exception {<br /><br /> // Declare a ConnectionFactory object<br /> ConnectionFactory pdfConnectionFactory = null;<br /><br /> <br /> Hashtable hashtable = new Hashtable();<br /> hashtable.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");<br /> hashtable.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");<br /> hashtable.put("java.naming.provider.url","10.46.25.167:1099");<br /> <br /> //InitialContext namingContext = new InitialContext();<br /> InitialContext namingContext = new InitialContext(hashtable);<br /><br /> ConnectionFactory dmConnectionFactory = null;<br /> <br /><br /> // Lookup the PDF Manipulation service<br /> Object pdfObject = namingContext.lookup("PDFManipulation");<br /><br />Line 82 => pdfConnectionFactory = (ConnectionFactory) PortableRemoteObject.narrow(pdfObject,ConnectionFactory.class);<br /> <br /> <br /> <br /> // Use the pdfConnectionFactory object to create a PDFFactory object<br /><br /> PDFFactory mPDFFactory = PDFFactoryHelper.narrow((org.omg.CORBA.Object)pdfConnectionFactory.getConnection());<br /> // Create a FileDataBuffer object to store an existing PDF document by<br /> // calling the DataManager objects createFileDataBufferFromUrl method.<br /> // Reference a PDF document named Loan.pdf<br /> DataManager mDataManager = DataManagerHelper.narrow((org.omg.CORBA.Object)pdfConnectionFactory.getConnection());<br /><br /> <br /> //FileDataBuffer pdfFile = mDataManager.createFileDataBufferFromUrl("http://<Application Server URL>:AppPort/LoanApp/Forms/Loan.pdf");<br /> FileDataBuffer pdfFile = mDataManager.createFileDataBuffer("y:/backup/test_bo.pdf");<br /> // Open the PDF object using the PDFFactory object<br /> PDFDocument pdf = mPDFFactory.openPDF(pdfFile);<br /> <br /> //pdf.setReaderDownloadMessage("Please download the latest version of Adobe Reader from our web site", "http://www.MyCorp.com");<br /> String[] formRights = new String[] {FORM_ADD.value};<br /> Credential cred = new Credential("Enabl
7 Replies

Avatar

Former Community Member
Apparently the msg was to long.



So here is the error-msg:



Error generated:



java.lang.ClassCastException

at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)

at javax.rmi.PortableRemoteObject.narrow(Unknown Source)

at com.kbc.x37.test.TestReaderExt.main(TestReaderExt.java:82)

Exception in thread "main

Avatar

Former Community Member
I have to do exactly the same procedure but from .NET side. Do you have any solution?



How far have you got?



Thanks,

Zlatan

Avatar

Former Community Member
Hi,



it's not possible to access by CORBA the application outside the container. So you have to deploy the AdobeLifeCycle-application in the same container as your sample-code.



I other words, your can't use corba for remote access. (The question 'Why do they use CORBA for?' is still unanswered..).



We solved the problem by writing a servlet we deployed localy . We use the servlet for handling our call. We needed only to be able to annotate a PDF.



If you use more (advanced) features, you should consider writing a SOAP-interface for your program-calls.



Regards,

Luc

Avatar

Former Community Member
Hi,

I'm not a java specialist, and I want to use an newly installed version of ReaderExtension 7.2.2 to get rid of an old server runnning ReaderExtension 6.x.

I successfully installed it and transformed a PDF document into a "comment and annotation free" PDF with the web interface.

In our production environment we need to call remotely the Application Server where ARES is deployed only for freeing annotations and comments.



Can you please give me your servlet code as a sample code



Thanks in advance



benoit.noss at secu.lu

Avatar

Former Community Member
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();

>}

}

Avatar

Former Community Member
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();

}

}

Avatar

Former Community Member
Thank you very much, I'll try it as soon as possible



Benoît