The short answer
To convert DXF to SVG, open the DXF in Inkscape and save it as SVG, or open it in LibreCAD and export it as SVG. DXF is a text based CAD exchange format, so a short script can also read its lines and circles and write them as SVG shapes. This site has no DXF to SVG tool, because browsers cannot run a CAD importer, and the tool this site offers for this pair of formats is the reverse direction, SVG to DXF for CNC and laser work. The conversion happens on your computer, and the file never needs to be uploaded. Once you have the SVG, the converters on this site can turn it into PNG, PDF or EPS.
What converting DXF to SVG actually does
DXF is short for Drawing Exchange Format. Autodesk created it as an open text format for moving drawings between AutoCAD and other CAD programs, and it stores geometry as plain text, in sections for the header, tables, blocks and entities, with each value tagged by a group code number.
SVG is short for Scalable Vector Graphics. It is an open W3C standard written in XML text, and it describes shapes as paths, fills and strokes for browsers, design tools, laser cutters and cutting machines. Converting DXF to SVG means reading the CAD entities, lines, circles, arcs, polylines and splines, and writing each one as an SVG shape or path, so it opens anywhere.
Lines, circles, arcs and polylines usually carry across well. Dimensions, hatching, paper space layouts, blocks and CAD only objects are the parts that can change or drop out, so a drawing prepared for print needs more care than a flat cut profile. Check the result with the steps in section 7 before you use it.
Method 1: Inkscape, free
Inkscape is the practical free route for this conversion. It imports a DXF file through its DXF import extension, shows an import dialog where you set the scale, and saves the result as SVG. It works on Windows, Mac and Linux, and the file stays on your computer.
Inkscape DXF import can be inconsistent, and complex CAD annotations and blocks may need preparation in a CAD program first. If Inkscape refuses the file, re-save it as DXF R14 in LibreCAD and try again, since older importers expect that version.
- Download Inkscape from inkscape.org and install it.
- Open Inkscape, go to File, Open, and choose the DXF file. Inkscape shows the DXF import settings when the file loads.
- Set the import units to the units used by the drawing, usually millimetres, and confirm. If the DXF does not record its units reliably, measure a known dimension in the CAD program first.
- Check the imported drawing at high zoom: look at the scale, the layers, the text and any hatching, and delete construction geometry and unwanted layers.
- Go to File, Save As, and save a copy as Plain SVG for the widest compatibility. Choose Inkscape SVG only when you need to keep Inkscape editing data in the file.
- Open the SVG in a browser or in the tool that will use it, and compare it with the drawing you expected.
Method 2: LibreCAD, free
librecad dxf2svg drawing.dxfLibreCAD is a free and open source 2D CAD program built around DXF, and it opens a DXF file natively, with no import step. It can export the drawing as SVG in one step, and it also has a command line tool for batch work. The command below converts one file without opening the program window.
- Download LibreCAD from librecad.org and install it.
- Open LibreCAD, go to File, Open, and choose your DXF file.
- Check the drawing, the layers and the scale, and fix anything that imported badly.
- Go to File, Export, and export the drawing as SVG.
- Open the SVG in a browser or in the tool that will use it, and check the size and the line work before you send it on.
Method 3: a short Python script, the sample drawing
0
SECTION
2
ENTITIES
0
LINE
8
0
10
10.0
20
10.0
11
90.0
21
10.0
0
LINE
8
0
10
90.0
20
10.0
11
90.0
21
90.0
0
CIRCLE
8
0
10
50.0
20
50.0
40
20.0
0
ENDSEC
0
EOFBecause DXF is plain text, a short script can do the conversion for simple drawings, with no CAD program installed. The sample below is a real DXF file: two lines that form a corner, and a circle. Each entity starts with group code 0 and its name, then pairs of group codes and values. A LINE uses codes 10 and 20 for the start point and codes 11 and 21 for the end point. A CIRCLE uses codes 10 and 20 for the centre and code 40 for the radius. Save it as drawing.dxf, in the same folder as the script in the next section.
Method 3: a short Python script, the converter
def read_pairs(path):
with open(path) as handle:
lines = [line.strip() for line in handle]
pairs = []
for i in range(0, len(lines) - 1, 2):
pairs.append((lines[i], lines[i + 1]))
return pairs
def dxf_to_svg(path):
shapes = []
current = None
for code, value in read_pairs(path):
if code == "0":
if current:
shapes.append(current)
if value in ("LINE", "CIRCLE"):
current = {"type": value}
else:
current = None
elif current is not None:
current[code] = value
if current:
shapes.append(current)
points = []
for shape in shapes:
if shape["type"] == "LINE":
points.append((float(shape["10"]), float(shape["20"])))
points.append((float(shape["11"]), float(shape["21"])))
if shape["type"] == "CIRCLE":
cx = float(shape["10"])
cy = float(shape["20"])
r = float(shape["40"])
points.append((cx - r, cy - r))
points.append((cx + r, cy + r))
xs = [p[0] for p in points]
ys = [p[1] for p in points]
min_x = min(xs)
min_y = min(ys)
max_x = max(xs)
max_y = max(ys)
width = max_x - min_x
height = max_y - min_y
out = []
out.append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' + str(width) + ' ' + str(height) + '">')
for shape in shapes:
if shape["type"] == "LINE":
x1 = float(shape["10"]) - min_x
y1 = max_y - float(shape["20"])
x2 = float(shape["11"]) - min_x
y2 = max_y - float(shape["21"])
out.append(' <line x1="' + str(x1) + '" y1="' + str(y1) + '" x2="' + str(x2) + '" y2="' + str(y2) + '" stroke="black" />')
if shape["type"] == "CIRCLE":
cx = float(shape["10"]) - min_x
cy = max_y - float(shape["20"])
r = float(shape["40"])
out.append(' <circle cx="' + str(cx) + '" cy="' + str(cy) + '" r="' + str(r) + '" fill="none" stroke="black" />')
out.append('</svg>')
return out
if __name__ == "__main__":
with open("drawing.svg", "w") as handle:
for line in dxf_to_svg("drawing.dxf"):
print(line, file=handle)The script reads the group code pairs, collects the LINE and CIRCLE entities, and writes them as SVG line and circle elements. It uses only the Python standard library, so there is nothing to install. It flips the Y axis, because DXF measures Y upwards and SVG measures Y downwards, and it sizes the viewBox to fit the drawing. Save it as dxf_to_svg.py, then run it with python3 dxf_to_svg.py in the same folder as drawing.dxf. It writes drawing.svg, which opens in any browser.
- Save the script as dxf_to_svg.py and the sample as drawing.dxf, in the same folder.
- Run python3 dxf_to_svg.py in a terminal in that folder.
- Open drawing.svg in a browser and check the corner and the circle against the drawing you expected.
Method 4: online converters
Online converters turn a DXF file into SVG in the browser, with nothing to install. They suit a one off file when you have no desktop software. Pick a converter that runs in the browser when privacy matters, because server side converters upload your drawing to a third party server, so do not use them for private client work or drawings you do not own.
- Open a DXF to SVG converter, such as the free converter on 101convert.com, and choose DXF as the input format and SVG as the output format.
- Upload the DXF file and start the conversion, then download the SVG. The converter on 101convert.com takes files up to 5 MB and converts up to 3 files in one batch.
- Open the SVG in a browser or in the tool that will use it, and check it carefully with the steps in section 7.
Prepare the DXF file first, then check the SVG
- Work on model space, not paper space. Most converters read the model space drawing only, and layouts, viewports and title blocks in paper space do not export.
- Explode blocks that the next tool may not understand, and hide or delete construction geometry and unwanted layers. They travel into the SVG unless you remove them first.
- Check the units before you convert. A drawing in millimetres that is read as inches comes out 25.4 times too large, so confirm the units at every step.
- Convert text to outlines when the lettering must stay exact. CAD fonts do not exist in browsers, so text can change shape or fall back to a different font.
- Save a copy of the original DXF before you change it. The cleaned copy is for conversion, and the original stays the master file.
- Open the SVG in a browser and zoom in to 200 percent or more. Lines should stay smooth, and corners should stay sharp.
- Measure the SVG against a known size. If the width is wrong, the units were set wrongly in the export, so go back and set them.
- Check every closed shape. A shape that must cut as a pocket or a hole needs a closed path, and an open path will not cut as a region.
- Try the SVG where it will be used, such as a laser cutter, a CNC router or a web page, before you delete the DXF. Keep the DXF as the master file until the SVG is proven.
DXF or SVG: when to keep each
| Use | Keep DXF | Use SVG |
|---|---|---|
| Editing in CAD | Yes, it is the native exchange file | No, CAD tools cannot edit SVG well |
| Website or app | No, browsers cannot display DXF | Yes, SVG is the web vector format |
| Laser or CNC cutting | Yes, cutters read DXF well | Yes, a flat vector file |
| Sharing with a client | Only with a CAD user | Yes, it opens in a browser |
| Editing later | Yes, any CAD program opens DXF | Yes, any vector editor opens SVG |
| Going back to CAD | Yes, it imports cleanly | Only through the SVG to DXF route |
Sources
Written by Shahab Uddin. Published ; updated . Corrections are welcome through the contact page.