Compressing and decompressing files using a AEM Forms on JEE Custom DSC compressing-decompressing-files

Prerequisite knowledge prerequisites

Experience with AEM Forms on JEE Process Management, basic Java™ programming, and creating custom Component.

Additional required other products

Java™ editor such as Eclipse or Netbeans IDE

User level user-level


AEM Forms on JEE lets developers create custom ASC (Acrobat Services Container) to create enriched out of the box features. Creating such components are pluggable to the AEM Forms on JEE runtime environment and serves the intended purpose. This article explains how to create a custom ZIP Service which can be used to compress a list of files into a .zip file and decompress a .zip to a list of documents.

Creating a custom ASC component create-custom-dsc-component

Create a custom ASC component with two service operations so you can compress and decompress a list of documents. This component uses the package for compression and decompression.

To create a custom ASC component:

  1. Add the adobe-livecycle-client.jar file to the library
  2. Add the required Icons
  3. Create a public class
  4. Create two public methods named UnzipDocument & ZipDocuments
  5. Write the logic for Compression & Decompression

The code can be found here:

 * Custom DSC : ZIP Utility
 * Purpose: This is a LiveCycle ES2 custom component used to Compress & Decompress List of Documents
 * Author: Nithiyanandam Dharmadass
 * Organization: Ministry of Finance, Kingdom of Bahrain
 * Last modified Date: 18/Apr/2011
package nith.lces2.dsc;

import com.adobe.idp.Document;
import java.util.ArrayList;
import java.util.List;

public class ZIPService {

    static final int BUFFER = 2048; // 2MB buffer size

    public java.util.List UnzipDocument(com.adobe.idp.Document zipDocument) throws Exception {
        ZipInputStream zis = new ZipInputStream(zipDocument.getInputStream());

        ZipEntry zipFile;

        List resultList = new ArrayList();

        while ((zipFile = zis.getNextEntry()) != null) {

            ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();

            int count;  // an int variable to hold the number of bytes read from input stream
            byte data[] = new byte[BUFFER];
            while ((count =, 0, BUFFER)) != -1) {
                byteArrayOutStream.write(data, 0, count);   // write to byte array

            com.adobe.idp.Document unzippedDoc = new Document(byteArrayOutStream.toByteArray());  // create an idp document
            unzippedDoc.setAttribute("file", zipFile.getName());
            unzippedDoc.setAttribute("wsfilename", zipFile.getName());  // update the wsfilename attribute
        return resultList;  // List of uncompressed documents

    public com.adobe.idp.Document ZipDocuments(java.util.List listOfDocuments,java.lang.String zipFileName) throws Exception {

        if (listOfDocuments == null || listOfDocuments.size() == 0) {
            return null;

        ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(byteArrayOutStream);  // ZIP Output Stream

        for (int i = 0; i < listOfDocuments.size(); i++) {
            Document doc = (Document) listOfDocuments.get(i);
            InputStream docInputStream = doc.getInputStream();
            ZipEntry zipEntry = new ZipEntry(doc.getAttribute("file").toString());
            int count;
            byte data[] = new byte[BUFFER];
            while ((count =, 0, BUFFER)) != -1) {
                zos.write(data, 0, count);  // Read document content and add to zip entry

        Document zippedDoc = new Document(byteArrayOutStream.toByteArray());
        if(zipFileName==null || zipFileName.equals(""))
            zipFileName = "";
        zippedDoc.setAttribute("file", zipFileName);
        return zippedDoc;

Creating a Component.XML file create-component-xml-file

A component.xml file must be created within the root folder of the package which defined the service operations and their parameters.

The component.xml file is shown here:

<?xml version="1.0" encoding="UTF-8"?>
<component xmlns="">
<!-- Unique id identifying this component -->

<!-- Version -->

<!-- Start of the Service definition -->
<!-- Unique name for service descriptor.
           The value is used as the default name for
           deployed services -->
      <service name="ZipService">
<!-- service implementation class definition -->

<!-- description -->
        <description>Compress or Decompress list of documents</description>

<!--  You can provide your own icons for a distinct look   -->

<!-- automatically deploys the service and starts it after installation -->
         <auto-deploy service-id="ZipService" />

<!-- method name in the interface setSmtpHost-->
            <operation name="UnzipDocument">
<!-- input parameters to the "send" method -->
              <input-parameter name="zipDocument" title="Input ZIP Document" type="com.adobe.idp.Document">
                    <hint>A ZIP File to be decompressed</hint>
                <output-parameter name="resultList" title="Decompressed list of documents" type="java.util.List">
                    <hint>Decompressed ZIP list</hint>
            <operation name="ZipDocuments">
<!-- input parameters to the "send" method -->
              <input-parameter name="listOfDocuments" title="List of Documents" type="java.util.List">
                    <hint>A list of documents to be Compressed</hint>
                <input-parameter name="zipFileName" title="Result File Name" type="java.lang.String">
                    <hint>The name of compressed file (optional)</hint>

                <output-parameter name="zippedDoc" title="Compressed Zip file" type="com.adobe.idp.Document">
                    <hint>Compressed ZIP File</hint>

Packaging and deploying the component packaging-deploying-component

  1. Compile the Java™ project and create a .JAR file.
  2. Deploy the component (.JAR file) to the AEM Forms on JEE runtime through Workbench.
  3. Start the service from Workbench (see Figure below).

Process Design

Using the ZIP service in workflows using-zip-service-in-workflows

The UnzipDocument operation of the custom service can now accept a document variable as input and return a list of document variables as output.

Unzip Document

Similarly the ZipDocuments operation of the custom component can accept a list of documents as input, compress them as a zip file and return the compressed document.

Zip Document

The following workflow orchestration shows how to decompress the given ZIP file, compress it back to another ZIP file, and return output (see Figure below).

Unzip Zip workflow

Some business use cases business-use-cases

You can use this ZIP Service for the following use cases:

  • Find all files in a given folder and return the files as a compressed document.

  • Supply a ZIP file containing several PDF documents which can be reader extended after decompressing them. This requires AEM Forms on JEE Reader Extensions module.

  • Supply a ZIP file containing a heterogeneous type of document that can be decompressed and converted as PDF document using the Generate PDF service.

  • Policy protect a list of documents and return as a ZIP file.

  • Let users download all the attachments of a process instance as a single ZIP file.