ABBYY FlexiCapture page re-ordering script

Created by Jeremy Burgess, Modified on Tue, 18 Feb at 8:04 AM by Jeremy Burgess

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<IPage>().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 < pagesList.Count; i++)
        {
            document.Pages.Move(pagesList[i].Index, i);
        }
    }
}


Or reverse order:

pagesList.Sort((x, y) => y.Index.CompareTo(x.Index));


Or order based on the value of a field:

pagesList.Sort((x, y) => 
    x.Fields["CustomFieldName"].Text.CompareTo(y.Fields["CustomFieldName"].Text));

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article