Converting PDF Documents to PostScript

This topic describes how you can use the Convert PDF Service API (Java and web service) to programmatically convert PDF documents to PostScript files. The PDF document that is converted to a PostScript file must be a non-interactive PDF document. That is, if you attempt to convert an interactive PDF document to a PostScript file, an exception is thrown.

Note: For more information about the Convert PDF service, see Services Reference for LiveCycle.

Summary of steps

To convert a PDF document to a PostScript file, perform the following steps:

  1. Include project files.

  2. Create a Convert PDF service client.

  3. Reference the PDF document to convert to a PostScript file.

  4. Set conversion run-time options.

  5. Convert the PDF document to a PostScript file.

  6. Save the PostScript file.

Include project files

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

Create a Convert PDF client

Before you can programmatically perform a Convert PDF service operation, you must create a Convert PDF service client. If you are using the Java API, create a ConvertPdfServiceClient object. If you are using the web service API, create a ConvertPDFServiceService object.

This section uses web service functionality that is introduced in LiveCycle. To access new functionality, you have to construct your proxy object using the lc_version attribute. (See “Accessing new functionality using web services” in Invoking LiveCycle using Web Services.)

Reference the PDF document to convert to a PostScript file

Reference the PDF document that you want to convert to a PostScript file. As stated earlier in this topic, the PDF document must be a non-interactive PDF document. If you attempt to convert an interactive PDF document to a PostScript file, an exception is thrown.

Set conversion run-time options

When converting a PDF document to a PostScript file, you can define run-time options that specify the PostScript type that is created. For example, you can define a level 3 PostScript file.

Typically, the generated PostScript file will reflect the size of input PDF document. If you select the ShrinkToFit option (which shrinks the output of the PostScript file to fit the page), you will not see a difference between the input PDF document and the generated PostScript file. The ShrinkToFit option takes effect only if you select to print on a smaller page size than the input PDF document. To select a smaller page size, define the PageSize option. In addition, it is recommended that you set the RotateAndCenter option to true to obtain the correct PostScript output.

Likewise, if you select the ExpandToFit option (which expands the output of the PostScript file to fit the page), it takes effect only if you select to print on a larger page size than the input PDF document. To select a larger page size, define the PageSize option. In addition, it is recommended that you set the RotateAndCenter option to true to obtain the correct PostScript output.

Note: For information about the run-time values that you can set, see the ToPSOptionsSpec class reference in LiveCycle API Reference.

Convert the PDF document to a PostScript file

After you create the service client and set run-time options, you can invoke the PostScript conversion operation. This operation will need information about the document to convert, including the preferred PostScript level for the target document.

Save the PostScript file

After you convert the PDF document to PostScript, you can save the output as a PostScript file.

Convert a PDF document to PS using the Java API

Convert a PDF document to PostScript by using the Convert PDF Service API (Java):

  1. Include project files.

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

  2. Create a Convert PDF client.

    • Create a ServiceClientFactory object that contains connection properties.

    • Create a ConvertPdfServiceClient object by using its constructor and passing the ServiceClientFactory object.

  3. Reference the PDF document to convert to a PostScript file.

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

    • Create a com.adobe.idp.Document object that stores the PDF document by using the com.adobe.idp.Document constructor. Pass the java.io.FileInputStream object that contains the PDF document.

  4. Set conversion run-time options.

    • Create a ToPSOptionsSpec object by invoking its constructor.

    • Set run-time options by invoking an appropriate method that belongs to the ToPSOptionsSpec object. For example, to define the PostScript level that is created, invoke the ToPSOptionsSpec object’s setPsLevel method and pass a PSLevel enumeration value that specifies the PostScript level. For information about all run-time values that you can set, see the ToPSOptionsSpec class reference in LiveCycle API Reference.

  5. Convert the PDF document to a PostScript file.

    Invoke the ConvertPdfServiceClient object’s toPS2 method and pass the following values:

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

    • A ToPSOptionsSpec object that specifies PostScript run-time options.

    The toPS2 method returns a Document object that contains the new PostScript document.

  6. Save the PostScript file.

    • Create a java.io.File object and ensure that the file name extension is .ps.

    • Invoke the Document object’s copyToFile method to copy the contents of the Document object to the file (ensure that you use the Document object that was returned by the toPS2 method).

Convert a PDF document to PS using the web service API

Convert a PDF document to PostScript by using the Convert PDF Service 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/ConvertPDFService?WSDL&lc_version=9.0.1.

    Note: Replace localhost with the IP address of the server hosting LiveCycle.
  2. Create a Convert PDF client.

    • Create a ConvertPdfServiceClient object by using its default constructor.

    • Create a ConvertPdfServiceClient.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/ConvertPDFService?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 ConvertPdfServiceClient.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 ConvertPdfServiceClient.ClientCredentials.UserName.UserName.

      • Assign the corresponding password value to the field ConvertPdfServiceClient.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. Reference the PDF document to convert to a PostScript file.

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

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

    • 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, starting position, and stream length to read.

    • Populate the BLOB object by assigning its MTOM field with the contents of the byte array.

  4. Set conversion run-time options.

    • Create a ToPSOptionsSpec object by invoking its constructor.

    • Set run-time options by assigning a value to the ToPSOptionsSpec object’s data member. For example, to define the PostScript level that is created, assign a PSLevel enumeration value to the ToPSOptionsSpec object’s psLevel data member.

  5. Convert the PDF document to a PostScript file.

    Invoke the GeneratePDFServiceService object’s toPS2 method and pass the following values:

    • A BLOB object that represents the PDF document to convert to a PostScript file

    • A ToPSOptionsSpec object that specifies run-time options

    After the conversion is complete, extract the binary data that represents the PostScript document by accessing its BLOB object’s MTOM property. This returns a byte array that you can write out to a PostScript file.

  6. Save the PostScript file.

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

    • Create a byte array that stores the data content of the BLOB object that was returned by the encryptPDFUsingPassword method. Populate the byte array by getting the value of the BLOB object’s MTOM field.

    • 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 the PostScript file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.

// Ethnio survey code removed