Load, render, view, convert CAD document using C#
August 04, 2026
/// <summary>
/// Converts pages of CAD document to the PNG files.
/// </summary>
public static void ConvertCadToPng(string cadFileName)
{
// specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
// specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
//Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
// create image collection
using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
{
// add CAD document to the image collection
images.Add(cadFileName);
// create PNG encoder
using (Vintasoft.Imaging.Codecs.Encoders.PngEncoder pngEncoder =
new Vintasoft.Imaging.Codecs.Encoders.PngEncoder())
{
// for each page in CAD document
for (int i = 0; i < images.Count; i++)
{
// save rendered image to a PNG file
images[i].Save(string.Format("page{0}.png", i), pngEncoder);
}
}
// dispose images
images.ClearAndDisposeItems();
}
}
...
// open CAD file in WinForms image viewer
imageViewer1.Images.Add("cube.dxf");
...
...
// open CAD file in WPF image viewer
wpfImageViewer1.Images.Add("cube.dxf");
...
...
var imageViewer1 = new Vintasoft.Imaging.UI.WebImageViewerJS("WebImageViewer1");
// open CAD file in web image viewer
imageViewer1.get_Images().openFile("cube.dxf");
...
...
// create the document viewer
var docViewer1 = new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerJS(docViewerSettings);
...
// open CAD file in web document viewer
docViewer1.openFile("cube.dxf");
...
/// <summary>
/// Converts CAD document to a PDF document using ImageCollection and PdfEncoder classes.
/// </summary>
public static void ConvertCadToPdf(string cadFileName, string pdfFileName)
{
// specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
// specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
//Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
// create image collection
using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
{
// add CAD document to the image collection
imageCollection.Add(cadFileName);
// create PDF encoder
using (Vintasoft.Imaging.Codecs.Encoders.PdfEncoder pdfEncoder =
new Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(true))
{
// set the compression for image-resources in PDF document
pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg;
// save images (CAD document) to a PDF document using PDF encoder
imageCollection.SaveSync(pdfFileName, pdfEncoder);
}
// dispose images
imageCollection.ClearAndDisposeItems();
}
}
/// <summary>
/// Converts CAD document to TIFF file using ImageCollection and TiffEncoder classes.
/// CAD document is rendered with specified resolution.
/// </summary>
public static void ConvertCadToTiff(string cadFileName, string tiffFileName, float dpi)
{
// specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
// specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
//Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
// create image collection
using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
{
// add CAD document to the image collection
imageCollection.Add(cadFileName);
// set the rendering settings for CAD document
imageCollection.SetRenderingSettings(new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(dpi, dpi));
// create TiffEncoder
using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder =
new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
{
// set TIFF compression to Zip
tiffEncoder.Settings.Compression =
Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
// save images (CAD document) to a multipage TIFF file using TiffEncoder
imageCollection.SaveSync(tiffFileName, tiffEncoder);
}
// dispose images
imageCollection.ClearAndDisposeItems();
}
}
/// <summary>
/// Converts pages of CAD document to the PNG files.
/// </summary>
public static void ConvertCadToPng(string cadFileName)
{
// specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
// specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
//Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
// create image collection
using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
{
// add CAD document to the image collection
images.Add(cadFileName);
// create PNG encoder
using (Vintasoft.Imaging.Codecs.Encoders.PngEncoder pngEncoder =
new Vintasoft.Imaging.Codecs.Encoders.PngEncoder())
{
// for each page in CAD document
for (int i = 0; i < images.Count; i++)
{
// save rendered image to a PNG file
images[i].Save(string.Format("page{0}.png", i), pngEncoder);
}
}
// dispose images
images.ClearAndDisposeItems();
}
}
/// <summary>
/// Converts CAD document to the SVG files using ImageCollection and SvgEncoder classes.
/// </summary>
public static void ConvertCadToSvg(string cadFileName)
{
// specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
// specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
//Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();
// create image collection
using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
{
// add CAD document to the image collection
images.Add(cadFileName);
// create SVG encoder
using (Vintasoft.Imaging.Codecs.Encoders.SvgEncoder svgEncoder =
new Vintasoft.Imaging.Codecs.Encoders.SvgEncoder())
{
// specify that SVG encoder should compress embedded image using PNG compression
svgEncoder.Settings.EmbeddedImageEncoder = new Vintasoft.Imaging.Codecs.Encoders.PngEncoder();
// for each page in CAD document
for (int i = 0; i < images.Count; i++)
{
// save page to SVG file
images[i].Save(string.Format("page{0}.svg", i), svgEncoder);
}
}
// dispose images
images.ClearAndDisposeItems();
}
}