#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrDocument_SaveXml(document, fileName, xmlOptions, outputOptions)

L_OcrDocument document; handle to the OCR document
const L_TCHAR* fileName; the output file name to save the XML data to
const L_OcrWriteXmlOptions* xmlOptions; the document format to use
L_OcrXmlOutputOptions outputOptions; a combination of one or more L_OcrXmlOutputOptions enumeration members that specify the XML generation options

Converts the cumulated recognition result stored in the pages of this OCR document to XML data and stores it in a disk file with XML options.

Parameter Description
document Handle to the OCR document.
fileName The output file name to save the XML data to.
xmlOptions Options to use when creating the XML data.
outputOptions A combination of one or more OcrXmlOutputOptions enumeration members that specify the XML generation options.


SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


Converts the cumulated recognition result stored in the pages of this OCR document to XML data and stores it in a disk file with XML options.

Required DLLs and Libraries

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrDocument_IsInMemory, L_OcrDocument_Destroy, L_OcrDocument_AddPage, L_OcrDocument_GetPageCount, L_OcrDocument_InsertPage, L_OcrDocument_IndexOfPage, L_OcrDocument_GetPageAt, L_OcrDocument_RemovePage, L_OcrDocument_RemovePageAt, L_OcrDocument_MovePage, L_OcrDocument_ClearPages, L_OcrDocument_GetFileName, L_OcrDocument_Save
Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages


L_INT L_OcrDocument_SaveXmlExample() 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
   L_OcrDocument ocrDocument = NULL; 
   // Create an instance of the engine 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   // Load an image to process 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   // Add the image to an OCR page 
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   // Transfer ownership to the OCR page 
   bitmap.Flags.Allocated = 0; 
   // Recognize it 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
   // Create an OCR document 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
   //L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_InMemory, NULL); 
   // In Document File Mode, add OcrPage to OcrDocument after recognition 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
   // Done with this, so we can dispose of it. 
   ocrPage = NULL; 
   // Save the result XML to a disk file 
   // Only save the words not characters, if we want the characters 
   // we need to change the options to OcrXmlOutputOptions.Characters 
   L_OcrWriteXmlOptions ocrWriteXmlOptions; 
   ocrWriteXmlOptions.StructSize = sizeof(L_OcrWriteXmlOptions); 
   ocrWriteXmlOptions.Encoding = L_OcrXmlEncoding_UTF8; 
   ocrWriteXmlOptions.Formatted = true; 
   wsprintf(ocrWriteXmlOptions.Indent, TEXT("   ")); 
   retCode = L_OcrDocument_SaveXml(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Ocr1.xml")), &ocrWriteXmlOptions, L_OcrXmlOutputOptions_None); 
   if(ocrPage != NULL) 
   if(ocrDocument != NULL) 
   if(ocrEngine != NULL) 
   return SUCCESS; 

Help Version 20.0.2018.1.19
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.