The Distiller® service converts PostScript®, Encapsulated PostScript (EPS), and PRN files to compact, reliable, and more secure PDF files over a network. The Distiller service is frequently used to convert large volumes of print documents to electronic documents, such as invoices and statements. Converting documents to PDF also allows enterprises to send their customers a paper version and an electronic version of a document.
This topic describes how you can use the Distiller Service API (Java and web service) to programmatically convert PostScript (PS), Encapsulated PostScript (EPS), and PRN files to PDF documents.
To convert PostScript files to PDF documents, one of the following needs to be installed on the server hosting AEM Forms: Acrobat 9 or Microsoft Visual C++ 2005 redistributable package.
Include the necessary files in 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.
Before you can programmatically perform a Distiller service operation, you must create a Distiller service client. If you are using the Java API, create a DistillerServiceClient object. If you are using the web service API, create a DistillerServiceService object.
You must retrieve the file that you want to convert. For example, to convert a PS file to a PDF document, you must retrieve the PS file.
After you create the service client, you can then invoke the PDF creation operation. This operation will need information about the document to be converted, including the path to the target document.
Invoke the PDF creation operation.
Invoke the DistillerServiceClient object’s createPDF method and pass the following values:
The com.adobe.idp.Document object that represents the PS, EPS, or PRN file to be converted
A java.lang.String object that contains the name of the file to be converted
A java.lang.String object that contains the name of the Adobe PDF settings to be used
A java.lang.String object that contains the name of the security settings to be used
An optional com.adobe.idp.Document object that contains settings to be applied while generating the PDF document
An optional com.adobe.idp.Document object that contains metadata information to be applied to the PDF document
Invoke the CreatePDFResult object’s getCreatedDocument method. This returns a com.adobe.idp.Document object.
Invoke the com.adobe.idp.Document object’s copyToFile method to extract the PDF document.
Create a DistillerServiceClient object by using its default constructor.
Create a DistillerServiceClient.Endpoint.Address object by using the System.ServiceModel.EndpointAddress constructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example, http://localhost:8080/soap/services/DistillerService?blob=mtom.) You do not need to use the lc_version attribute. This attribute is used when you create a service reference. However, specify ?blob=mtom to use MTOM.
Create a System.ServiceModel.BasicHttpBinding object by getting the value of the DistillerServiceClient.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 AEM forms user name to the field DistillerServiceClient.ClientCredentials.UserName.UserName.
Assign the corresponding password value to the field DistillerServiceClient.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.
Create a BLOB object by using its constructor. This BLOB object is used to store the file to convert to a PDF document.
Create a System.IO.FileStream object by invoking its constructor and passing a string value that represents the file location 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, the starting position, and the stream length to read.
Populate the BLOB object by assigning its MTOM property with the contents of the byte array.
Invoke the PDF creation operation.
Invoke the DistillerServiceService object’s CreatePDF2 method and pass the following required values:
The BLOB object that represents the PS file to convert
A string that contains the path name of the file to be convert
A string object that contains the Adobe PDF settings to be used (for example, Standard)
A string object that contains the security settings to be used (for example, No Security)
An optional BLOB object that contains settings to be applied while generating the PDF document
An optional BLOB object that contains metadata information to be applied to the PDF document
A BLOB output parameter used to store the PDF document
A BLOB output parameter used to store the log
Create a System.IO.FileStream object by invoking its constructor. Pass a string value that represents the file location of the signed PDF document and the mode in which to open the file.
Create a byte array that stores the content of the BLOB object that was returned by the CreatePDF2 method (the output parameter). Populate the byte array by getting the value of the BLOB object’s MTOM data member.
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 PDF file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.