Skip to main content

ABBYY FlexiCapture page re-ordering script

Symptoms​

Pages of a document in ABBYY FlexiCapture are not in the correct order but there is a pattern that can be applied to correct this.

Cause​

There are myriad causes but typically the scanning / capture process could be to blame, e.g. document is 'back to front' or an A3 folded document has been split into A4 pages, e.g. front side + back-side A3 -> p4, 1, 2, 3.

Resolution​

Use an assembly script or a scripted stage to re-order pages. The script below will restore the original page order of a document.

using System; using System.Linq; using ABBYY.FlexiCapture;

public void ChangePageOrder(IBatch batch) { foreach (IDocument document in batch.Documents) { // Convert pages to a list for sorting var pagesList = document.Pages.Cast().ToList();

// Sort pages based on their original page number (or custom logic)
pagesList.Sort((x, y) => x.Index.CompareTo(y.Index));

// Reorder pages in the document
for (int i = 0; i

Or reverse order:

\${NL}pagesList.Sort((x, y) => y.Index.CompareTo(x.Index)); \${NL}

Or order based on the value of a field: pagesList.Sort((x, y) => x.Fields["CustomFieldName"].Text.CompareTo(y.Fields["CustomFieldName"].Text));