The following code example renders a rights-enabled form
to a client web browser using the Forms web service API. The usage
rights set in this code example enables a user to add comments in
the form and save form data in Adobe Reader (typically this functionality
is not available in Adobe Reader). (See Rendering Rights-Enabled Forms.)
/*
* Ensure that you create the Java proxy classes to use
* base64 encoding. This is required to populate a BLOB
* object with data or retrieve data from a BLOB object.
*
* For information, see "Creating Java proxy classes using Apache Axis"
* in Programming with LiveCycle.
*/
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 java.io.FileInputStream;
import com.adobe.idp.services.*;
public class RenderUsageRightsFormsWS 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
{
//Create a FormsService object and set authentication values
FormsServiceServiceLocator sl = new FormsServiceServiceLocator();
FormsService formsClient = sl.getFormsService();
((javax.xml.rpc.Stub)formsClient)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "administrator");
((javax.xml.rpc.Stub)formsClient)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password");
//Set the parameter values
String formName = "Loan.xdp";
String userAgent = "" ;
//Create a BLOB object to pass to the renderPDFFormWithUsageRights method
//Reference an XML file that matches the form schema but does not
//contain values
//A BLOB object cannot be NULL
FileInputStream fileInputStream = new FileInputStream("C:\\Adobe\Loan_data_empty.xml");
BLOB dataMerge = new BLOB();
int len = fileInputStream.available();
byte [] myStream = new byte[len] ;
fileInputStream.read(myStream);
dataMerge.setBinaryData(myStream);
//Set run-time options
PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();
pdfFormRenderSpec.setCacheEnabled(new Boolean(true));
//Set URI values required by the Forms service to render the form
URLSpec uriValues = new URLSpec();
uriValues.setApplicationWebRoot("http://localhost:8080/FormsWSQS");
uriValues.setContentRootURI("C:\\Adobe");
uriValues.setTargetURL("http://localhost:8080/FormsWSQS/HandleData");
//Set usage-rights options
ReaderExtensionSpec reOptions = new ReaderExtensionSpec();
reOptions.setReCredentialAlias("RE2");
reOptions.setReCommenting(true);
reOptions.setReFillIn(true);
//Render a rights-enabled PDF form
FormsResult formOut = formsClient.renderPDFFormWithUsageRights(
formName, //formQuery
dataMerge, //inDataDoc
pdfFormRenderSpec, //renderFormOptionsSpec
reOptions, //applicationWebRoot
uriValues //targetURL
);
//Create a BLOB object that contains form data
BLOB formData = formOut.getOutputContent();
//Get the content type of the response and
//set the HttpServletResponse object's content type
String contentType = formData.getContentType();
resp.setContentType(contentType);
//Create a ServletOutputStream object
ServletOutputStream oOutput = resp.getOutputStream();
//Create a byte array that stores form data in the BLOB object
byte[] cContent = formData.getBinaryData();
//Write a byte stream back to the web browser.
//Pass the byte array
oOutput.write(cContent);
}catch (Exception e) {
System.out.println("The following error occurred: " +e.getMessage());
}
}
}
|
|
|