Preloader
Others
  • Estimated reading time: 5 Minutes

Converting DWG Files and Scanned Drawings to DXF in the Browser with WebAssembly

Converting DWG Files and Scanned Drawings to DXF in the Browser with WebAssembly

If you have ever built software that touches manufacturing, architecture or fabrication, you have probably heard the same request: "Can you just open this drawing?" The file is usually a DWG from AutoCAD, sometimes a DXF exported from a laser-cutting program, and occasionally a phone photo of a pencil sketch. For years, the honest answer involved a desktop CAD license, a server-side converter, or an upload to a website you had never heard of.

WebAssembly has changed that. Reading and writing CAD formats can now happen inside a browser tab, on the user's own machine. This article covers why DWG is awkward to work with, how browser-based conversion works, and how to inspect the results with a few lines of Python.

DWG vs. DXF: why one is harder than the other

DWG is AutoCAD's native format. It is binary, it changes between AutoCAD releases, and Autodesk has never published an official specification. Everything outside the Autodesk ecosystem that reads DWG relies on reverse-engineered implementations, which is why so many tools simply refuse to open it.

DXF (Drawing Exchange Format) was designed as the opposite: an interchange format with a public reference. An ASCII DXF file is plain text made of group-code/value pairs, so you can open it in a text editor and read it. That openness is why most non-Autodesk software prefers it. Laser and plasma cutting software such as LightBurn and SheetCAM, open-source CAD programs like LibreCAD and QCAD, vector editors like Inkscape, and countless in-house scripts all import DXF, while very few accept DWG.

In practice, one conversion keeps showing up in support tickets and job queues: DWG in, DXF out.

Moving the converter from the server to the browser

The traditional approach was a backend job: accept an upload, run a converter binary, return the result. It works, but you pay for compute, you become responsible for customers' confidential drawings, and users wait on large uploads.

The open-source GNU LibreDWG project offers a different path. It is a C library that reads (and partially writes) DWG files, and because it is written in C it can be compiled to WebAssembly with Emscripten. Once it runs as Wasm, the browser can parse a DWG file locally, and the file never needs to leave the user's computer.

A well-built browser converter usually follows the same pattern:

  1. Read the file locally. The user drops a file, and the page reads it as an ArrayBuffer through the File API. Nothing is sent over the network.
  2. Work in a Web Worker. Parsing a large drawing can take a few seconds, so the Wasm module runs in a background worker. The UI stays responsive and can show progress.
  3. Write the target format. The parsed entities (lines, arcs, polylines, blocks, layers, hatches, dimensions) are serialized as DXF, ideally keeping the same release as the source rather than silently upgrading it to a version older software can't read.
  4. Verify before download. A careful tool re-reads its own output and counts layers and objects, so the user knows the conversion is complete before saving it.

The browser CAD tools from DrawCAD are one example of this pattern: LibreDWG runs as WebAssembly in a background worker, and the result is read back and previewed before you download it. Because nothing is uploaded, this approach also suits drawings you are not allowed to send to third-party servers.

Inspecting a DXF file with Python

Whatever tool produced your DXF, it is worth checking the output before it goes to a CNC machine or a customer. The open-source ezdxf library makes that easy:

from collections import Counter
import ezdxf

doc = ezdxf.readfile("bracket.dxf")

# DXF release (e.g. AC1015 = AutoCAD 2000) and drawing units
print("DXF version:", doc.dxfversion)
print("Units ($INSUNITS):", doc.header.get("$INSUNITS", 0))  # 4 = mm, 1 = inches, 0 = unitless

# Which layers exist?
for layer in doc.layers:
    print("Layer:", layer.dxf.name)

# What kinds of entities are in model space?
msp = doc.modelspace()
print(Counter(entity.dxftype() for entity in msp))

Two details deserve attention. First, $INSUNITS tells you what one drawing unit means. A part drawn in millimeters but imported as inches will come out 25.4 times too large, and that kind of mistake can waste an entire sheet of material. Second, the entity count is a quick sanity check: if the original drawing had hundreds of objects and the converted file contains a dozen, something was dropped.

When the input is a picture, not a CAD file

Not every drawing starts life in CAD. Old parts come with scanned blueprints, makers sketch on paper, and clients send photos of whiteboards. Turning those into DXF is a different problem: instead of parsing a file format, you have to trace pixels into geometry.

A typical raster-to-vector pipeline looks like this:

  • Thresholding decides which pixels count as lines. Adaptive thresholding handles photos with shadows and uneven lighting better than a single global value.
  • Despeckling removes isolated dots of dirt and paper texture.
  • Hole filling closes small gaps inside thick strokes so one line stays one line.
  • Tracing converts the cleaned bitmap into vectors. Outline mode traces both edges of every stroke, which suits logos and shapes you will cut. Centerline mode draws one line down the middle of each stroke, which is what you want for drawings you will edit later.
  • Smoothing trades fidelity for cleaner geometry with fewer points.
  • Scaling is the step that is easiest to forget. A traced image is only useful in CAD if it is the right size, so you need to set the real width, a DPI value, or measure a known dimension.

A browser-based image to DXF converter can expose these same controls and write the result as a true-scale DXF or SVG, so you can tune the trace and check the scale before importing anything into CAD.

Practical tips before you send a converted file anywhere

  • Match the DXF release to the consumer. Many laser and CNC packages are happiest with R12 or 2000-era DXF. Newer is not always better.
  • Check units first, geometry second. Most "the part came out wrong" problems are unit problems.
  • Expect traced geometry to need cleanup. Basic tracing produces polylines rather than true arcs and circles. Critical features such as bolt holes should be redrawn or verified against a known dimension.
  • Respect confidentiality. Engineering drawings often fall under NDAs. Converters that run locally in the browser sidestep a whole category of data-handling questions.

Conclusion

A few years ago, handling CAD files on the web meant either a server-side pipeline or telling users to install desktop software. WebAssembly has made a third option practical: run mature open-source libraries such as LibreDWG directly in the browser, keep files on the user's device, and give people an instant preview of the result. For developers, that means fewer backend jobs, fewer privacy questions, and a much shorter path from "can you open this drawing?" to a usable DXF file.

Related articles
What Really Drives the Cost of a Data Annotation Project
1 Dec, 2026
  • Estimated reading time: 5 Minutes
Best Image to Video AI With Sound Tools in 2026
1 Dec, 2026
  • Estimated reading time: 5 Minutes
Prototype Game Audio With a Cue Sheet and One Reference Mix
1 Dec, 2026
  • Estimated reading time: 5 Minutes
Weekly trending
What Really Drives the Cost of a Data Annotation Project
1 Dec, 2026
  • Estimated reading time: 5 Minutes
Best Image to Video AI With Sound Tools in 2026
1 Dec, 2026
  • Estimated reading time: 5 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.