|
|
The following code example renders an interactive PDF form named Loan.xdp to a client web browser. A file is attached to the form. Notice that the form design is stored in the repository.import java.io.FileInputStream;import java.io.IOException;import javax.servlet.Servlet;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.adobe.livecycle.formsservice.client.*;import java.util.*;import java.io.InputStream;import com.adobe.idp.Document;import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;public class RenderPDFForm extends HttpServlet implements Servlet {public void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req,resp);}public void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {try{//Set connection properties required to invoke LiveCycle ESProperties connectionProps = new Properties();connectionProps.setProperty("DSC_DEFAULT_EJB_ENDPOINT", "jnp://localhost:1099");connectionProps.setProperty("DSC_TRANSPORT_PROTOCOL","EJB");connectionProps.setProperty("DSC_SERVER_TYPE", "JBoss");connectionProps.setProperty("DSC_CREDENTIAL_USERNAME", "administrator");connectionProps.setProperty("DSC_CREDENTIAL_PASSWORD", "password");//Create a ServiceClientFactory objectServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);//Create a FormsServiceClient objectFormsServiceClient formsClient = new FormsServiceClient(myFactory);//Set the parameter values for the renderPDFForm methodString formName = "/Loan.xdp";byte[] cData = "".getBytes();Document oInputData = new Document(cData);//Cache the PDF formPDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();pdfFormRenderSpec.setCacheEnabled(new Boolean(true));//Specify URI values that are required to render a formURLSpec uriValues = new URLSpec();uriValues.setApplicationWebRoot("http://localhost:8080/FormsServiceClientApp4");uriValues.setContentRootURI("repository://");uriValues.setTargetURL("http://localhost:8080/FormsServiceClientApp4/HandleData");//Specify file attachments to attach to the formFileInputStream fileAttachment = new FileInputStream("C:\\rideau1.jpg");Document attachment1 = new Document(fileAttachment);String fileName = "rideau1.jpg";Map fileAttachments = new HashMap();fileAttachments.put(fileName, attachment1);//Invoke the renderPDFForm method and write the//results to a client web browserFormsResult formOut = formsClient.renderPDFForm(formName, //formQueryoInputData, //inDataDocpdfFormRenderSpec, //PDFFormRenderSpecuriValues, //urlSpecfileAttachments //attachments);//Create a Document object that stores form dataDocument myData = formOut.getOutputContent();//Get the content type of the response and//set the HttpServletResponse object’s content typeString contentType = myData.getContentType();resp.setContentType(contentType);//Create a ServletOutputStream objectServletOutputStream oOutput = resp.getOutputStream();//Create an InputStream objectInputStream inputStream = myData.getInputStream();//Get the size of the InputStream objectint size = inputStream.available();//Create and populate a byte arraybyte[] data = new byte[size];inputStream.read(data);//Write the data stream to the web browseroOutput.write(data);}catch (Exception e) {System.out.println("The following exception occurred: "+e.getMessage());}}}
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_Forms.10.2.html