Creates an SvgDocument object from an SVG file on disk.
public static Leadtools.Svg.SvgDocument LoadFromFile(string fileName,Leadtools.Svg.SvgLoadOptions options)
Public Shared Function LoadFromFile( _ByVal fileName As String, _ByVal options As Leadtools.Svg.SvgLoadOptions _) As Leadtools.Svg.SvgDocument
- (nullable instancetype)initWithFile:(NSString *)fileoptions:(nullable LTSvgLoadOptions *)optionserror:(NSError **)error
public:static Leadtools.Svg.SvgDocument^ LoadFromFile(String^ fileName,Leadtools.Svg.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.Forms.DocumentWriters.DocumentWriter to create a PDF file from SVG files.
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
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.Forms.DocumentWriters;using Leadtools.Svg;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;}}
|
Products |
Support |
Feedback: LoadFromFile Method - Leadtools.Svg |
Introduction |
Help Version 19.0.2017.3.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.