Converting PDF Documents to Non-image Formats

This section describes how you can use the Generate PDF Java API and web service API to programmatically convert a PDF document to an RTF file, which is an example of a non-image format. Other non-image formats include HTML, text, DOC, and EPS. When converting a PDF document to RTF, ensure that the PDF document does not contain form elements, such as a submit button. Form elements are not converted.

注意: For more information about the Generate PDF service, see Services Reference for LiveCycle.

Summary of steps

To convert a PDF document to any of the supported types, perform the following steps:

  1. Include project files.

  2. Create a Generate PDF client.

  3. Retrieve the PDF document to convert.

  4. Convert the PDF document.

  5. Save the converted file.

Include project files

Include necessary files into your development project. If you are creating a client application using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.

Create a Generate PDF client

Before you can programmatically perform a Generate PDF operation, you must create a Generate PDF service client. If you are using the Java API, create a GeneratePdfServiceClient object. If you are using the web service API, create a GeneratePDFServiceService object.

Retrieve the PDF document to convert

Retrieve the PDF document to convert to a non-image format.

Convert the PDF document

After you create the service client, you can invoke the PDF export operation. This operation needs information about the document to be converted, including the path to the target document.

Save the converted file

Save the converted file. For example, if you convert a PDF document to an RTF file, save the converted document to an RTF file.

Convert a PDF document to a RTF file using the Java API

Convert a PDF document to an RTF file by using the Generate PDF API (Java):

  1. Include project files.

    Include client JAR files, such as adobe-generatepdf-client.jar, in your Java project’s class path.

  2. Create a Generate PDF client.

    Create a GeneratePdfServiceClient object by using its constructor and passing a ServiceClientFactory object that contains connection properties.

  3. Retrieve the PDF document to convert.

    • Create a java.io.FileInputStream object that represents the PDF document to convert by using its constructor. Pass a string value that specifies the location of the PDF document.

    • Create a com.adobe.idp.Document object by using its constructor and passing the java.io.FileInputStream object.

  4. Convert the PDF document.

    Invoke the GeneratePdfServiceClient object’s exportPDF2 method and pass the following values:

    • A com.adobe.idp.Document object that represents the PDF file to convert.

    • A java.lang.String object that contains the name of the file to convert.

    • A java.lang.String object that contains the name of the Adobe PDF settings.

    • A ConvertPDFFormatType object that specifies the target file type for the conversion.

    • An optional com.adobe.idp.Document object that contains settings to be applied while generating the PDF document.

    The exportPDF2 method returns an ExportPDFResult object that contains the converted file.

  5. Convert the PDF document.

    To obtain the newly created file, perform the following actions:

    • Invoke the ExportPDFResult object’s getConvertedDocument method. This returns a com.adobe.idp.Document object.

    • Invoke the com.adobe.idp.Document object’s copyToFile method to extract the new document.

Convert a PDF document to a RTF file using the web service API

Convert a PDF document to an RTF file by using the Generate PDF API (web service):

  1. Include project files.

    Create a Microsoft .NET project that uses MTOM. Ensure that you use the following WSDL definition: http://localhost:8080/soap/services/GeneratePDFService?WSDL&lc_version=9.0.1.

    注意: Replace localhost with the IP address of the server hosting LiveCycle.
  2. Create a Generate PDf client.

    • Create a GeneratePDFServiceClient object by using its default constructor.

    • Create a GeneratePDFServiceClient.Endpoint.Address object by using the System.ServiceModel.EndpointAddress constructor. Pass a string value that specifies the WSDL to the LiveCycle service (for example, http://localhost:8080/soap/services/GeneratePDFService?blob=mtom.) You do not need to use the lc_version attribute. However, specify ?blob=mtom.

    • Create a System.ServiceModel.BasicHttpBinding object by getting the value of the GeneratePDFServiceClient.Endpoint.Binding field. Cast the return value to BasicHttpBinding.

    • Set the System.ServiceModel.BasicHttpBinding object’s MessageEncoding field to WSMessageEncoding.Mtom. This value ensures that MTOM is used.

    • Enable basic HTTP authentication by performing the following tasks:

      • Assign the LiveCycle user name to the field GeneratePDFServiceClient.ClientCredentials.UserName.UserName.

      • Assign the corresponding password value to the field GeneratePDFServiceClient.ClientCredentials.UserName.Password.

      • Assign the constant value HttpClientCredentialType.Basic to the field BasicHttpBindingSecurity.Transport.ClientCredentialType.

      • Assign the constant value BasicHttpSecurityMode.TransportCredentialOnly to the field BasicHttpBindingSecurity.Security.Mode.

  3. Retrieve the PDF document to convert.

    • Create a BLOB object by using its constructor. The BLOB object is used to store a PDF document that is converted.

    • Create a System.IO.FileStream object by invoking its constructor and passing a string value that represents the file location of the PDF document and the mode in which to open the file.

    • Create a byte array that stores the content of the System.IO.FileStream object. You can determine the size of the byte array by getting the System.IO.FileStream object’s Length property.

    • Populate the byte array with stream data by invoking the System.IO.FileStream object’s Read method and passing the byte array, the starting position, and the stream length to read.

    • Populate the BLOB object by assigning to its MTOM property the contents of the byte array.

  4. Convert the PDF document.

    Invoke the GeneratePDFServiceServiceWse object’s ExportPDF2 method and pass the following values:

    • A BLOB object that represents the PDF file to convert.

    • A string that contains the path name of the file to convert.

    • A java.lang.String object that specifies the file location.

    • A string object that specifies the target file type for the conversion. Specify RTF.

    • An optional BLOB object that contains settings to be applied while generating the PDF document.

    • An output parameter of type BLOB that is populated by the ExportPDF2 method. The ExportPDF2 method populates this object with the converted document. (This parameter value is required only for web service invocation).

  5. Save the converted file.

    • Retrieve the converted RTF document by assigning the BLOB object’s MTOM field to a byte array. The byte array represents the converted RTF document. Ensure you use the BLOB object that is used as the output parameter for the ExportPDF2 method.

    • Create a System.IO.FileStream object by invoking its constructor. Pass a string value that represents the location of the RTF file.

    • Create a System.IO.BinaryWriter object by invoking its constructor and passing the System.IO.FileStream object.

    • Write the contents of the byte array to a RTF file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.