←Select platform

LoadFromMemory Method

Summary
Creates an SvgDocument object from data saved in a memory buffer.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public static SvgDocument LoadFromMemory( 
   byte[] buffer, 
   int offset, 
   int length, 
   SvgLoadOptions options 
) 
- (nullable instancetype)initWithData:(NSData *)data 
                              options:(nullable LTSvgLoadOptions *)options 
                                error:(NSError **)error 
public static SvgDocument loadFromMemory(byte[] buffer, int offset, int length, SvgLoadOptions options) 
public: 
static SvgDocument^ LoadFromMemory(  
   array<byte>^ buffer, 
   int offset, 
   int length, 
   SvgLoadOptions^ options 
)  
def LoadFromMemory(self,buffer,offset,length,options): 

Parameters

buffer
Buffer containing the SVG data.

offset
0-based offset into the  buffer where the data begins.

length
Number of bytes to read.

options
Options to use during load. If this parameter is null, then a default SvgLoadOptions object will be used.

Return Value

The SvgDocument object this method creates.

Remarks

To get and set information about the document's bounds and resolution, refer to SVG Size, Bounds and Flat.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgLoadFromMemoryExample() 
{ 
   // Assume the SVG file is located here 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Page1.svg"); 
 
   // Load the file into memory 
   byte[] data = File.ReadAllBytes(srcFileName); 
 
   // Load the SVG 
   using (SvgDocument document = SvgDocument.LoadFromMemory(data, 0, data.Length, null)) 
   { 
      // Prepare it 
      if (!document.IsFlat) 
         document.Flat(null); 
      if (!document.Bounds.IsValid) 
         document.CalculateBounds(false); 
 
      // Show its properties 
      Console.WriteLine("Bounds: " + document.Bounds.Bounds); 
      Console.WriteLine("Resolution: " + document.Bounds.Resolution); 
   } 
} 
 
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 svgDocumentLoadFromMemoryExample() { 
   // Assume the SVG file is located here 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_ImagesDir, "Leadtools_pdf.svg"); 
   File file = new File(srcFileName); 
 
   // Load the file into memory 
   try (FileInputStream fis = new FileInputStream(file)) { 
      byte[] byteArray = new byte[(int) file.length()]; 
      fis.read(byteArray); 
 
      // Load the SVG 
      SvgDocument document = SvgDocument.loadFromMemory(byteArray, 0, byteArray.length, null); 
      // Prepare it 
      if (!document.isFlat()) 
         document.flat(null); 
      if (!document.getBounds().isValid()) 
         document.calculateBounds(false); 
 
      // Show its properties 
      System.out.printf("Bounds: %s%nResolution: %s%n%n", document.getBounds().getBounds(), 
            document.getBounds().getResolution()); 
      assertTrue(document != null); 
   } catch (Exception exception) { 
      exception.printStackTrace(); 
   } 
} 
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.