Converting PDF to Postscript and Image Files converting-pdf-to-postscript-andimage-files
Samples and examples in this document are only for AEM Forms on JEE environment.
About the Convert PDF Service
The Convert PDF service converts PDF documents to PostScript and to several image formats (JPEG, JPEG 2000, PNG, and TIFF). Converting a PDF document to PostScript is useful for unattended server-based printing on any PostScript printer. Converting a PDF document to a multipage TIFF file is practical when archiving documents in content management systems that do not support PDF documents.
You can accomplish these tasks using the Convert PDF service:
- Convert PDF documents to PostScript.
- Convert PDF documents to image formats.
Converting PDF Documents to PostScript 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.
Summary of steps summary-of-steps
To convert a PDF document to a PostScript file, perform the following steps:
- Include project files.
- Create a Convert PDF service client.
- Reference the PDF document to convert to a PostScript file.
- Set conversion run-time options.
- Convert the PDF document to a PostScript file.
- 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 AEM Forms. 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 AEM Forms 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.
ToPSOptionsSpec class reference in AEM Forms 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.
See also
Convert a PDF document to PS using the Java API
Convert a PDF document to PS using the web service API
Convert a PDF document to PS using the Java API convert-a-pdf-document-to-ps-using-the-java-api
Convert a PDF document to PostScript by using the Convert PDF Service API (Java):
-
Include project files.
Include client JAR files, such as adobe-convertpdf-client.jar, in your Java project’s class path.
-
Create a Convert PDF client.
- Create a
ServiceClientFactoryobject that contains connection properties. - Create a
ConvertPdfServiceClientobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Reference the PDF document to convert to a PostScript file.
- Create a
java.io.FileInputStreamobject by using its constructor and pass a string value that specifies the location of the PDF document to convert. - Create a
com.adobe.idp.Documentobject that stores the PDF document by using thecom.adobe.idp.Documentconstructor. Pass thejava.io.FileInputStreamobject that contains the PDF document.
- Create a
-
Set conversion run-time options.
- Create a
ToPSOptionsSpecobject by invoking its constructor. - Set run-time options by invoking an appropriate method that belongs to the
ToPSOptionsSpecobject. For example, to define the PostScript level that is created, invoke theToPSOptionsSpecobject’ssetPsLevelmethod and pass aPSLevelenumeration value that specifies the PostScript level. For information about all run-time values that you can set, see theToPSOptionsSpecclass reference in AEM Forms API Reference.
- Create a
-
Convert the PDF document to a PostScript file.
Invoke the
ConvertPdfServiceClientobject’stoPS2method and pass the following values:- A
com.adobe.idp.Documentobject that represents the PDF document to convert to a PostScript file. - A
ToPSOptionsSpecobject that specifies PostScript run-time options.
The
toPS2method returns aDocumentobject that contains the new PostScript document. - A
-
Save the PostScript file.
- Create a
java.io.Fileobject and ensure that the file name extension is .ps. - Invoke the
Documentobject’scopyToFilemethod to copy the contents of theDocumentobject to the file (ensure that you use theDocumentobject that was returned by thetoPS2method).
- Create a
See also
Quick Start (SOAP mode): Converting a PDF document to PostScript using the Java API
Convert a PDF document to PS using the web service API 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):
-
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 note NOTE Replace localhostwith the IP address of the server hosting AEM Forms. -
Create a Convert PDF client.
-
Create a
ConvertPdfServiceClientobject by using its default constructor. -
Create a
ConvertPdfServiceClient.Endpoint.Addressobject by using theSystem.ServiceModel.EndpointAddressconstructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example,http://localhost:8080/soap/services/ConvertPDFService?blob=mtom.) You do not need to use thelc_versionattribute. However, specify?blob=mtom. -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theConvertPdfServiceClient.Endpoint.Bindingfield. Cast the return value toBasicHttpBinding. -
Set the
System.ServiceModel.BasicHttpBindingobject’sMessageEncodingfield toWSMessageEncoding.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
ConvertPdfServiceClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the field
ConvertPdfServiceClient.ClientCredentials.UserName.Password. - Assign the constant value
HttpClientCredentialType.Basicto the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnlyto the fieldBasicHttpBindingSecurity.Security.Mode.
- Assign the AEM forms user name to the field
-
-
Reference the PDF document to convert to a PostScript file.
- Create a
BLOBobject by using its constructor. TheBLOBobject is used to store a PDF document that is converted to a PostScript file. - Create a
System.IO.FileStreamobject 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.FileStreamobject. You can determine the size of the byte array by getting theSystem.IO.FileStreamobject’sLengthproperty. - Populate the byte array with stream data by invoking the
System.IO.FileStreamobject’sReadmethod and passing the byte array, starting position, and stream length to read. - Populate the
BLOBobject by assigning itsMTOMfield with the contents of the byte array.
- Create a
-
Set conversion run-time options.
- Create a
ToPSOptionsSpecobject by invoking its constructor. - Set run-time options by assigning a value to the
ToPSOptionsSpecobject’s data member. For example, to define the PostScript level that is created, assign aPSLevelenumeration value to theToPSOptionsSpecobject’spsLeveldata member.
- Create a
-
Convert the PDF document to a PostScript file.
Invoke the
GeneratePDFServiceServiceobject’stoPS2method and pass the following values:- A
BLOBobject that represents the PDF document to convert to a PostScript file - A
ToPSOptionsSpecobject that specifies run-time options
After the conversion is complete, extract the binary data that represents the PostScript document by accessing its
BLOBobject’sMTOMproperty. This returns a byte array that you can write out to a PostScript file. - A
-
Save the PostScript file.
- Create a
System.IO.FileStreamobject 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
BLOBobject that was returned by theencryptPDFUsingPasswordmethod. Populate the byte array by getting the value of theBLOBobject’sMTOMfield. - Create a
System.IO.BinaryWriterobject by invoking its constructor and passing theSystem.IO.FileStreamobject. - Write the contents of the byte array to the PostScript file by invoking the
System.IO.BinaryWriterobject’sWritemethod and passing the byte array.
- Create a
See also
Converting PDF Documents to Image Formats converting-pdf-documents-to-image-formats
You can use the Convert PDF service to programmatically convert PDF documents to image formats, which include JPEG, JPEG 2000, TIFF, and PNG. By converting a PDF document to an image file, you can use the PDF document as an image file. For example, you can place the image in an enterprise content management system for storage.
When converting a PDF document to an image, the Convert PDF service creates a separate image for each page in the document. That is, if the document has 20 pages, the Convert PDF service creates 20 image files. When converting a PDF document to an image format, you can create individual images for each page within the PDF document or a single image file for the entire PDF document.
Summary of steps summary_of_steps-1
To convert a PDF document to any of the supported types, perform the following steps:
- Include project files.
- Create a Convert PDF service client.
- Retrieve the PDF document to convert.
- Set run-time options.
- Convert the PDF to an image.
- Retrieve the image files from a collection.
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.
Retrieve the PDF document to convert
Retrieve the PDF document to convert to an image. You cannot convert an interactive PDF document to an image. If you attempt to do so, an exception is thrown. To convert an interactive PDF document to an image file, you must flatten the PDF document before you convert it. (See Flattening PDF Documents.)
Set run-time options
Set run-time options such as the image format and the resolution values. For information about the run-time values, see the ToImageOptionsSpec class reference in AEM Forms API Reference.
Convert the PDF to an image
After you create the service client and set run-time options, you can convert the PDF document to an image. A collection object that contains the images is returned.
Retrieve the image files from a collection
You can retrieve image files from a collection object that the Convert PDF service returns. Each element in the collection is a com.adobe.idp.Document instance (or a BLOB instance if you are using web services) that you can save as an image file, such as a JPG file.
The format of the image file is dependent on the ImageConvertFormat run-time option. That is, if you set the ImageConvertFormat run-time option to ImageConvertFormat.JPEG, you can save image files as JPG files.
See also
Convert a PDF document to image files using the Java API convert-a-pdf-document-to-image-files-using-the-java-api
Convert a PDF document to an image format by using the Convert PDF service API (Java):
-
Include project files.
Include client JAR files, such as adobe-convertpdf-client.jar, in your Java project’s class path.
-
Create a Convert PDF client.
- Create a
ServiceClientFactoryobject that contains connection properties. - Create a
ConvertPdfServiceClientobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Retrieve the PDF document to convert.
- Create a
java.io.FileInputStreamobject that represents the PDF document to convert by using its constructor and passing a string value that specifies the location of the PDF document. - Create a
com.adobe.idp.Documentobject by using its constructor and passing thejava.io.FileInputStreamobject.
- Create a
-
Set run-time options.
- Create a
ToImageOptionsSpecobject by using its constructor. - Invoke methods that belong to this object as required. For example, set the image type by invoking the
setImageConvertFormatmethod and passing anImageConvertFormatenum value that specifies the format type.
note note NOTE Setting the ImageConvertFormatenumeration value is mandatory. - Create a
-
Convert the PDF to an image.
Invoke the
ConvertPdfServiceClientobject’stoImage2method and pass the following values:- A
com.adobe.idp.Documentobject that represents the PDF file to convert. - A
com.adobe.livecycle.converpdfservice.client.ToImageOptionsSpecobject that contains the various preferences about the target image format.
The
toImage2method returns ajava.util.Listobject that contains images. Each element in the collection is acom.adobe.idp.Documentinstance. - A
-
Retrieve the image files from a collection.
Iterate through the
java.util.Listobject to determine whether images are present. Each element is acom.adobe.idp.Documentinstance. Save the image by invoking thecom.adobe.idp.Documentobject’scopyToFilemethod and passing ajava.io.Fileobject.
See also
Quick Start (SOAP mode): Converting a PDF document to JPEG files using the Java API
Convert a PDF document to image files using the web service API convert-a-pdf-document-to-image-files-using-the-web-service-api
Convert a PDF document to an image format by using the Convert PDF Service API (web service):
-
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 note NOTE Replace localhostwith the IP address of the server hosting AEM Forms. -
Create a convert PDF client.
-
Create a
ConvertPdfServiceClientobject by using its default constructor. -
Create a
ConvertPdfServiceClient.Endpoint.Addressobject by using theSystem.ServiceModel.EndpointAddressconstructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example,http://localhost:8080/soap/services/ConvertPDFService?blob=mtom.) You do not need to use thelc_versionattribute. However, specify?blob=mtom. -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theConvertPdfServiceClient.Endpoint.Bindingfield. Cast the return value toBasicHttpBinding. -
Set the
System.ServiceModel.BasicHttpBindingobject’sMessageEncodingfield toWSMessageEncoding.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
ConvertPdfServiceClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the field
ConvertPdfServiceClient.ClientCredentials.UserName.Password. - Assign the constant value
HttpClientCredentialType.Basicto the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnlyto the fieldBasicHttpBindingSecurity.Security.Mode.
- Assign the AEM forms user name to the field
-
-
Retrieve the PDF document to convert.
- Create a
BLOBobject by using its constructor. ThisBLOBobject is used to store the PDF form. - Create a
System.IO.FileStreamobject by invoking its constructor. Pass a string value that specifies the location of the PDF form and the mode to open the file in. - Create a byte array that stores the content of the
System.IO.FileStreamobject. Determine the size of the byte array by getting theSystem.IO.FileStreamobject’sLengthproperty. - Populate the byte array with stream data by invoking the
System.IO.FileStreamobject’sReadmethod. Pass the byte array, the starting position, and the stream length to read. - Populate the
BLOBobject by assigning itsMTOMfield with the contents of the byte array.
- Create a
-
Set run-time options.
- Create a
ToImageOptionsSpecobject by using its constructor. - Invoke methods that belong to this object as required. For example, set the image type by invoking the
setImageConvertFormatmethod and passing anImageConvertFormatenumeration value that specifies the format type.
note note NOTE Setting the ImageConvertFormatenumeration value is mandatory. - Create a
-
Convert the PDF to an image.
Invoke the
ConvertPDFServiceServiceobject’stoImage2method and pass the following values:- A
BLOBobject that represents the file to be converted - A
ToImageOptionsSpecobject that contains the various preferences about the target image format
The
toImage2method returns aMyArrayOfBLOBobject that contains the newly created image files. - A
-
Retrieve the image files from a collection.
- Determine the number of elements in the
MyArrayOfBLOBobject by getting the value of itsCountfield. Each element is aBLOBobject that contains the image. - Iterate through the
MyArrayOfBLOBobject and save each image file.
- Determine the number of elements in the
See also
Invoking AEM Forms using SwaRef