Moves the L_OcrPage to different index inside the OCR document.
#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrDocument_MovePage(document, page, index)
Handle to the OCR document.
L_OcrPage to move inside the document.
The new index of L_OcrPage inside the document.
| Value | Meaning |
|---|---|
| SUCCESS | The function was successful. |
| < 1 | An error occurred. Refer to Return Codes. |
Moves the L_OcrPage to different index inside the OCR document.
For more information on creating the OCR pages, refer to L_OcrPage_FromBitmap.
Note: This method only works in memory-based documents.
static L_INT CreateMultiPageFile(L_TCHAR* outputFileName){// Create a multi-page TIF from Ocr1.tif, Ocr2.tif, Ocr3.tif and Ocr4.tifHBITMAPLIST bitmapList;L_INT retCode = -1;SAVEFILEOPTION saveOptions = {0};retCode = L_CreateBitmapList(&bitmapList);if(retCode != SUCCESS)return retCode;BITMAPHANDLE bitmaps[4];L_TCHAR *imageFiles[] = {MAKE_IMAGE_PATH(L_TEXT("OCR1.tif")),MAKE_IMAGE_PATH(L_TEXT("OCR2.tif")),MAKE_IMAGE_PATH(L_TEXT("OCR3.tif")),MAKE_IMAGE_PATH(L_TEXT("OCR4.tif"))};for(L_INT i = 0; i < _countof(imageFiles); i++){retCode = L_LoadBitmap(imageFiles[i], &bitmaps[i], sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL);if(retCode != SUCCESS)return retCode;retCode = L_InsertBitmapListItem(bitmapList, (L_UINT)-1, &bitmaps[i]);if(retCode != SUCCESS)goto CLEANUP;}// Save the output fileretCode = L_GetDefaultSaveFileOption(&saveOptions, sizeof(SAVEFILEOPTION));if(retCode != SUCCESS)goto CLEANUP;// Save all pagessaveOptions.PageNumber = -1;retCode = L_SaveBitmapList(outputFileName, bitmapList, FILE_CCITT_GROUP4, 1, 0, &saveOptions);CLEANUP://free all bitmaps in list & dispose of handleL_DestroyBitmapList(bitmapList);return retCode;}L_INT L_OcrDocument_MovePageExample(){L_INT retCode = -1;L_OcrEngine ocrEngine = NULL;L_OcrDocumentManager ocrDocumentManager = NULL;L_OcrDocument ocrDocument = NULL;L_OcrPage ocrPage = NULL;LOADFILEOPTION loadOpts;FILEINFO fileInfo;// For this example, we need a multi-page TIF file.// If you have a different sample file, replace the file name belowL_TCHAR* multiPageFile = MAKE_IMAGE_PATH(L_TEXT("Multipage.tif"));if(CreateMultiPageFile(multiPageFile) != SUCCESS)return FAILURE;// Create an instance of the engineretCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_LEAD, &ocrEngine);if(retCode != SUCCESS)return retCode;// Start the engine using default parametersretCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR);if(retCode == SUCCESS){retCode = L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager);if(retCode != SUCCESS)goto CLEANUP;// Create memory-based OCR documentretCode = L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_InMemory, NULL);if(retCode != SUCCESS)goto CLEANUP;// Load each page of the multi-page tif file we created and process themL_GetDefaultLoadFileOption(&loadOpts, sizeof(LOADFILEOPTION));retCode = L_FileInfo(multiPageFile, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, &loadOpts);if(retCode != SUCCESS)goto CLEANUP;for(L_INT pageNum = 1; pageNum <= fileInfo.TotalPages; pageNum++){// Load pageBITMAPHANDLE bitmap = { 0 };loadOpts.PageNumber = pageNum;retCode = L_LoadBitmap(multiPageFile, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, &loadOpts, &fileInfo);if(retCode != SUCCESS)goto CLEANUP;// Create Ocr pageretCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL);if(retCode != SUCCESS){L_FreeBitmap(&bitmap);goto CLEANUP;}// Transfer ownership to the OCR pagebitmap.Flags.Allocated = 0;// Find zones in the pageretCode = L_OcrPage_AutoZone(ocrPage, NULL, NULL);if(retCode != SUCCESS)goto CLEANUP;// RecognizeretCode = L_OcrPage_Recognize(ocrPage, NULL, NULL);if(retCode != SUCCESS)goto CLEANUP;// In Document File Mode, add OcrPage to OcrDocument after recognitionretCode = L_OcrDocument_AddPage(ocrDocument, ocrPage);if(retCode != SUCCESS)goto CLEANUP;}// SaveretCode = L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Multipage.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL);// now we will try to swap first and second pages and then delete the last page and then re-save the document// final document should have 3 pages instead of 4 and with the first page in place of the second one.L_OcrPage firstPage = NULL;retCode = L_OcrDocument_GetPageAt(ocrDocument, 0, &firstPage);if(retCode != SUCCESS)goto CLEANUP;retCode = L_OcrDocument_MovePage(ocrDocument, firstPage, 1);if(retCode != SUCCESS)goto CLEANUP;// Delete last pageL_UINT uPagesCount = 0;retCode = L_OcrDocument_GetPageCount(ocrDocument, &uPagesCount);if(retCode != SUCCESS)goto CLEANUP;L_OcrPage lastPage = NULL;retCode = L_OcrDocument_GetPageAt(ocrDocument, uPagesCount - 1, &lastPage);if(retCode != SUCCESS)goto CLEANUP;retCode = L_OcrDocument_RemovePage(ocrDocument, lastPage);if(retCode != SUCCESS)goto CLEANUP;retCode = L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Multipage2.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL);}CLEANUP:if(ocrDocument != NULL)L_OcrDocument_Destroy(ocrDocument);if(ocrEngine != NULL)L_OcrEngine_Destroy(ocrEngine);return retCode;}