This constructor is required by System.Runtime.Serialization.ISerializable
protected SvgDocument(
SerializationInfo info,
StreamingContext context
)
info
The data needed to serialize or deserialize an object.
context
The source and destination of a given serialized stream.
The SvgDocument class supports standard .NET serialization. Serialization of a SvgDocument is the process of converting the state of a Leadtools.RasterImage object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an Leadtools.RasterImage object. Together, these processes allow the image data to be easily stored and transferred.
When you serialize a SvgDocument object, all the data inside the object is saved. The SvgDocument can be reconstructed back to its original state from the stream.
This example will show how to serialize and deserialize a SVG document.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.Forms.DocumentWriters;
using Leadtools.Svg;
using LeadtoolsExamples.Common;
public void SvgDocumentSerializationExample()
{
SvgDocument document = null;
// Load a page from a document file as SVG
string srcFileName = Path.Combine(ImagesPath.Path, "Leadtools.pdf");
using (var codecs = new RasterCodecs())
{
// Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300;
document = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument;
}
// Prepare it
if (!document.IsFlat)
document.Flat(null);
if (!document.Bounds.IsValid)
document.CalculateBounds(false);
// Show its properties
Console.WriteLine("Before serialization");
Console.WriteLine("Bounds: " + document.Bounds.Bounds);
Console.WriteLine("Resolution: " + document.Bounds.Resolution);
// Serialize (save) it to a stream
var stream = new MemoryStream();
var formatter = new BinaryFormatter();
formatter.Serialize(stream, document);
stream.Position = 0;
// Get rid of the document
document.Dispose();
// Now de-serailize (load) it back from the stream and show its properties
document = formatter.Deserialize(stream) as SvgDocument;
Console.WriteLine("After de-serialization");
Console.WriteLine("Bounds: " + document.Bounds.Bounds);
Console.WriteLine("Resolution: " + document.Bounds.Resolution);
document.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.Forms.DocumentWriters
Imports Leadtools.Svg
Public Shared Sub SvgDocumentSerializationExample()
Dim document As SvgDocument = Nothing
' Load a page from a document file as SVG
Dim srcFileName As String = Path.Combine(Common.ImagesPath.Path, "Leadtools.pdf")
Using codecs As New RasterCodecs()
' Set 300 as the default value for loading document files
codecs.Options.RasterizeDocument.Load.Resolution = 300
document = DirectCast(codecs.LoadSvg(srcFileName, 1, Nothing), SvgDocument)
End Using
' Prepare it
If Not document.IsFlat Then
document.Flat(Nothing)
End If
If Not document.Bounds.IsValid Then
document.CalculateBounds(False)
End If
' Show its properties
Console.WriteLine("Before serialization")
Console.WriteLine("Bounds: " + document.Bounds.Bounds.ToString())
Console.WriteLine("Resolution: " + document.Bounds.Resolution.ToString())
' Serialize (save) it to a stream
Dim stream As New MemoryStream()
Dim formatter As New BinaryFormatter()
formatter.Serialize(stream, document)
stream.Position = 0
' Get rid of the document
document.Dispose()
' Now de-serailize (load) it back from the stream and show its properties
document = DirectCast(formatter.Deserialize(stream), SvgDocument)
Console.WriteLine("After de-serialization")
Console.WriteLine("Bounds: " + document.Bounds.Bounds.ToString())
Console.WriteLine("Resolution: " + document.Bounds.Resolution.ToString())
document.Dispose()
End Sub
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.