←Select platform

DropImages Property

Summary

Gets or sets a value that indicates whether the image elements of the SVG should be dropped during load.

Syntax
C#
VB
Java
Objective-C
C++
public bool DropImages { get; set; } 
Public Property DropImages As Boolean 
@property (nonatomic, assign) BOOL dropImages 
public boolean getDropImages() 
public void setDropImages(boolean value) 
public: 
property bool DropImages { 
   bool get(); 
   void set (    bool ); 
} 

Property Value

true if image elements of the SVG should be dropped during load, otherwise; false. Default value is false.

Remarks

Creating an SVG document with text only is desired in certain scenarios. For example, if the application loads SVG document to parse the text values and store them in an external database for text search purposes, then setting the value of DropImages and DropShapes to true while leaving DropText as false will speed up the loading operation and elements not required will be discarded. This is especially useful if the original SVG document contains image elements which may use a lot of memory and disk space.

Example

This example will parse the text found in a PDF document and write it to the console.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
 
public static void CodecsLoadSvgOptionsExample() 
{ 
   // The source PDF file 
   string srcFileName = Path.Combine(ImagesPath.Path, "Leadtools.pdf"); 
 
   // SVG sort callback handler 
   SvgSortElementsCallback sortCallback = (callabackDocument, info, userData) => 
   { 
      // Is it text? 
      SvgTextData textData = info.TextData; 
      if (textData != null) 
      { 
         // Yes, print it to the console 
         Console.Write(textData.Text + " "); 
 
         // See if its end of line 
         var len = textData.Text.Length; 
         if ((textData.CharacterFlags[len - 1] & SvgTextCharacterFlags.EndOfLine) == SvgTextCharacterFlags.EndOfLine) 
            Console.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); 
 
      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.DropText = 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, null); 
            Console.WriteLine("-------------"); 
         } 
      } 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Public Shared Sub CodecsLoadSvgOptionsExample() 
   ' The source PDF file 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
 
   ' SVG sort callback handler 
   Dim sortCallback As SvgSortElementsCallback = 
      Function(document As SvgDocument, info As SvgElementInfo, userData As Object) As Boolean 
         ' Is it text? 
         Dim textData As SvgTextData = info.TextData 
         If Not IsNothing(textData) Then 
            ' Yes, print it to the console 
            Console.Write(textData.Text + " ") 
 
            ' See if its end of line 
            Dim len As Integer = textData.Text.Length 
            If (textData.CharacterFlags(len - 1) And SvgTextCharacterFlags.EndOfLine) = SvgTextCharacterFlags.EndOfLine Then 
               Console.WriteLine() 
            End If 
         End If 
 
         Return True 
      End Function 
 
   Using codecs As New RasterCodecs() 
      ' Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300 
 
      ' get the number of pages 
      Dim pageCount As Integer = codecs.GetTotalPages(srcFileName) 
 
      For pageNumber As Integer = 1 To pageCount 
         ' Load this page as SVG, we are interested in the text only so 
         ' we will ask LEADTOOLS to skip other elements 
         Dim loadSvgOptions As New CodecsLoadSvgOptions() 
         loadSvgOptions.DropText = False 
         loadSvgOptions.DropImages = True 
         loadSvgOptions.DropShapes = True 
         Using svgDocument As SvgDocument = DirectCast(codecs.LoadSvg(srcFileName, pageNumber, Nothing), SvgDocument) 
 
            ' Sort requires a flat document, so check for that 
            If Not svgDocument.IsFlat Then 
               svgDocument.Flat(Nothing) 
            End If 
 
            If Not svgDocument.Bounds.IsValid Then 
               svgDocument.CalculateBounds(False) 
            End If 
 
            Dim sortOptions As New SvgSortOptions() 
            sortOptions.ExtractText = SvgExtractText.Word 
            sortOptions.SortFlags = SvgSortFlags.Default 
            Console.WriteLine("Text for page {0}", pageNumber) 
            svgDocument.SortElements(sortOptions, sortCallback, Nothing) 
            Console.WriteLine("-------------") 
         End Using 
      Next 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

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

Leadtools.Codecs Assembly