←Select platform

Bounds Property

Summary
Gets the physical (pixel) bounds and resolution of this SvgDocument.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public SvgBounds Bounds { get; } 
- (nullable LTSvgBounds *)bounds:(NSError **)error; 
public SvgBounds getBounds() 
public: 
property SvgBounds Bounds { 
   SvgBounds get(); 
} 
Bounds # get  (SvgDocument) 

Property Value

The physical (pixel) bounds and resolution of this SvgDocument.

Remarks

For more information about flat SVG documents and bounds and resolution, refer to SVG Size, Bounds and Flat.

Before calling CalculateBounds, the value of Bounds.IsValid will be false and the document does not have its physical (pixel) bounds calculated. The rest of SvgBounds members should not be used.

The CalculateBounds method will calculate the physical (pixel) bounds of the document by internally enumerating all the elements and resolving the transformation. When this method returns, the members of Bounds will be set as follows:

Member Description
SvgBounds.IsValid

true

SvgBounds.IsTrimmed

The value of 'trimmed' passed to CalculateBounds

SvgBounds.Resolution

A value such as 96 or 300 DPI calculated automatically from the SVG elements. If this value cannot be calculated, it will be set to the default value of 0.

SvgBounds.Bounds

The document physical boundaries in pixels.

Use SetBounds to set the physical (pixel) bounds of the document manually.

Use Flat and ToFlat to flatten a document in-place or return a flat copy of an SvgDocument.

Use IsFlat to determine whether this SvgDocument is flat. Use SetFlat to set or clear the internal flattening flag without re-calculating the document's bounds.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgDocumentExample() 
{ 
   // input directory 
   string inDir = LEAD_VARS.ImagesDir; 
   // output directory 
   string outDir = Path.Combine(LEAD_VARS.ImagesDir, "svgpages"); 
   if (!Directory.Exists(outDir)) 
      Directory.CreateDirectory(outDir); 
 
   using (var codecs = new RasterCodecs()) 
   { 
      // Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
      codecs.ThrowExceptionsOnInvalidImages = false; 
 
      // Get all the files from input directory 
      foreach (var srcFileName in Directory.EnumerateFiles(inDir)) 
      { 
         Console.WriteLine("Checking {0}", srcFileName); 
         using (var info = codecs.GetInformation(srcFileName, false)) 
         { 
            // We can load as SVG if its document or vector (skipping SVG files themselves) 
            if (info.Format != RasterImageFormat.Unknown && // valid format 
               info.Format != RasterImageFormat.Svg && // not svg 
               (info.Document.IsDocumentFile || // a document 
               info.Vector.IsVectorFile)) // or vector 
            { 
               // try to load the first page as SVG 
               try 
               { 
                  using (SvgDocument svgDocument = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument) 
                  { 
                     // Save it to disk 
                     string name = Path.GetFileName(srcFileName).Replace(".", "-"); 
                     name = Path.ChangeExtension(name, "svg"); 
                     string dstFileName = Path.Combine(outDir, name); 
                     Console.WriteLine("Saving to {0}", dstFileName); 
                     svgDocument.SaveToFile(dstFileName, null); 
                  } 
               } 
               catch (Exception ex) 
               { 
                  Console.WriteLine(ex.Message); 
               } 
            } 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Svg Assembly

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