SVG to DXF converter using native Inkscape dxf_outlines extension
$ dotnet add package SvgToDxfA .NET library for converting SVG files to DXF format using native Inkscape dxf_outlines extension.
Microsoft.Extensions.Loggingdotnet add package SvgToDxf
using SvgToDxf;
// Create converter
var converter = new SvgToDxfConverter();
// Convert SVG bytes to DXF bytes
byte[] svgBytes = File.ReadAllBytes("input.svg");
byte[] dxfBytes = await converter.ConvertAsync(svgBytes);
File.WriteAllBytes("output.dxf", dxfBytes);
var options = new DxfConversionOptions
{
UsePolyline = true, // Use LWPOLYLINE instead of LINE
UseLegacyPolyline = false,
UseRobo = false,
Units = "mm" // Output units: mm, cm, in, pt, px
};
byte[] dxfBytes = await converter.ConvertAsync(svgBytes, options);
using var svgStream = File.OpenRead("input.svg");
byte[] dxfBytes = await converter.ConvertAsync(svgStream);
using Microsoft.Extensions.Logging;
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = loggerFactory.CreateLogger<SvgToDxfConverter>();
var converter = new SvgToDxfConverter(logger);
byte[] dxfBytes = await converter.ConvertAsync(svgBytes);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
byte[] dxfBytes = await converter.ConvertAsync(svgBytes, cts.Token);
| Platform | Architecture | RID |
|---|---|---|
| Linux (glibc) | x64 | linux-x64 |
| Linux (glibc) | arm64 | linux-arm64 |
| Linux (musl/Alpine) | x64 | linux-musl-x64 |
| Linux (musl/Alpine) | arm64 | linux-musl-arm64 |
| macOS | Intel | osx-x64 |
| macOS | Apple Silicon | osx-arm64 |
| Windows | x64 | win-x64 |
| Windows | ARM64 | win-arm64 |
try
{
byte[] dxfBytes = await converter.ConvertAsync(svgBytes);
}
catch (DxfConversionException ex)
{
Console.WriteLine($"Conversion failed: {ex.Message}");
Console.WriteLine($"Exit code: {ex.ExitCode}");
Console.WriteLine($"Error output: {ex.ErrorOutput}");
}
MIT License - see LICENSE for details.
This library uses the dxf_outlines extension from Inkscape Extensions, compiled to native binaries using Nuitka.