#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgSortElements(flatDocHandle, options, callback, userData)

const L_SvgNodeHandle flatDocHandle;

SVG document handle

const L_SvgSortOptions* options;

callback function for each handle

L_SvgSortElementsCallback callback

callback function for each element

L_VOID* userData

pointer to more parameters for the callback

Enumerates the elements of the specified SVG document in a sorted manner.



flatDocHandle The SVG document handle for which the elements should be sorted.
options Pointer to a structure containing the options to use. Can be NULL.
callback Callback to receive the sorted elements. Cannot be NULL.
L_SvgSortElements calls this callback function for each element in the SVG document. The callback function must adhere to the function prototype described in L_SvgSortElementsCallback Function.
userData Void pointer that you can use to pass one or more additional parameters that the callback function needs.
To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter.


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


Support for SVG is only available in the Document and Medical Imaging toolkits.

For more information on flat SVG documents and bounds and resolution, refer to SVG Size, Bounds and Flat.

Use this function to enumerate the elements of the specified SVG document in a controlled sorted manner.

This function will throw an exception if this document is not flat or if it does not have valid physical (pixel) bounds.

If the value of options is NULL, then default options will be used as follows:



SortFlags L_SvgSortFlags_Default
ExtractText L_SvgExtractText_Character

The value of L_SvgSortOptions.ExtractText controls how the engine parses the text of the document as follows:



L_SvgExtractText_Character Default. Extract the text one character at a time.
L_SvgExtractText_Word Extract the text one word at a time.
L_SvgExtractText_Line Extract the text one line at a time.

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.


Win32, x64.

See Also
Functions: L_SvgSortElementsCallback, L_SvgGetBounds, L_SvgFlatDocument, L_SvgSetFlatDocument
Topics: Working with SVG
SVG Size, Bounds and Flat


This example will load pages from a DOC as SVG print out all the strings found.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
// SVG sort callback function 
L_INT EXT_FUNCTION SvgSortElementsCallback(const L_SvgNodeHandle flatDocHandle, const L_SvgElementInfo* info, L_VOID* userData) 
   // Is it text? 
   if (info->Type == L_SvgElementType_Text) 
      // Yes, print it to the console 
      L_TCHAR msg[2048] = {0}; 
      wsprintf(msg, L_TEXT("%s "), info->TextData.Text); 
      // See if its end of line 
      int len = _tcslen(info->TextData.Text); 
      if ((info->TextData.CharacterFlags[len - 1] & L_SvgTextCharacterFlags_EndOfLine) == L_SvgTextCharacterFlags_EndOfLine) 
   return SUCCESS; 
L_INT SvgSortElementsExample(L_VOID) 
   L_INT nRet = SUCCESS; 
   L_TCHAR srcFileName[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("Leadtools.doc")); 
   // get the number of pages 
   FILEINFO fileInfo = {0}; 
   fileInfo.uStructSize = sizeof(FILEINFO); 
   nRet = L_FileInfo(srcFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL); 
   if(nRet == SUCCESS) 
      L_INT pageCount = fileInfo.TotalPages; 
      for(L_INT pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
         // Load this page as SVG, we are interested in the text only so 
         // we will ask LEADTOOLS to skip other elements 
         LOADSVGOPTIONS loadSvgOptions = {0}; 
         loadSvgOptions.uStructSize = sizeof(LOADSVGOPTIONS); 
         loadSvgOptions.uFlags = L_LOADSVGOPTIONS_NONE; 
         LOADFILEOPTION loadOptions = {0}; 
         loadOptions.uStructSize = sizeof(LOADFILEOPTION); 
         loadOptions.PageNumber = pageNumber; 
         nRet = L_LoadSvg(srcFileName, &loadSvgOptions, &loadOptions); 
         if(nRet == SUCCESS) 
            L_SvgNodeHandle docHandle = loadSvgOptions.SvgHandle; 
            L_SvgNodeHandle flatDocHandle = NULL; 
            // Sort requires a flat document, so check for that 
            L_BOOL isFlat = TRUE; 
            L_INT nRet = L_SvgIsFlatDocument(docHandle, &isFlat); 
            if (!isFlat) 
               L_SvgFlatDocument(docHandle, &flatDocHandle, NULL); 
               flatDocHandle = docHandle; 
            // If the document does not have a valid bounds, calculate it now automatically 
            L_SvgBounds bounds; 
            L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
            if (!bounds.IsValid) 
               L_SvgCalculateBounds(flatDocHandle, FALSE); 
            L_SvgSortOptions sortOptions = {0}; 
            sortOptions.StructSize = sizeof(L_SvgSortOptions); 
            sortOptions.ExtractText = L_SvgExtractText_Word; 
            sortOptions.SortFlags = L_SvgSortFlags_Default; 
            L_TCHAR msg[1024] = {0}; 
            wsprintf(msg, L_TEXT("Text for page %d\n"), pageNumber); 
            nRet = L_SvgSortElements(flatDocHandle, &sortOptions, SvgSortElementsCallback, NULL); 
   return nRet; 

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