←Select platform

SvgSortElementsCallback Delegate

Summary
Callback to receive the sorted SVG elements.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public delegate bool SvgSortElementsCallback( 
   SvgDocument document, 
   SvgElementInfo info, 
   object userData 
) 
BOOL (^)(LTSvgDocument *document, LTSvgElementInfo *info, id _Nullable userData) 
boolean SvgSortElementsCallback.onSort(SvgDocument document, SvgElementInfo info, object userData) 
public delegate bool SvgSortElementsCallback(  
   SvgDocument^ document, 
   SvgElementInfo^ info, 
   Object^ userData 
) 
def SvgSortElementsCallback(self,document,info,userData): 
# document : SvgDocument, info : SvgElementInfo, userData : Object 

Parameters

document
The source SvgDocument.

info
Element information.

userData
Optional user data. This is the same parameter passed to SortElements.

Return Value

true to continue to the next element (if any), and false to stop enumerating.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SortElementsExample() 
{ 
   // The source PDF file 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
   string dstFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.txt"); 
 
   // SVG sort callback handler 
   SvgSortElementsCallback sortCallback = (callabackDocument, info, userData) => 
   { 
      StreamWriter writer = userData as StreamWriter; 
      // Is it text? 
      SvgTextData textData = info.TextData; 
      if (textData != null) 
      { 
         // Yes, print it to the console 
         writer.Write(textData.Text + " "); 
 
         // See if its end of line 
         var len = textData.Text.Length; 
         if ((textData.CharacterFlags[len - 1] & SvgTextCharacterFlags.EndOfLine) == SvgTextCharacterFlags.EndOfLine) 
            writer.WriteLine(); 
      } 
 
      return true; 
   }; 
 
   using (var codecs = new RasterCodecs()) 
   { 
      // Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
      // get the number of pages 
      int pageCount = codecs.GetTotalPages(srcFileName); 
 
      // Create a writer for the output text file 
      using (StreamWriter writer = File.CreateText(dstFileName)) 
      { 
         for (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 
            CodecsLoadSvgOptions loadSvgOptions = new CodecsLoadSvgOptions(); 
            loadSvgOptions.DropShapes = false; 
            loadSvgOptions.DropImages = true; 
            loadSvgOptions.DropShapes = true; 
            using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, pageNumber, loadSvgOptions) as SvgDocument) 
            { 
               // Sort requires a flat document, so check for that 
               if (!svgDocument.IsFlat) 
                  svgDocument.Flat(null); 
 
               if (!svgDocument.Bounds.IsValid) 
                  svgDocument.CalculateBounds(false); 
 
               SvgSortOptions sortOptions = new SvgSortOptions(); 
               sortOptions.ExtractText = SvgExtractText.Word; 
               sortOptions.SortFlags = SvgSortFlags.Default; 
               Console.WriteLine("Text for page {0}", pageNumber); 
               svgDocument.SortElements(sortOptions, sortCallback, writer); 
            } 
         } 
 
         // Show the text file 
         System.Diagnostics.Process.Start(dstFileName); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

SvgSortElementsCallback Members

Leadtools.Svg Namespace

Help Version 22.0.2023.4.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Svg Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.