←Select platform

CodecsLoadSvgOptions Class

Summary
Provides the options used when loading documents as SVG.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class CodecsLoadSvgOptions 
@interface LTCodecsLoadSvgOptions : NSObject<NSCopying, NSSecureCoding> 
public class CodecsSvgLoadOptions 
public ref class CodecsLoadSvgOptions  
class CodecsLoadSvgOptions: 
Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void CodecsLoadSvgOptionsExample() 
{ 
   // The source PDF file 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "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) 
            Debug.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; 
            Debug.WriteLine("Text for page {0}", pageNumber); 
            svgDocument.SortElements(sortOptions, sortCallback, null); 
            Debug.WriteLine("-------------"); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
SvgSortElementsCallback sortCallback = new SvgSortElementsCallback() { 
 
   @Override 
   public boolean onSort(SvgDocument callbackDocument, SvgElementInfo info, Object userData) { 
      try { 
         // Is it text? 
         SvgTextData textData = info.getTextData(); 
         if (textData != null) { 
            // Yes, print it to the console 
            System.out.println(textData.getText() + " "); 
 
            // See if its end of line 
            var len = textData.getText().length(); 
            if (textData.getCharacterFlags()[len - 1] == SvgTextCharacterFlags.END_OF_LINE.getValue()) 
               System.out.println(" "); 
         } 
         return true; 
      } catch (Exception e) { 
         System.out.println("Current Page doesn't contain text (null)"); 
         return true; 
      } 
   } 
 
}; 
 
public void codecsLoadSvgOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"); 
   ILeadStream srcFileStream = LeadStreamFactory.create(srcFileName); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Set 300 as the default value for loading document files 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
 
   // get the number of pages 
   int pageCount = codecs.getTotalPages(srcFileName); 
 
   for (int pageNumber = 2; 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.setDropText(false); 
      loadSvgOptions.setDropImages(true); 
      loadSvgOptions.setDropShapes(true); 
      SvgDocument svgDocument = (SvgDocument) codecs.loadSvg(srcFileName, pageNumber, loadSvgOptions); 
 
      // Sort requires a flat document, so check for that 
      if (!svgDocument.isFlat()) 
         svgDocument.flat(null); 
 
      if (!svgDocument.getBounds().isValid()) 
         svgDocument.calculateBounds(false); 
 
      SvgSortOptions sortOptions = new SvgSortOptions(); 
      sortOptions.setExtractText(SvgExtractText.WORD.getValue()); 
      sortOptions.setSortFlags(SvgSortFlags.DEFAULT.getValue()); 
      System.out.println("Text for page " + pageNumber); 
      svgDocument.sortElements(sortOptions, sortCallback, srcFileStream); 
      System.out.println("-------------"); 
   } 
} 
Requirements

Target Platforms

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

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