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 stepsTo 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 filesInclude 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 clientBefore 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 convertYou must 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 optionsYou must 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 LiveCycle API Reference.
Convert the PDF to an imageAfter 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 collectionYou 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.
Convert a PDF document to image files using the Java APIConvert 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.
Retrieve the PDF document to convert.
Create
a java.io.FileInputStream object 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.Document object by
using its constructor and passing the java.io.FileInputStream object.
Set run-time options.
Create a ToImageOptionsSpec object
by using its constructor.
Invoke methods that belong to this object as required. For
example, set the image type by invoking the setImageConvertFormat method
and passing an ImageConvertFormat enum value that
specifies the format type.
注意: Setting
the ImageConvertFormat enumeration value is mandatory.
Convert the PDF to an image.
Invoke the ConvertPdfServiceClient object’s toImage2 method
and pass the following values:
A com.adobe.idp.Document object
that represents the PDF file to convert.
A com.adobe.livecycle.converpdfservice.client.ToImageOptionsSpec object
that contains the various preferences about the target image format.
The toImage2 method
returns a java.util.List object that contains images.
Each element in the collection is a com.adobe.idp.Document instance.
Retrieve the image files from a collection.
Iterate
through the java.util.List object to determine
whether images are present. Each element is a com.adobe.idp.Document instance.
Save the image by invoking the com.adobe.idp.Document object’s copyToFile method
and passing a java.io.File object.
Convert a PDF document to image files using the web service APIConvert 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.
注意: Replace localhost with the IP
address of the server hosting LiveCycle.
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.
Retrieve the PDF document to convert.
Create
a BLOB object by using its constructor. This BLOB object
is used to store the PDF form.
Create a System.IO.FileStream object 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.FileStream object.
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.
Pass the byte array, the starting position, and the stream length
to read.
Populate the BLOB object by assigning its MTOM field
with the contents of the byte array.
Set run-time options.
Create a ToImageOptionsSpec object
by using its constructor.
Invoke methods that belong to this object as required. For
example, set the image type by invoking the setImageConvertFormat method
and passing an ImageConvertFormat enumeration value
that specifies the format type.
注意: Setting
the ImageConvertFormat enumeration value is mandatory.
Convert the PDF to an image.
Invoke the ConvertPDFServiceService object’s toImage2 method and
pass the following values:
The toImage2 method
returns a MyArrayOfBLOB object that contains the newly
created image files.
Retrieve the image files from a collection.
Determine the number of elements in the MyArrayOfBLOB object
by getting the value of its Count field. Each element
is a BLOB object that contains the image.
Iterate through the MyArrayOfBLOB object
and save each image file.
|
|
|