LoadSvg(string,int,CodecsLoadSvgOptions) Method (original) (raw)
Summary
Loads a page from an image, document or vector file as SVG
Syntax
C#
Objective-C
C++/CLI
Python
- (nullable id<ISvgDocument>)loadSvgFile:(NSString *)file
page:(NSInteger)_pageNumber_
options:(nullable LTCodecsLoadSvgOptions *)_options_
error:(NSError **)error
Parameters
fileName
The input file name.
pageNumber
1-based page number to load.
options
The options used for loading SVG. This can be null.
Return Value
SVG document representation of the page.
Example
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 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:\LEADTOOLS22\Resources\Images";
}
Leadtools.Codecs Assembly
CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method
CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method
CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method
CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method