public ISvgDocument LoadSvg(string fileName,int pageNumber,CodecsLoadSvgOptions options)
- (nullable id<ISvgDocument>)loadSvgFile:(NSString *)filepage:(NSInteger)pageNumberoptions:(nullable LTCodecsLoadSvgOptions *)optionserror:(NSError **)error
public:ISvgDocument^ LoadSvg(String^ fileName,int pageNumber,CodecsLoadSvgOptions^ options)
def LoadSvg(self,options):
fileName
The input file name.
pageNumber
1-based page number to load.
options
The options used for loading SVG. This can be null.
SVG document representation of the page.
Use this method to load a page from any supported image, document or vector file 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). |
To find out if an input file can be loaded as SVG, use the CanLoadSvg method.
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 |
Usually, the returned ISvgDocument is to be casted to Leadtools.Svg.SvgDocument to continue working with the other SVG features, such as retrieving its data, rendering it to a target or saving it to a separate file.
You must check the result SVG document flatness and perform the necessary operation before continuing.
To determine whether a file or stream can be loaded as SVG, use CanLoadSvg(string fileName) or CanLoadSvg(Stream stream).
To load as SVG from a stream, use LoadSvg(Stream stream, int pageNumber, CodecsLoadSvgOptions options).
To load as SVG asynchronously, use LoadSvgAsync.
For more information, refer to Working With SVG.
This example will check a folder of document and images files for SVG support then loads the first page of each supported file and saves the result SVG.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;public void LoadSvgExample(){// input directorystring inDir = LEAD_VARS.ImagesDir;// output directorystring 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 filescodecs.Options.RasterizeDocument.Load.Resolution = 300;codecs.ThrowExceptionsOnInvalidImages = false;// Get all the files from input directoryforeach (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 formatinfo.Format != RasterImageFormat.Svg && // not svg(info.Document.IsDocumentFile || // a documentinfo.Vector.IsVectorFile)) // or vector{// try to load the first page as SVGtry{using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument){// Save it to diskstring 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:\LEADTOOLS22\Resources\Images";}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
