我想创建一个自定义模块,通过获取包含来自索引字段、批处理字段等的一些字段值的生成文件名字符串来重命名生成的 PDF 文件。
因此,当涉及到批处理时,我可以这样做(setupTransformator
包含自定义存储字符串中的解析值)
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);
}
我必须使用该File.Move
方法还是可以使用 Kofax 库中的方法?