public static SvgDocument LoadFromFile(string fileName,SvgLoadOptions options)
Public Shared Function LoadFromFile( _ByVal fileName As String, _ByVal options As SvgLoadOptions _) As SvgDocument
- (nullable instancetype)initWithFile:(NSString *)fileoptions:(nullable LTSvgLoadOptions *)optionserror:(NSError **)error
public:static SvgDocument^ LoadFromFile(String^ fileName,SvgLoadOptions^ options)
fileName
Path to the SVG file on disk
options
Options to use during load. If this parameter is null, then a default SvgLoadOptions object will be used.
The SvgDocument object this method creates.
To get and set information about the document's bounds and resolution, refer to SVG Size, Bounds and Flat.
This example will use Leadtools.Document.Writer.DocumentWriter to create a PDF file from SVG files.
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.Forms.DocumentWriters;using Leadtools.Svg;using LeadtoolsExamples.Common;public void SvgLoadFromFileExample(){// Create the SVG pages we will be usingstring srcFileName = Path.Combine(ImagesPath.Path, "Leadtools.doc");string dstFileName = Path.Combine(ImagesPath.Path, "Example.pdf");string outDir = Path.Combine(ImagesPath.Path, "TempSvgPages");if (!Directory.Exists(outDir))Directory.CreateDirectory(outDir);int pageCount = CreateSvgPages(srcFileName, outDir);// Create a PDF document using Document Writervar documentWriter = new DocumentWriter();documentWriter.BeginDocument(dstFileName, DocumentFormat.Pdf);string svgPageTemplateName = Path.Combine(outDir, "Page{0}.svg");for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++){// Load this SVGstring pageFileName = string.Format(svgPageTemplateName, pageNumber);Console.WriteLine("Loading {0}", pageFileName);using (SvgDocument svgDocument = SvgDocument.LoadFromFile(pageFileName, null)){// Check if we need to flat itif (!svgDocument.IsFlat)svgDocument.Flat(null);if (!svgDocument.Bounds.IsValid)svgDocument.CalculateBounds(false);// Add it to the document writerConsole.WriteLine("Adding ...");DocumentSvgPage svgPage = new DocumentSvgPage();svgPage.SvgDocument = svgDocument;documentWriter.AddPage(svgPage);}}// Finish upConsole.WriteLine("Finishing ...");documentWriter.EndDocument();}private static int CreateSvgPages(string srcFileName, string outDir){// Extract all the pages from the source file as SVGusing (var codecs = new RasterCodecs()){// Set 300 as the default value for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300;// Get all the files from input directoryint pageCount = codecs.GetTotalPages(srcFileName);for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++){using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, pageNumber, null) as SvgDocument){// Save it to diskstring dstFileName = Path.Combine(outDir, Path.Combine(string.Format("Page{0}.svg", pageNumber)));Console.WriteLine("Saving to {0}", dstFileName);svgDocument.SaveToFile(dstFileName, null);}}return pageCount;}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.Forms.DocumentWritersImports Leadtools.SvgPublic Shared Sub SvgLoadFromFileExample()' Create the SVG pages we will be usingDim srcFileName As String = Path.Combine(Common.ImagesPath.Path, "Leadtools.doc")Dim dstFileName As String = Path.Combine(Common.ImagesPath.Path, "Example.pdf")Dim outDir As String = Path.Combine(Common.ImagesPath.Path, "TempSvgPages")If Not Directory.Exists(outDir) ThenDirectory.CreateDirectory(outDir)End IfDim pageCount As Integer = CreateSvgPages(srcFileName, outDir)' Create a PDF document using Document WriterDim documentWriter As New DocumentWriter()documentWriter.BeginDocument(dstFileName, DocumentFormat.Pdf)Dim svgPageTemplateName As String = Path.Combine(outDir, "Page{0}.svg")For pageNumber As Integer = 1 To pageCount' Load this SVGDim pageFileName As String = String.Format(svgPageTemplateName, pageNumber)Console.WriteLine("Loading {0}", pageFileName)Using svgDocument As SvgDocument = svgDocument.LoadFromFile(pageFileName, Nothing)' Check if we need to flat itIf Not svgDocument.IsFlat ThensvgDocument.Flat(Nothing)End IfIf Not svgDocument.Bounds.IsValid ThensvgDocument.CalculateBounds(False)End If' Add it to the document writerConsole.WriteLine("Adding ...")Dim svgPage As New DocumentSvgPage()svgPage.SvgDocument = svgDocumentdocumentWriter.AddPage(svgPage)End UsingNext' Finish upConsole.WriteLine("Finishing ...")documentWriter.EndDocument()End SubPrivate Shared Function CreateSvgPages(srcFileName As String, outDir As String) As Integer' Extract all the pages from the source file as SVGUsing codecs As New RasterCodecs()' Set 300 as the default value for loading document filescodecs.Options.RasterizeDocument.Load.Resolution = 300' Get all the files from input directoryDim pageCount As Integer = codecs.GetTotalPages(srcFileName)For pageNumber As Integer = 1 To pageCountUsing svgDocument As SvgDocument = DirectCast(codecs.LoadSvg(srcFileName, pageNumber, Nothing), SvgDocument)' Save it to diskDim dstFileName As String = Path.Combine(outDir, Path.Combine(String.Format("Page{0}.svg", pageNumber)))Console.WriteLine("Saving to {0}", dstFileName)svgDocument.SaveToFile(dstFileName, Nothing)End UsingNextReturn pageCountEnd UsingEnd Function
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
