Iterating Document Pages

When you work with analysis, recognition, or synthesis results, you may need to iterate document pages and blocks on them. In this case, you should take into account that when you request a document element (e.g., a page or a block) for viewing or editing, the data is loaded into memory and stays there until it is unloaded explicitly. This may lead to an "out of memory" error. To prevent it, follow the recommendations below.

Iterating document pages

When you use processing methods of the FRDocument object, layouts and image documents can be saved to disk automatically depending on the selected value of the PageFlushingPolicy property.

But if you request a page of a document and its blocks for viewing or editing, the data is not unloaded or saved automatically. If you are viewing or editing a number of pages, you should unload the data after you have finished working with each page. It means that you should call the Flush method of the FRPage object, and, if you work with .NET, additionally call GC.Collect and GC.WaitForPendingFinalizers.

On the other hand, if you make some changes while iterating through pages, you need to call the Flush method to save these changes. Otherwise, if you call, for example, the SaveToFolder or one of the export methods of the corresponding FRDocument, your changes will be saved to the folder (or the exported document) but will be cleared from the object you are working with.

Note: The behavior of the Flush method depends on the value of the IFRDocument::PageFlushingPolicy property. If the value of PageFlushingPolicy is PFP_FlushToDisk, a call to the method unloads layout and image documents to disk. If it is PFP_Auto, a call to the method unloads the data to disk if there are more than 30 pages in the document; otherwise, the data is kept in memory. If it is PFP_KeepInMemory, the data is not unloaded. This is convenient when you process both small and large documents in one solution, as you can use the same code for processing.

C# code

C++ (COM) code

See also

FRDocument

Working with Text

24.03.2023 8:51:52

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.