DXF Viewer and Converter
Operator: Abdulla Al Fahad. How tools are built and checked
A DXF file is a text export of a CAD drawing, and the person who sends it usually assumes you own the software that opens it. Nothing about the format is hard to read, though: it is a list of lines, arcs and polylines with layer names and colours.
This page reads an ASCII DXF, draws the model-space geometry on a canvas you can pan and zoom, lets you switch layers off, measures between two clicked points, and writes the drawing out as an SVG or PDF at a paper size and scale you pick.
Key features
- Lines, polylines with bulged arc segments, arcs, circles, ellipses, splines, solids, text, multi-line text and blocks placed with INSERT, including rotated, scaled and arrayed inserts
- Pan, wheel zoom, Fit, and a two-click distance tool that reports the distance and its x and y parts
- Units from the $INSUNITS header (inches, feet, millimetres, centimetres, metres and others), with an override when the file does not say
- SVG and PDF export on A4, A3, A2, A1, A0, Letter or Tabloid, fitted or at a fixed 1:N
Which DXF entities are drawn
Curves are approximated by straight segments: a circle becomes between 8 and 256 segments depending on its size, splines are evaluated as B-splines from their control points and knots (or joined through their fit points when no control points are stored), and a bulge value b on a polyline segment gives an arc whose included angle is 4 times the arctangent of b.
Blocks are expanded with a depth limit of 8 and a check against a block that inserts itself. A file is read up to 600,000 entities or 3 million points; past that the drawing is cut short, with a note about it. Paper-space layouts and entities such as HATCH, IMAGE, LEADER and 3D solids are not drawn; unsupported types found in the file are counted by type so you know what is missing.
In a DXF the layer table holds each layer's colour and on or off state, while entities may carry their own colour index or inherit it BYLAYER. Colour index 7 is white on a dark screen and black on paper, which is why the paper export draws any colour lighter than a luminance of 200 out of 255 in black and darkens mid-light colours such as pure green or orange to about 55% of their brightness, so they stay readable on white.
How it works
The file is parsed in a worker with dxf-parser and flattened into typed arrays of points, one run per polyline, so large drawings never block the page and a parse can be cancelled by opening another file. Binary DXF files are refused with a message asking for an ASCII save. For export, the drawing's extent is multiplied by the millimetres per unit and compared with the paper minus a 10 mm margin. Fit uses the smaller of the width and height ratios, so the whole drawing stays on the sheet; 1:N uses exactly 1/N. The result is centred on the sheet, y is flipped to the paper's downward axis, and every polyline is written as a path in millimetres, grouped by colour.
In the PDF, lines are drawn with PDF path operators at the chosen line weight and text with the built-in Helvetica font; characters outside Latin-1 print as a question mark. The scale is printed in the page's lower corner.
When this helps
- A customer emails a laser-cutting shop a 1,800-entity DXF of a door panel. The shop opens it, switches off the DIMENSIONS layer and exports A3 at 1:5, a print the customer can mark up with a pen before any metal is cut.
- A supplier sends a drawing in inches with no $INSUNITS value. Setting the units to inches and measuring a feature the datasheet lists as 3.5 in confirms the scale before anything is cut.
- A landscape architect receives a 60 m wide site plan in metres ($INSUNITS 6). Exporting A3 landscape at 1:200 gives a sheet 300 mm wide on the 400 mm of usable paper, so the page reports that it fits, and a contractor can scale it with a ruler.
- A MEMS designer's drawing is in micrometres ($INSUNITS 13), so a 2,000-unit line is 2 mm. The page reads the unit from the header, which keeps the measure tool and the paper scale honest instead of showing a 2,000 mm line.
Opening a file
- Drop the DXF and check the layer list and units line.
- Hide layers you do not want on paper, then use Measure to check a known dimension.
- Choose paper, fit or 1:N, line weight and units.
- Export SVG for editing or PDF for printing.
Example
A bracket outline in millimetres: a 100 mm line, a closed polyline with a 25 mm radius bulge, a 10 mm quarter arc, two circles, a bolt block and a text label
Paper: A4, Scale: Fit to the paper, Drawing units: from the file (millimetres)Layout line on the page
Drawing 125 × 50 mm, page 297 × 210 mm at scale 2.22:1, line weight 0.25 mm
Fixed 1:1 gives the same drawing at true size; 1:2 gives 62.5 × 25 mmLimits
AutoCAD's MIRROR command stores arcs and polylines with an extrusion direction of (0, 0, -1). The viewer applies that flip to arcs and polylines; circles with a non-default extrusion are not flipped, because the parser does not expose their direction.
Hatches are not drawn, so a filled area appears as its outline only, and a drawing that relies on hatches to show materials will look empty.
A DXF exported from a 3D model shows the model's x and y only; z coordinates are ignored.
Line types such as dashed and centre lines are drawn solid.
Text is drawn in a plain sans-serif font. Fonts, width factors and oblique angles from the file's text styles are not applied, so lines of text can be longer or shorter than in the CAD program.
- Measure a dimension you already know before trusting a scale; the distance line shows both drawing units and millimetres.
- For a plotted 1:50 elevation, set N to 50 and read the warning: it tells you by what percentage the drawing overflows the sheet.
Common errors and how to fix them
- "This is a binary DXF"
- Re-save the drawing from the CAD program as an ASCII DXF (the dialog usually lists a format such as AutoCAD 2013 DXF).
- "No drawable lines, arcs, circles, polylines or text were found in model space"
- The drawing may live in paper space or consist only of hatches and 3D solids. Export the model space as 2D geometry.
- "The visible drawing has more than 1,500,000 points"
- Hide layers until the export fits, or export one region at a time.
Best practices
- A drawing with thousands of tiny text items is quicker to inspect with the text layer hidden, because text is drawn only when it is at least 4 pixels tall.
Frequently asked questions
Why is my drawing 25.4 times too big or too small?
The file has no $INSUNITS value or the wrong one, so inches were read as millimetres or the reverse. Set the drawing units in the export card, then measure a feature whose size you know; the distance line shows the value in both drawing units and millimetres.
Why do some coloured lines print black or darker than on screen?
On white paper, colours with a luminance above 200 of 255, such as yellow, cyan and white, are drawn black, and colours between 120 and 200, such as pure green, are darkened. Untick the white-paper option to export with the original colours on a dark background.
Why does the page say a file is not a DXF?
An ASCII DXF is made of pairs of lines, a group code and a value, and every file contains 0 / SECTION pairs. A file without them is plain text, a DWG renamed to .dxf or a different CAD format, and needs to be saved again as ASCII DXF from the CAD program.