←Select platform

GetObjectData Method

Summary
Populates a specified System.Runtime.Serialization.SerializationInfo with the data needed to serialize this object.
Syntax
C#
C++/CLI
Python
public virtual void GetObjectData( 
   SerializationInfo info, 
   StreamingContext context 
) 
public: 
virtual void GetObjectData(  
   SerializationInfo^ info, 
   StreamingContext context 
)  
def GetObjectData(self,info,context): 

Parameters

info
The System.Runtime.Serialization.SerializationInfo to populate with data.

context
The contextual information about the source or destination of the serialization.

Remarks

This method implements System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)

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.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgDocumentSerializationExample() 
{ 
   SvgDocument document = null; 
 
   // Load a page from a document file as SVG 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "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(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
import java.io.PrintStream; 
import java.nio.file.FileVisitOption; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.util.stream.Stream; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.svg.*; 
 
 
public void svgDocumentSerializationExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // Load a page from a document file as SVG 
   String srcFileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
 
   RasterCodecs codecs = new RasterCodecs(); 
   // Set 300 as the default value for loading document files 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
   SvgDocument document = (SvgDocument) codecs.loadSvg(srcFileName, 1, null); 
 
   // Prepare it 
   if (!document.isFlat()) 
      document.flat(null); 
   if (!document.getBounds().isValid()) 
      document.calculateBounds(false); 
 
   // Show its properties 
   System.out.println("Before serialization"); 
   System.out.printf("Bounds: %s%nResolution: %s%n%n", document.getBounds().getBounds(), 
         document.getBounds().getResolution()); 
 
   // Serialize (save) it to a stream 
   byte[] serializedObject = null; 
   try (ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
         ObjectOutputStream objectOutputStream = new ObjectOutputStream(outStream)) { 
 
      objectOutputStream.writeObject(document); 
      objectOutputStream.flush(); 
 
      serializedObject = outStream.toByteArray(); 
   } catch (Exception e) { 
      e.printStackTrace(); 
   } 
 
   // Dispose of the document 
   document.dispose(); 
 
   // Deserialize the object from the byte array 
   SvgDocument deserializedDocument = null; 
   try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(serializedObject); 
         ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) { 
 
      deserializedDocument = (SvgDocument) objectInputStream.readObject(); 
   } catch (Exception e) { 
      e.printStackTrace(); 
   } 
 
   // Display the properties of the deserialized object 
   System.out.println("After de-serialization"); 
   System.out.println("Bounds: " + deserializedDocument.getBounds().getBounds()); 
   System.out.println("Resolution: " + deserializedDocument.getBounds().getResolution()); 
   assertTrue(deserializedDocument.getBounds().getBounds() != null); 
 
   // Dispose of the deserialized document 
   deserializedDocument.dispose(); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.23
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Svg Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.