←Select platform

Dispose() Method

Summary
Releases all resources used by this SvgDocument.
Syntax
C#
C++/CLI
Java
Python
public void Dispose() 
public synchronized void dispose() 
public: 
void Dispose();  
def Dispose(self): 
Remarks

The SvgDocument class implements the System.IDisposable interface. It is best to follow the standard .NET dispose pattern when using the SvgDocument class. For more information, refer to the System.IDisposable interface documentation in MSDN.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgDocumentExample() 
{ 
   // 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)) 
      { 
         Console.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); 
                     Console.WriteLine("Saving to {0}", dstFileName); 
                     svgDocument.SaveToFile(dstFileName, null); 
                  } 
               } 
               catch (Exception ex) 
               { 
                  Console.WriteLine(ex.Message); 
               } 
            } 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
import java.io.PrintStream; 
import java.nio.file.FileVisitOption; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.util.stream.Stream; 
 
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.document.writer.*; 
import leadtools.svg.*; 
 
 
public void svgDocumentExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // input directory 
   String inDir = LEAD_VARS_ImagesDir; 
   // output directory 
   String outDir = combine(LEAD_VARS_ImagesDir, "svgpages"); 
   File outDirr = new File(outDir); 
   if (!outDirr.exists()) { 
      outDirr.mkdirs(); 
   } 
   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 
   try (Stream<Path> stream = Files.walk(Paths.get(inDir), FileVisitOption.FOLLOW_LINKS) 
         .filter(Files::isRegularFile)) { 
      stream.forEach(file -> { 
         System.out.println("Checking " + file.toString()); 
         CodecsImageInfo info = codecs.getInformation(file.toString(), 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 
 
            SvgDocument svgDocument = (SvgDocument) codecs.loadSvg(file.toString(), 1, null); 
            // Change file extension 
            int i = file.getFileName().toString().lastIndexOf('.'); 
            String dstFileName = outDirr.toString() + "-" + file.getFileName().toString().substring(0, i) + ".svg"; 
            // Save the file 
            System.out.println("Saving to " + dstFileName); 
            svgDocument.saveToFile(dstFileName, null); 
            assertTrue(new File(dstFileName).exists()); 
         } 
      }); 
   } catch (Exception e) { 
      e.printStackTrace(); 
   } 
 
} 

.

Requirements

Target Platforms

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

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