←Select platform

LoadSvgAsync(RasterCodecs,ILeadStream,int,CodecsLoadSvgOptions) Method

Summary

Asynchronously loads a page from a stream containing an image, document or vector file as SVG.

Syntax
C#

Parameters

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.

Return Value

A Task that represents the asynchronous operation. TResult: The SVG document representation of the page.

Remarks

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.

Example

This example will load a page from a URL as SVG:

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
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)) 
         { 
            Debug.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); 
 
            Debug.WriteLine("Bounds: {0}", svgDocument.Bounds.Bounds); 
            svgDocument.Dispose(); 
         } 
      } 
   } 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
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.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void loadSvgAsyncExample() throws URISyntaxException, IOException { 
   // 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); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Set 300 as the default value for loading document files 
   codecs.getOptions().getRasterizeDocument().getLoad().setResolution(300); 
 
   // Create an ILeadStream object to the URI - await 
   ILeadStream leadStream = LeadStreamFactory.create(uri); 
 
   // Load the first page as SVG - await 
   codecs.addLoadSvgAsyncCompletedListener(new CodecsLoadSvgAsyncCompletedListener() { 
 
      @Override 
      public void onLoadSvgAsyncCompleted(CodecsLoadSvgAsyncCompletedEvent e) { 
         System.out.println("Loading is done"); 
 
         // Cast the generic ISvgDocument interface it to SvgDocument so we can use it. 
         SvgDocument svgDocument = (SvgDocument) e.getDocument(); 
 
         // Show its size 
         if (!svgDocument.getBounds().isValid()) 
            svgDocument.calculateBounds(false); 
 
         System.out.printf("Bounds: %s%n" + svgDocument.getBounds().getBounds()); 
         svgDocument.dispose(); 
      } 
 
   }); 
   codecs.loadSvgAsync(leadStream, 1, null, null); 
   leadStream.close(); 
 
} 
Requirements

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.

Target Platforms

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

Leadtools.Codecs Assembly

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