←Select platform

GetSvg Method


Gets this page as an SVG document with the specified options.

public SvgDocument getSvg(CodecsLoadSvgOptions options) 
def GetSvg(self,options): 



Options to use when creating the SVG document. It can be used to drop images, text or shapes from the returned document

if they are not needed. If this value can is null, then the SVG document is returned as is without modifications.

Return Value

The SVG document of this page if found or null.


GetSvg is used to get an SVG document representation of this page. Not all document types support this method, this depends on the value of DocumentImages.IsSvgSupported.

SetSvg is used to replace the SVG document of the page. IsSvgModified is used to as flag that indicates that the SVG document of this page has been replaced by the user.

The options parameter controls how the SVG document is generated. A common use is to load the SVG without any image elements that may contain large embedded data. This data is Base64 encoded which result in even bigger memory size for the SVG data. One workaround for this is to use DropImages in options. The result SVG document will only contain the text and vector shapes and will a small memory footprint. Then, GetSvgBackImage can be called to return a raster image that contain the dropped image elements separately.

This method works as follows (the "item" is an SVG document with the specified options):

  1. If this document does not support SVG (the value of DocumentImages.IsSvgSupported is false), then this method will return null.

  2. If an item was found in the cache, it is returned right away. This is available if the document was created using the cache system. and LEADDocument.CacheOptions contains DocumentCacheOptions.PageSvg.

  3. If this is an original page in the source document file (the value of OriginalPageNumber is not -1), then RasterCodecs is used to load the SvgDocument object from the original page using RasterCodecs.LoadSvg.

  4. If this is not an original page in the source document file (the value of OriginalPageNumber is not 1), then a new SvgDocument object is created based on the page size and resolution and the default values in DocumentImages.

  5. If this document uses the cache system (LEADDocument.HasCache is true), then the SvgDocument object is saved to the cache before it is returned. Next time this method is called, the SVG will be returned from the cache directly without loading it from the file or creating a new instance.

Note that if SetSvg has been previously called with a null object for the svg parameter, then this method will return null as well.

In all cases, the returned SvgDocument object is not used by this LEADDocument, the user is responsible for deleting it using SvgDocument.Dispose after it has been used.

If the value of ImageScale is a value greater than 1, then the result SVG document will have a size that is equal to Size / ImageScale.

The LEADTOOLS Document Viewer uses this method to obtain the SVG document for the page when the view mode is "SVG".

The LEADTOOLS Document Converter uses this method to obtain the SVG document for the page when converting without using OCR.

Refer to Loading Using LEADTOOLS Document Library for more information.

using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
public void DocumentExample() 
   var cache = GetCache(); 
   var policy = new CacheItemPolicy(); 
   policy.AbsoluteExpiration = DateTime.Now + new TimeSpan(0, 0, 1); 
   policy.SlidingExpiration = new TimeSpan(0, 0, 1); 
   var options = new LoadDocumentOptions(); 
   options.CachePolicy = policy; 
   options.Cache = cache; 
   if(options.Cache == null) 
      options.Cache = DocumentFactory.Cache; 
   string documentId = null; 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), options)) 
      document.IsReadOnly = false; 
      document.AutoDeleteFromCache = false; 
      // DocumentImages reference 
      document.Images.DefaultBitsPerPixel = 24; 
      // Check if the document has a stream in memory 
      if (document.HasStream) 
         // Get the document stream 
      // Indicate whether the document is using the cache or not 
      //Indicate if the document was downloaded 
      // Gets a value that determines whether the document structure is supported 
      // Output metadata values (DocumentMetadata reference) 
      // Get the Mime type of the document 
      // Parse document structure data (DocumentStructure reference) 
      foreach(DocumentBookmark bookmark in document.Structure.Bookmarks) 
         bookmark.Title = null; 
         bookmark.FontStyles = DocumentFontStyles.Normal; 
      // Get the document URI 
      // Get each DocumentPage object (DocumentPage & DocumentPages reference) 
      foreach (DocumentPage page in document.Pages) 
         // Get the page as a raster image at the specified resolution 
         // Get the page as an Svg with specified options 
         // Flip this page horizontally 
         // Use this method to add an array of links for this page 
         page.IsLinksModified = false; 
         page.Resolution = 0; 
         page.ViewPerspective = RasterViewPerspective.TopLeft; 
         Console.WriteLine($"Page Number: {page.PageNumber}, Original PageNumber: {page.OriginalPageNumber}, Size of the page: {page.Size}"); 
      documentId = document.DocumentId; 
   var loadFromCacheOptions = new LoadFromCacheOptions(); 
   loadFromCacheOptions.Cache = cache; 
   loadFromCacheOptions.DocumentId = documentId; 
   using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions)) 
      if (null == document) 
         Console.WriteLine("Cached document was expired and deleted!"); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 

Target Platforms

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

Leadtools.Document Assembly

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