Assembling Encrypted PDF Documents assembling-encrypted-pdf-documents
Samples and examples in this document are only for AEM Forms on JEE environment.
You can encrypt a PDF document with a password by using the Assembler service. After a PDF document is encrypted with a password, a user must specify the password to view the PDF document in Adobe Reader or Acrobat. To encrypt a PDF document with a password, the DDX document must contain encryption element values that are required to encrypt a PDF document.
For the purpose of this discussion, assume that the following DDX document is used.
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="https://ns.adobe.com/DDX/1.0/">
<PDF result="EncryptLoan.pdf" encryption="userProtect">
<PDF source="inDoc" />
</PDF>
<PasswordEncryptionProfile name="userProtect" compatibilityLevel="Acrobat7">
<OpenPassword>AdobeOpen</OpenPassword>
</PasswordEncryptionProfile>
</DDX>
Within this DDX document, notice that the source attribute is assigned the value inDoc. In situations where only one input PDF document is passed to the Assembler service and one PDF document is returned, and you invoke the invokeOneDocument operation, assign the value inDoc to the PDF source attribute. When invoking the invokeOneDocument operation, the inDoc value is a predefined key that must be specified in the DDX document.
In contrast, when passing two or more input PDF documents to the Assembler service, you can invoke the invokeDDX operation. In this situation, assign the file name of the input PDF document to the source attribute.
The Encryption service does not have to be part of your AEM forms installation to encrypt a PDF document with a password. See Encrypting and Decrypting PDF Documents.
Summary of steps summary-of-steps
To assemble an encrypted PDF document, perform the following steps:
- Include project files.
- Create a PDF Assembler client.
- Reference an existing DDX document.
- Reference an unsecured PDF document.
- Set run-time options.
- Encrypt the document.
- Save the encrypted PDF document.
Include project files
Include necessary files into your development project. If you are creating a client application using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.
The following JAR files must be added to your project’s class path:
- adobe-livecycle-client.jar
- adobe-usermanager-client.jar
- adobe-assembler-client.jar
- adobe-utilities.jar (required if AEM Forms is deployed on JBoss)
- jbossall-client.jar (required if AEM Forms is deployed on JBoss)
if AEM Forms is deployed on a supported J2EE application server other than JBoss, you must replace the adobe-utilities.jar and jbossall-client.jar files with JAR files that are specific to the J2EE application server that AEM Forms is deployed on. For information about the location of all AEM Forms JAR files, see Including AEM Forms Java library files.
Create an Assembler client
Before you can programmatically perform an Assembler operation, you must create an Assembler service client.
Reference an existing DDX document
A DDX document must be referenced to assemble a PDF document. For example, consider the DDX document that was introduced in this section. To encrypt a PDF document, the DDX document must contain the PasswordEncryptionProfile element.
Reference an unsecured PDF document
An unsecured PDF document must be referenced and passed to the Assembler service to encrypt it. If you reference a PDF document that is already encrypted, an exception is thrown.
Set run-time options
You can set run-time options that control the behaviour of the Assembler service while it performs a job. For example, you can set an option that instructs the Assembler service to continue processing a job if an error is encountered. For information about the run-time options that you can set, see the AssemblerOptionSpec class reference in AEM Forms API Reference.
Encrypt the document
After you create the Assembler service client, reference the DDX document that contains encryption information, reference an unsecured PDF document, and set run-time options, you can invoke the invokeOneDocument operation. Because only one input PDF document is being passed to the Assembler service (and one document is being returned), you can use the invokeOneDocument operation instead of the invokeDDX operation.
Save the encrypted PDF document
If only a single PDF document is being passed to the Assembler service, the Assembler service returns a single document instead of a collection object. That is, when invoking the invokeOneDocument operation, a single document is returned. Because the DDX document referenced in this section contains encryption information, the Assembler service returns a PDF document that is encrypted with a password.
See also
Assemble an encrypted PDF document using the Java API assemble-an-encrypted-pdf-document-using-the-java-api
-
Include project files.
Include client JAR files, such as adobe-assembler-client.jar, in your Java project’s class path.
-
Create an Assembler client.
- Create a
ServiceClientFactoryobject that contains connection properties. - Create an
AssemblerServiceClientobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Reference an existing DDX document.
- Create a
java.io.FileInputStreamobject that represents the DDX document by using its constructor and passing a string value that specifies the location of the DDX file. - Create a
com.adobe.idp.Documentobject by using its constructor and passing thejava.io.FileInputStreamobject.
- Create a
-
Reference an unsecured PDF document.
- Create a
java.io.FileInputStreamobject by using its constructor and passing the location of an unsecured PDF document. - Create a
com.adobe.idp.Documentobject and pass thejava.io.FileInputStreamobject that contains the PDF document. Thiscom.adobe.idp.Documentobject is passed to theinvokeOneDocumentmethod.
- Create a
-
Set run-time options.
- Create an
AssemblerOptionSpecobject that stores run-time options by using its constructor. - Set run-time options to meet your business requirements by invoking a method that belongs to the
AssemblerOptionSpecobject. For example, to instruct the Assembler service to continue processing a job when an error occurs, invoke theAssemblerOptionSpecobject’ssetFailOnErrormethod and passfalse.
- Create an
-
Encrypt the document.
Invoke the
AssemblerServiceClientobject’sinvokeOneDocumentmethod and pass the following values:- A
com.adobe.idp.Documentobject that represents the DDX document. Ensure that this DDX document contains the valueinDocfor the PDF source element. - A
com.adobe.idp.Documentobject that contains the unsecured PDF document. - A
com.adobe.livecycle.assembler.client.AssemblerOptionSpecobject that specifies the run-time options, including default font and job log level.
The
invokeOneDocumentmethod returns acom.adobe.idp.Documentobject that contains a password-encrypted PDF document. - A
-
Save the encrypted PDF document.
- Create a
java.io.Fileobject and ensure that the file name extension is .pdf. - Invoke the
Documentobject’scopyToFilemethod to copy the contents of theDocumentobject to the file. Ensure that you use theDocumentobject that theinvokeOneDocumentmethod returned.
- Create a
See also
Quick Start (SOAP mode): Assembling an encrypted PDF document using the Java API
Assemble an encrypted PDF document using the web service API assemble-an-encrypted-pdf-document-using-the-web-service-api
-
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 localhostwith the IP address of the server hosting AEM Forms. -
Create an Assembler client.
-
Create an
AssemblerServiceClientobject by using its default constructor. -
Create an
AssemblerServiceClient.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/AssemblerService?blob=mtom). You do not need to use thelc_versionattribute. This attribute is used when you create a service reference. -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theAssemblerServiceClient.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
AssemblerServiceClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the field
AssemblerServiceClient.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 an existing DDX document.
- Create a
BLOBobject by using its constructor. TheBLOBobject is used to store the DDX document. - Create a
System.IO.FileStreamobject by invoking its constructor and passing a string value that represents the file location of the DDX document 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, the starting position, and the stream length to read. - Populate the
BLOBobject by assigning itsMTOMfield with the contents of the byte array.
- Create a
-
Reference an unsecured PDF document.
- Create a
BLOBobject by using its constructor. TheBLOBobject is used to store the input PDF document. ThisBLOBobject is passed to theinvokeOneDocumentas an argument. - Create a
System.IO.FileStreamobject by invoking its constructor and passing a string value that represents the file location of the input PDF document 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, 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 an
AssemblerOptionSpecobject 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
AssemblerOptionSpecobject. For example, to instruct the Assembler service to continue processing a job when an error occurs, assignfalseto theAssemblerOptionSpecobject’sfailOnErrordata member.
- Create an
-
Encrypt the document.
Invoke the
AssemblerServiceClientobject’sinvokeOneDocumentmethod and pass the following values:- A
BLOBobject that represents the DDX document - A
BLOBobject that represents the unsecured PDF document - An
AssemblerOptionSpecobject that specifies run-time options
The
invokeOneDocumentmethod returns aBLOBobject that contains an encrypted PDF document. - A
-
Save the encrypted PDF document.
- Create a
System.IO.FileStreamobject by invoking its constructor and passing a string value that represents the file location of the encrypted PDF document and the mode to open the file in. - Create a byte array that stores the content of the
BLOBobject that theinvokeOneDocumentmethod returned. Populate the byte array by getting the value of theBLOBobject’sMTOMdata member. - Create a
System.IO.BinaryWriterobject by invoking its constructor and passing theSystem.IO.FileStreamobject. - Write the contents of the byte array to a PDF file by invoking the
System.IO.BinaryWriterobject’sWritemethod and passing the byte array.
- Create a
See also