Monday, October 18, 2010

Silicon Valley Code Camp Cloud Session

Last weekend I taught two sessions at the Silicon Valley Code Camp in Sunnyvale, CA.  One of the sessions was on cloud computing called "Manipulating PDF with Java on the Cloud: For fun and profit!".  The slide deck is available to anyone who wants to have it.  Please email me if you wish to get it.

The slide deck was not the main part however.  Here are the steps required to repeat the code camp.

1. First, you have to have an instance of LiveCycle ES2 up and running on the cloud.  Adobe has this all bundled up for you and if you are a member of the Adobe Enterprise Developer Program (AEDP), you have ten free hours per month (YAMMV).  You can also set up another cloud account and install it yourself.  I've looked around and found some cloud accounts that seem to be good for this.  See the note at the end of this post for more details.

2. Log in to the cloud and start your instance. 

3. Press the start instance button.  When your instance is up and running, there are two methods to use to connect.  The easiest is to download and install the Developer Express Desktop network client.  This simply intercepts all traffic bound for localhost (http://127.0.0.1) on port 8080 and redirects it to the cloud.  The second methods is to use the public URL for the cloud instance.  Either way is fine.

Note: the rest of this tutorial will assume you are using the network desktop client.



4. If using the LiveCycle Desktop networking application, log in with the same credentials you used to log into the cloud.

5. Start up Eclipse and start a new Java project.  Within your project, add a new package, then add a Java class called "CreatePDF".

6. You will need several core Java libs from the LiveCycle ES install.  These are located under the /sdks directory.  For this example, you will need the following *.jars:
  • adobe-encryption-client.jar
  • adobe-livecycle-client.jar
  • adobe-usermanager-client.jarThese JAR files are located in the following path:
    {install directory}/LiveCycle/LiveCycle_ES_SDK/client-libs/common
  • adobe-utilities.jar This file is located in the following path:
    {install directory}/LiveCycle/LiveCycle_ES_SDK/client-libs/jboss
  • jbossall-client.jar This file is located in the following path:
    {install directory}/LiveCycle/jboss/client
    (Use a different JAR file if LiveCycle ES is not deployed on JBoss.)
  • You will also need the third-party JAR files to use the SOAP stack rather than EJB endpoints. If you want to invoke a remote LiveCycle ES instance and there is a firewall between the client application and LiveCycle ES, then it is recommended that you use the SOAP mode. When using the SOAP mode, you have to include additional JAR files located in the following path:

    {install directory}/LiveCycle/LiveCycle_ES_SDK/client-libs/thirdparty
    Within your class, you should see some skeleton code under your new project. Highlight all code, delete it and replace the deleted skeleton code with this source code:

    package org.duanesworldtv.samples;

    /*
     * This Java Quick Start uses the following JAR files
     * 1. adobe-distiller-client.jar
     * 2. adobe-livecycle-client.jar
     * 3. adobe-usermanager-client.jar
     * 4. adobe-utilities.jar
     * 5. jbossall-client.jar (use a different JAR file if LiveCycle ES is not deployed
     * on JBoss)

     *
     *  These JAR files are located in the following path:
     * /LiveCycle/LiveCycle_ES_SDK/client-libs
     *
     * For complete details about the location of these JAR files,
     * see "Including LiveCycle ES library files" in Programming
     * with LiveCycle ES
     */
    import java.io.File;
    import java.io.FileInputStream;
    import java.util.Properties;
    import com.adobe.livecycle.generatepdf.client.CreatePDFResult;
    import com.adobe.idp.Document;
    import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
    import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
    import com.adobe.livecycle.distiller.client.DistillerServiceClient;
     
    public class CreatePDF {
     
     public static void main(String[] args)
     {
      try
      {
          //Set connection properties required to invoke LiveCycle ES                                          
          Properties ConnectionProps = new Properties();
          ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://127.0.0.1:8080");
          ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);        
          ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
          ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
          ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "{password}");
     
      // Create a ServiceClientFactory instance
      ServiceClientFactory factory = ServiceClientFactory.createInstance(ConnectionProps);
     
      DistillerServiceClient disClient = new DistillerServiceClient(factory );
     
      // Get a PS file document to convert to a PDF document and populate a com.adobe.idp.Document object
      String inputFileName = "/Users/duane/Desktop/eclipse/workspace/JavaOne2009-docs/test.ps";
      FileInputStream fileInputStream = new FileInputStream(inputFileName);
      Document inDoc = new Document(fileInputStream);
      
      //Set run-time options
      String adobePDFSettings = "Standard";
      String securitySettings = "No Security";
        
      //Convert a PS  file into a PDF file
      CreatePDFResult result = new CreatePDFResult();
      result = disClient.createPDF(
        inDoc, inputFileName, adobePDFSettings,
        securitySettings, null, null
      );
         
      //Get the newly created document
      Document createdDocument = result.getCreatedDocument();
         
      //Save the PDF file
      createdDocument.copyToFile(new File("/Users/duane/Desktop/eclipse/workspace/JavaOne2009-docs/DuanesWorldTest.pdf"));
      }
      catch (Exception e) {
       e.printStackTrace();
      }
     }
    }
     
    Be sure to replace the package name, class name and paths with your own.
    7. Now compile your class and run it.  When Eclipse runs this, it should try to hit 127.0.0.1:8080 to make the request.  This will be intercepted by the desktop networking client and forwarded to the cloud instance where the invocation request will be fulfilled.  When completed, you should find a new instance of a PDF document under the path you used at the end of this code!

    We've also been doing some research into cloud computing providers.  While Adobe uses The Amazon cloud for various reasons (including legal, compliance, support and technical), We've found some hidden gems.   After testing a few, we found the best VPS Cloud Hosting at sherweb.com.  Regardless of where you go for cloud hosting, this tutorial should work fine once you get Livecycle ES up and running.



    1 comment:

    1. Thanks Duane for posting this. This was my 4th year at the Silicon Valley Code Camp. I think it is important for Developers to think about many different toolset and to expand their skills out of their day job. One of the facts, I heard you repeat over a dozen times over the CodeCamp weekend. Is that there is a real need for developers who understand LC. and that Banks/Financial institutions in places like Dubai who have thousands of online document/forms (pdfs) are paying up to $400/hr for developers who can come to help solve this problem. The LC solution is an enterprise workflow to help ripapart-update these PDFs. Another sample you mentioned was the current housing loan App/documents where thousands of loan documents in the US have to analyzed for digital signatures in the loan documents... You mentioned that LiveCycle can segments parts of a PDF (like a signature field) and put them into an enterprise process flow... Developers should know there is lots of opportunity in this area -- Aaron Houston Adobe Community Manager San Jose

      ReplyDelete

    Do not spam this blog! Google and Yahoo DO NOT follow comment links for SEO. If you post an unrelated link advertising a company or service, you will be reported immediately for spam and your link deleted within 30 minutes. If you want to sponsor a post, please let us know by reaching out to duane dot nickull at gmail dot com.