Asynchronously loads a page from a stream containing an image, document or vector file as SVG.
public static Task<ISvgDocument> LoadSvgAsync(
this RasterCodecs rasterCodecs,
ILeadStream stream,
int pageNumber,
CodecsLoadSvgOptions options
)
rasterCodecs
RasterCodecs object to perform the operation.
stream
The stream containing the image data to load.
pageNumber
The 1-based page number.
options
The options used for loading SVG. This can be null.
A Task
that represents the asynchronous operation. TResult
: The SVG document representation of the page.
This topic is part of RasterCodecs
support for .NET async/await
support. Refer to RasterCodecs Async Operations for more information.
Use this method to load a page from any supported image, document or vector file as SVG (Scalable Vector Graphics). For more information refer LoadSvg(string fileName, int pageNumber, CodecsLoadSvgOptionsOptions).
To determine whether a file or stream can be loaded as SVG, use CanLoadSvgAsync.
To load as SVG from a file or stream directly, use LoadSvg.
For more information, refer to Working With SVG.
This example will load a page from a URL as SVG:
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;
using LeadtoolsExamples.Common;
public async void LoadSvg_AsyncExample()
{
// For .NET Framework: Add a reference to Leadtools.Async to get the async support as extension methods
// For .NET Standard: async support is included.
// Address of a document thats supports loading as SVG, for example, a PDF file
string address = @"https://demo.leadtools.com/images/pdf/leadtools.pdf";
Uri uri = new Uri(address);
using (RasterCodecs codecs = new RasterCodecs())
{
// Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300;
// Create an ILeadStream object to the URI
using (ILeadStream leadStream = await LeadStream.Factory.FromUri(uri))
{
// Load the first page as SVG
using (ISvgDocument svg = await codecs.LoadSvgAsync(leadStream, 1, null))
{
Console.WriteLine("Loading from {0} is done", uri);
// Cast the generic ISvgDocument interface it to SvgDocument so we can use it.
SvgDocument svgDocument = svg as SvgDocument;
// Show its size
if (!svgDocument.Bounds.IsValid)
svgDocument.CalculateBounds(false);
Console.WriteLine("Bounds: {0}", svgDocument.Bounds.Bounds);
svgDocument.Dispose();
}
}
}
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing
Imports Leadtools.Svg
Public Async Sub LoadSvg_AsyncExample()
' For .NET Framework: Add a reference To Leadtools.Async To Get the async support As extension methods
' For .NET Standard Async support Is included.
' Address of a document thats supports loading as SVG, for example, a PDF file
Dim address As String = "https://demo.leadtools.com/images/pdf/leadtools.pdf"
Dim uri As New Uri(address)
Using codecs As New RasterCodecs
' Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300
' Create an ILeadStream object to the URI
Using stream As ILeadStream = Await LeadStream.Factory.FromUri(uri)
' Load the first page as SVG
Using svg As ISvgDocument = Await codecs.LoadSvgAsync(stream, 1, Nothing)
Console.WriteLine("Loading from {0} is done", uri)
' Cast the generic ISvgDocument interface it to SvgDocument so we can use it.
Dim SvgDocument As SvgDocument = DirectCast(svg, SvgDocument)
' Show its size
If Not SvgDocument.Bounds.IsValid Then
SvgDocument.CalculateBounds(False)
End If
Console.WriteLine("Bounds: {0}", SvgDocument.Bounds.Bounds)
SvgDocument.Dispose()
End Using
End Using
End Using
End Sub
For .NET Framework: A reference to the Leadtools.Async.dll assembly is required to use this functionality.
For .NET Standard: This functionality is included in the Leadtools.Codecs.dll assembly.
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
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.