Disassemble a PDF document using the web service API disassemble-a-pdf-document-usingthe-web-service-api
Samples and examples in this document are only for AEM Forms on JEE environment.
Disassemble a PDF document by using the Assembler Service API (web service):
-
Include project files.
Create a Microsoft .NET project that uses MTOM. Ensure that you use the following WSDL definition when setting a service reference:
http://localhost:8080/soap/services/AssemblerService?WSDL&lc_version=9.0.1
.note note NOTE Replace localhost
with the IP address of the server hosting AEM Forms. -
Create a PDF Assembler client.
-
Create an
AssemblerServiceClient
object by using its default constructor. -
Create an
AssemblerServiceClient.Endpoint.Address
object by using theSystem.ServiceModel.EndpointAddress
constructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example,http://localhost:8080/soap/services/AssemblerService?blob=mtom
). You do not need to use thelc_version
attribute. This attribute is used when you create a service reference. -
Create a
System.ServiceModel.BasicHttpBinding
object by getting the value of theAssemblerServiceClient.Endpoint.Binding
field. Cast the return value toBasicHttpBinding
. -
Set the
System.ServiceModel.BasicHttpBinding
object’sMessageEncoding
field 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
AssemblerServiceClient.ClientCredentials.UserName.UserName
. - Assign the corresponding password value to the field
AssemblerServiceClient.ClientCredentials.UserName.Password
. - Assign the constant value
HttpClientCredentialType.Basic
to the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType
. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnly
to the fieldBasicHttpBindingSecurity.Security.Mode
.
- Assign the AEM forms user name to the field
-
-
Reference an existing DDX document.
- Create a
BLOB
object by using its constructor. TheBLOB
object is used to store the DDX document. - Create a
System.IO.FileStream
object by invoking its constructor. Pass a string value that represents the file location of the DDX 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 theSystem.IO.FileStream
object’sLength
property. - Populate the byte array with stream data by invoking the
System.IO.FileStream
object’sRead
method and passing the byte array, the starting position, and the stream length to read. - Populate the
BLOB
object by assigning itsMTOM
property with the contents of the byte array.
- Create a
-
Reference a PDF document to disassemble.
- Create a
BLOB
object by using its constructor. TheBLOB
object is used to store the input PDF document. ThisBLOB
object is passed to theinvokeOneDocument
as an argument. - Create a
System.IO.FileStream
object by invoking its constructor and passing a string value that represents the file location of the input 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 theSystem.IO.FileStream
object’sLength
property. - Populate the byte array with stream data by invoking the
System.IO.FileStream
object’sRead
method and passing the byte array, the starting position, and the stream length to read. - Populate the
BLOB
object by assigning itsMTOM
field the contents of the byte array. - Create a
MyMapOf_xsd_string_To_xsd_anyType
object. This collection object is used to store the PDF to disassemble. - Create a
MyMapOf_xsd_string_To_xsd_anyType_Item
object. - Assign a string value that represents the key name to the
MyMapOf_xsd_string_To_xsd_anyType_Item
object’skey
field. This value must match the value of the PDF source element specified in the DDX document. - Assign the
BLOB
object that stores the PDF document to theMyMapOf_xsd_string_To_xsd_anyType_Item
object’svalue
field. - Add the
MyMapOf_xsd_string_To_xsd_anyType_Item
object to theMyMapOf_xsd_string_To_xsd_anyType
object. Invoke theMyMapOf_xsd_string_To_xsd_anyType
object’Add
method and pass theMyMapOf_xsd_string_To_xsd_anyType
object.
- Create a
-
Set run-time options.
- Create an
AssemblerOptionSpec
object that stores run-time options by using its constructor. - Set run-time options to meet your business requirements by assigning a value to a data member that belongs to the
AssemblerOptionSpec
object. For example, to instruct the Assembler service to continue processing a job when an error occurs, assignfalse
to theAssemblerOptionSpec
object’sfailOnError
field.
- Create an
-
Disassemble the PDF document.
Invoke the
AssemblerServiceClient
object’sinvokeDDX
method and pass the following values:- A
BLOB
object that represents the DDX document that disassembles the PDF document - The
MyMapOf_xsd_string_To_xsd_anyType
object that contains the PDF document to disassemble - An
AssemblerOptionSpec
object that specifies run-time options
The
invokeDDX
method returns anAssemblerResult
object that contains the job results and any exceptions that occurred. - A
-
Save the disassembled PDF documents.
To obtain the newly created PDF documents, perform the following actions:
- Access the
AssemblerResult
object’sdocuments
field, which is aMap
object that contains the disassembled PDF documents. - Iterate through the
Map
object to obtain each resultant document. Then, cast that array member’svalue
to aBLOB
. - Extract the binary data that represents the PDF document by accessing its
BLOB
object’sMTOM
property. This returns an array of bytes that you can write out to a PDF file.
- Access the
See also
Programmatically Disassembling PDF Documents