public void CalculateBounds(
bool trimmed
)
trimmed
true to crop the result bounds using the actual object; otherwise, false.
For more information about flat SVG documents and bounds and resolution, refer to SVG Size, Bounds and Flat.
This 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 |
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 of 0. |
SvgBounds.Bounds |
The document physical boundaries in pixels. |
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.
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:\LEADTOOLS23\Resources\Images";
}