I would like to create a custom module that renames the generated PDF files by taking a generated filename string containg some field values from index fields, batch fields etc.
So when it comes to batch processing i could go for this (setupTransformator
contains the parsed values from the custom storage strings)
public void ProcessBatch(IBatch batch)
{
IACDataElement batchElement = GetBatchElementFromBatch(batch);
IACDataElementCollection currentDocuments = GetDocumentsFromBatchElement(batchElement);
IACDataElement customStorageStrings = GetCustomStorageStringsFromBatch(batch);
IACDataElementCollection batchFields = GetElementsByName(batchElement, ResourcesKofax.BATCH_FIELDS, ResourcesKofax.BATCH_FIELD);
setupTransformator = new SetupTransformator(customStorageStrings);
for (int i = 0; i < currentDocuments.Count; i++)
{
int currentDocumentIndex = i + 1;
IACDataElement currentDocument = currentDocuments[currentDocumentIndex];
IACDataElementCollection indexFields = GetElementsByName(currentDocument, ResourcesKofax.INDEX_FIELDS, ResourcesKofax.INDEX_FIELD);
string targetFilename = setupTransformator.GetFilename(batchElement, currentDocument, batchFields, indexFields);
string documentFilePath = currentDocument[ResourcesKofax.PDF_GENERATION_FILE_NAME];
// rename the PDF file
}
batch.BatchClose(KfxDbState.KfxDbBatchReady, KfxDbQueue.KfxDbQueueNext, 0, string.Empty);
}
private IACDataElement GetBatchElementFromBatch(IBatch batch)
{
IACDataElement rootElement = batch.ExtractRuntimeACDataElement(0);
return rootElement.FindChildElementByName(ResourcesKofax.BATCH);
}
private IACDataElementCollection GetDocumentsFromBatchElement(IACDataElement batchElement)
{
return GetElementsByName(batchElement, ResourcesKofax.DOCUMENTS, ResourcesKofax.DOCUMENT);
}
private IACDataElement GetCustomStorageStringsFromBatch(IBatch batch)
{
IACDataElement setupElement = batch.ExtractSetupACDataElement(0);
IACDataElementCollection batchClasses = GetElementsByName(setupElement, ResourcesKofax.BATCH_CLASSES, ResourcesKofax.BATCH_CLASS);
IACDataElement batchClass = batchClasses[1];
return batchClass.FindChildElementByName(ResourcesKofax.BATCH_CLASS_CUSTOM_STORAGE_STRINGS);
}
private IACDataElementCollection GetElementsByName(IACDataElement dataElement, string rootName, string targetName)
{
return dataElement.FindChildElementByName(rootName).FindChildElementsByName(targetName);
}
Do I have to use the File.Move
method or is there a method from the Kofax library I can use?