←Select platform

SaveToStream Method

Summary
Saves this SvgDocument to a stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SaveToStream( 
   Stream stream, 
   SvgSaveOptions options 
) 
- (BOOL)saveToStream:(LTLeadStream *)stream options:(nullable LTSvgSaveOptions *)options error:(NSError **)error NS_SWIFT_NAME(save(to:options:)); 
public void saveToStream(OutputStream stream, SvgSaveOptions options) 
public: 
void SaveToStream(  
   Stream^ stream, 
   SvgSaveOptions^ options 
)  
def SaveToStream(self,stream,options): 

Parameters

stream
Output stream.

options
Save option. Can be null.

Remarks

This method will save this SvgDocument to the output stream as a standard SVG document. Use Version to control the SVG version used.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgToStreamExample() 
{ 
   // Assume the SVG file is located here 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Page1.svg"); 
 
   Stream stream = new MemoryStream(); 
 
   // Load the SVG from file 
   using (SvgDocument document = SvgDocument.LoadFromFile(srcFileName, null)) 
   { 
      ShowSvgProperties("Original", document); 
 
      // Set the version and save it to a stream 
      document.Version = SvgVersion.v10; 
      document.SaveToStream(stream, null); 
      stream.Position = 0; 
   } 
 
   // Load the SVG from stream and show its properties 
   using (SvgDocument document = SvgDocument.LoadFromStream(stream, null)) 
   { 
      ShowSvgProperties("Loaded from stream", document); 
   } 
 
   stream.Dispose(); 
} 
 
private static void ShowSvgProperties(string message, SvgDocument document) 
{ 
   // Prepare it 
   if (!document.IsFlat) 
      document.Flat(null); 
   if (!document.Bounds.IsValid) 
      document.CalculateBounds(false); 
 
   // Show its properties 
   Console.WriteLine(message); 
   Console.WriteLine(" Version: " + document.Version); 
   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 svgDocumentSaveToStreamExample() { 
   // Assume the SVG file is located here 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_ImagesDir, "Leadtools_pdf.svg"); 
 
   // Load the SVG from file 
   try (ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
         ObjectOutputStream objectOutputStream = new ObjectOutputStream(outStream)) { 
      SvgDocument document = SvgDocument.loadFromFile(srcFileName, null); 
 
      showSvgProperties("Original", document); 
      // Set the version and save it to a stream 
      document.setVersion(SvgVersion.V10); 
      document.saveToStream(objectOutputStream, null); 
      objectOutputStream.flush(); 
      byte[] byteArray = outStream.toByteArray(); 
 
      ByteArrayInputStream inStream = new ByteArrayInputStream(byteArray); 
      ObjectInputStream objectInputStream = new ObjectInputStream(inStream); 
 
      // Load the SVG from stream and show its properties 
      SvgDocument document2 = SvgDocument.loadFromStream(objectInputStream, null); 
      showSvgProperties("Loaded from stream", document2); 
   } catch (Exception exception) { 
      exception.printStackTrace(); 
   } 
 
} 
 
private static void showSvgProperties(String message, SvgDocument document) { 
   // Prepare it 
   if (!document.isFlat()) 
      document.flat(null); 
   if (!document.getBounds().isValid()) 
      document.calculateBounds(false); 
 
   // Show its properties 
   System.out.println(message); 
   System.out.println(" Version: " + document.getVersion()); 
   System.out.println(" Bounds: " + document.getBounds().getBounds()); 
   System.out.println(" Resolution: " + document.getBounds().getResolution()); 
} 
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.