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 *)file
options:(nullable LTSvgLoadOptions *)options
error:(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 Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Svg
Public Shared Sub SvgLoadFromFileExample()
' Create the SVG pages we will be using
Dim 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) Then
Directory.CreateDirectory(outDir)
End If
Dim pageCount As Integer = CreateSvgPages(srcFileName, outDir)
' Create a PDF document using Document Writer
Dim 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 SVG
Dim 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 it
If Not svgDocument.IsFlat Then
svgDocument.Flat(Nothing)
End If
If Not svgDocument.Bounds.IsValid Then
svgDocument.CalculateBounds(False)
End If
' Add it to the document writer
Console.WriteLine("Adding ...")
Dim svgPage As New DocumentSvgPage()
svgPage.SvgDocument = svgDocument
documentWriter.AddPage(svgPage)
End Using
Next
' Finish up
Console.WriteLine("Finishing ...")
documentWriter.EndDocument()
End Sub
Private Shared Function CreateSvgPages(srcFileName As String, outDir As String) As Integer
' Extract all the pages from the source file as SVG
Using codecs As New RasterCodecs()
' Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300
' Get all the files from input directory
Dim pageCount As Integer = codecs.GetTotalPages(srcFileName)
For pageNumber As Integer = 1 To pageCount
Using svgDocument As SvgDocument = DirectCast(codecs.LoadSvg(srcFileName, pageNumber, Nothing), SvgDocument)
' Save it to disk
Dim 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 Using
Next
Return pageCount
End Using
End 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 using
string 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 Writer
var 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 SVG
string pageFileName = string.Format(svgPageTemplateName, pageNumber);
Console.WriteLine("Loading {0}", pageFileName);
using (SvgDocument svgDocument = SvgDocument.LoadFromFile(pageFileName, null))
{
// Check if we need to flat it
if (!svgDocument.IsFlat)
svgDocument.Flat(null);
if (!svgDocument.Bounds.IsValid)
svgDocument.CalculateBounds(false);
// Add it to the document writer
Console.WriteLine("Adding ...");
DocumentSvgPage svgPage = new DocumentSvgPage();
svgPage.SvgDocument = svgDocument;
documentWriter.AddPage(svgPage);
}
}
// Finish up
Console.WriteLine("Finishing ...");
documentWriter.EndDocument();
}
private static int CreateSvgPages(string srcFileName, string outDir)
{
// Extract all the pages from the source file as SVG
using (var codecs = new RasterCodecs())
{
// Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300;
// Get all the files from input directory
int pageCount = codecs.GetTotalPages(srcFileName);
for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++)
{
using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, pageNumber, null) as SvgDocument)
{
// Save it to disk
string 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.