←Select platform

CanLoadSvg(Stream) Method

Summary
Determines whether specified image, document or vector stream can be loaded as SVG.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool CanLoadSvg( 
   Stream stream 
) 
- (BOOL)canLoadSvgStream:(LTLeadStream *)svgStream error:(NSError **)error 
public boolean canLoadSvg(ILeadStream stream) 
public: 
bool CanLoadSvg(  
   Stream^ stream 
)  
def CanLoadSvg(self,stream): 

Parameters

stream
The input stream.

Return Value

true if the specified image, document or vector file can be loaded as SVG, otherwise; false.

Remarks

Use this method to determine if the specified image, document or vector file supports loading as SVG (Scalable Vector Graphics). The following conditions must be met to load a page from a file as SVG:

Condition Description
The file format is SVG

SVG can be loaded as SVG

The file format is document

Any of the document file formats supported by LEADTOOLS such DOCX/DOC, PPTX/PPT, XLSX/XLS, RTF, TXT, AFP, ICA, etc. These formats will set the CodecsDocumentImageInfo.IsDocumentFile property to true when calling GetInformation

The file format is vector

Any of the vector file formats supported by LEADTOOLS such as DXF, DWG, etc. These formats will set the CodecsVectorImageInfo.IsVectorFile property to true when calling GetInformation

The file format is PDF

And the PDF file contains more than pure raster data (for example, not scanned PDF file).

In addition to the usual format filter assembly (Leadtools.Codecs.*), The following additional assemblies may be required to support loading as SVG

Assembly Description
Leadtools.Svg

SVG support. Always required

Leadtools.Vector

Required if the input document is a vector file

Leadtools.Pdf

Required if the input document is a PDF file

To determine whether a file can be loaded as SVG, use CanLoadSvg(string fileName).

To load a page as SVG from a file or stream, use LoadSvg(string fileName, int pageNumber, CodecsLoadSvgOptions options) or LoadSvg(Stream stream, int pageNumber, CodecsLoadSvgOptions options).

To load as SVG asynchronously, use LoadSvgAsync.

For more information, refer to Working With SVG.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void LoadSvgExample() 
{ 
   // input directory 
   string inDir = LEAD_VARS.ImagesDir; 
   // output directory 
   string outDir = Path.Combine(LEAD_VARS.ImagesDir, "svgpages"); 
   if (!Directory.Exists(outDir)) 
      Directory.CreateDirectory(outDir); 
 
   using (var codecs = new RasterCodecs()) 
   { 
      // Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
      codecs.ThrowExceptionsOnInvalidImages = false; 
 
      // Get all the files from input directory 
      foreach (var srcFileName in Directory.EnumerateFiles(inDir)) 
      { 
         codecs.CanLoadSvg(srcFileName); 
         // codecs.CanLoadSvg(stream); 
         Debug.WriteLine("Checking {0}", srcFileName); 
         using (var info = codecs.GetInformation(srcFileName, false)) 
         { 
            // We can load as SVG if its document or vector (skipping SVG files themselves) 
            if (info.Format != RasterImageFormat.Unknown && // valid format 
               info.Format != RasterImageFormat.Svg && // not svg 
               (info.Document.IsDocumentFile || // a document 
               info.Vector.IsVectorFile)) // or vector 
            { 
               // try to load the first page as SVG 
               try 
               { 
                  using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument) 
                  { 
                     // Save it to disk 
                     string name = Path.GetFileName(srcFileName).Replace(".", "-"); 
                     name = Path.ChangeExtension(name, "svg"); 
                     string dstFileName = Path.Combine(outDir, name); 
                     Debug.WriteLine("Saving to {0}", dstFileName); 
                     svgDocument.SaveToFile(dstFileName, null); 
                  } 
               } 
               catch (Exception ex) 
               { 
                  Debug.WriteLine(ex.Message); 
               } 
            } 
         } 
      } 
   } 
} 
 
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.*; 
 
 
public void loadSvgExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String outDir = combine(LEAD_VARS_IMAGES_DIR, "svgpages"); 
 
   File outDirFile = new File(outDir); 
   if (!outDirFile.exists()) 
      outDirFile.createNewFile(); 
 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Set 300 as the default value for loading document files 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
 
   codecs.setThrowExceptionsOnInvalidImages(false); 
 
   // Get all the files from input directory 
   File inDirFile = new File(LEAD_VARS_IMAGES_DIR); 
   for (String srcFileName : inDirFile.list()) { 
      codecs.canLoadSvg(srcFileName); 
      // codecs.CanLoadSvg(stream); 
      System.out.println("Checking " + srcFileName); 
      CodecsImageInfo info = codecs.getInformation(srcFileName, false); 
      // We can load as SVG if its document or vector (skipping SVG files themselves) 
      if (info.getFormat() != RasterImageFormat.UNKNOWN && // valid format 
            info.getFormat() != RasterImageFormat.SVG && // not svg 
            (info.getDocument().isDocumentFile() || // a document 
                  info.getVector().isVectorFile())) // or vector 
      { 
         // try to load the first page as SVG 
         try { 
            SvgDocument svgDocument = (SvgDocument) codecs.loadSvg(srcFileName, 1, null); 
 
            // Save it to disk 
 
            String name = srcFileName.replace(".", "-"); 
            name = name + ".svg"; 
            String dstFileName = combine(outDir, name); 
            System.out.println("Saving to " + dstFileName); 
            svgDocument.saveToFile(dstFileName, null); 
 
         } catch (Exception ex) { 
            System.out.println(ex.getMessage()); 
         } 
      } 
   } 
} 
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.