Combine password protected PDF files
This feature unlocks password protected PDF files and concatenate the output files.
Conversion of password protected PDF Portfolio and ZIP files is not supported.
Sample code for using this feature.
class CombineEncryptedPdfs : IDocumentConverterScript
{
public ConversionResult DocumentConverter(Message message, IDocumentConverter converter)
{
ConversionResult result = new ConversionResult();
if (converter != null)
{
Attachment combinedAttachment = null;
DocumentCombineOptions options =
new DocumentCombineOptions
{
/* Setting CombineTo to PDF.*/
combineTo = CombineOptionsCombineTo.PDF,
WaitTimeSec = 120,
conversionDetails = new ConversionDetails()
};
// Enabling PDF normalization and ALC flattening.
options.conversionDetails.isALCFlatteningEnabled = true;
options.conversionDetails.isPdfNormalationEnabled = true;
options.conversionDetails.PDFACompliance = PDFAComplianceType.PDFA3a;
/*
* 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.CombineBinaries(out combinedAttachment, pdfAttachments, options);
}
if (result.Code == 0 && combinedAttachment != null)
{
// Uncomment below line to replace all the files and import only the combined attachment
//message.BodyAttachments.Clear();
// To add the combined Attachment to the list of files imported
message.BodyAttachments.Add(combinedAttachment);
}
}
return result;
}
public eMessageScriptCode ReRoute(Message message, object extension)
{
return eMessageScriptCode.Other;
}
}
To enable this feature, do the following:
-
Copy the script file ConvertEncryptedPdf.cs from the KCSImportScriptingSample.zip file. Default path:
C:\Program Files (x86)\Kofax\KIC-ED\KCPlugIn\ScriptSample
-
In KC Plug-In:
- 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 ConvertEncryptedPdf.cs file.
- Ensure that the Import original content option is selected in the Import settings tab.
- Restart the KC Plug-In service.
- In Message Connector, clear the Unpack archives check box.