Convert password protected PDF files

This feature unlocks password protected PDF files. The passwords for unlocking the PDF files can be fetched from any source, such as an XML file or a database.

Sample code for using this feature.

public class ConvertEncryptedPdf : IDocumentConverterScript
    {
        /// <summary>
        /// This method is used to Convert dicuments to Tiff/PDF
        /// </summary>
        /// <param name="message">The message to be imported into KC</param>
        /// <param name="converter">The Document Converter Interface object</param>
        /// <returns></returns>
        public ConversionResult DocumentConverter(Message message, IDocumentConverter converter)
        {
            ConversionResult result = new ConversionResult();

            if (converter != null)
            {
                List<Attachment> convertedAttachments = null;
                DocumentConversionOptions options = new DocumentConversionOptions();

                /* ConversionDetails class exposes the following settings:
                 *  PDF Normalization
                 *  Flattening portfolio PDFs using Adobe Life Cycle
                 *  Image Quality
                 *  Image Resolution
                 *  Image Scaling and Image Coding
                 *  Smoothening and Rendering Flags
                */

                options.ConversionDetails = new ConversionDetails();

                // Configuring PDF Normalization and Flattening portfolio PDFs.
                options.ConversionDetails.isPdfNormalationEnabled = true;
                options.ConversionDetails.isALCFlatteningEnabled = true;

                // To Convert documents to Tiff or PDF, configure the required options below.

                // Configuring PDF conversion.
                // NOTE: If the input is a PDF document, and PDF normalization is not enabled, then output will be empty.
                options.Pdf = 1;

                // Configuring Tif conversion.
                options.Tif = 1;

                /*
                 * Passwords can be read from any source.
                 * They can be read from an XML file or a database and 
                 * be used for unlocking the incoming PDF documents.
                */

                // As sample, we are hardcoding the passwords here.
                List<string> passwords = new List<string>();
                passwords.Add("GoodPassW0rd");
                passwords.Add("badpassword");
                passwords.Add("Just@Pwd");
                passwords.Add("RE@ll$TouGHP@sSW0R&");
                passwords.Add("test@88");
                passwords.Add("test");
                passwords.Add("abcd");

                // The passwords set here would be encrypted before sending the request to 
                // Message connector for unlocking the PDF files.
                options.ConversionDetails.SetPasswords(passwords);

                // Call the Convert API with the documents which needs conversion as input.
                List<Attachment> pdfAttachments = message.BodyAttachments.FindAll(att => att.Extension.ToUpper().Contains("PDF"));

                if (pdfAttachments.Count > 0)
                {
                    result = converter.Convert(out convertedAttachments, pdfAttachments, options);
                }

                if (result.Code == 0 && convertedAttachments != null && convertedAttachments.Count > 0)
                {
                    // Add the converted documents to the message 
                    // so that they will be imported into Kofax Capture.
                    message.BodyAttachments.AddRange(convertedAttachments);
                }
            }

            return result;
        }

        public eMessageScriptCode ReRoute(Message message, object extension)
        {
            return eMessageScriptCode.Other;
        }

To enable this feature, do the following:

  1. Copy the script file CombineEncryptedPdfs.cs from the KCSImportScriptingSample.zip file. Default path:
    C:\Program Files (x86)\Kofax\KIC-ED\KCPlugIn\ScriptSample
  2. In KC Plug-In:
    1. Paste this script file to a local path. In Additional settings tab of KC Plug-In Destination configuration, configure Rerouting\Document conversion script path field to browse the CombineEncryptedPdfs.cs file.
    2. Ensure that the Import original content option is selected in the Import settings tab.
    3. Restart the KC Plug-In service.
  3. In Message Connector, clear the Enable decompression check box.