SVG to G-code converter for pen plotters
Choose an SVG, type the commands that lift and lower your pen, and download G-code that draws the outline of every shape at the size you set.
Free, no account. The file is read by code running in your browser. It is not uploaded, and nothing about it is stored.
SVG to gcode, step by step
- Choose the SVG, drop it on the box, or paste its code.
- Check the size in millimetres and type the width you want on paper.
- Say which corner of the page is X0 Y0 on your machine.
- Pick a starting point for the pen commands and change them to the ones your machine uses.
- Set the drawing speed, look at the preview and the reach of the moves, and download the G-code.
What the file contains
G-code is one command to a line. This is the whole of the file for a 20 mm square drawn 10 mm in from the corner of a 40 mm page, with the servo pen commands, leaving out the comment lines at the top:
G21G90M3 S20G4 P0.5G0 X10 Y30M3 S30G4 P0.5G1 X30 Y30 F2000G1 X30 Y10G1 X10 Y10G1 X10 Y30M3 S20G4 P0.5G0 X0 Y0
G21 sets millimetres and G90 sets absolute positions, so every X and Y is a place on the bed. The pen is lifted before anything moves. G0 travels to the start of a path with the pen up, your pen down lines follow, and G1 draws at the feed rate F, in millimetres a minute; the first drawn move of each path carries it. After the last point your pen up lines run again. Positions are written to a thousandth of a millimetre.
The comment lines at the top, each starting with a semicolon, record the settings: units, origin, page size, how far the moves reach, the pen commands and the speeds. The file sets no offsets, never homes the machine, and does not end with M2 or M30, because on some servo builds of GRBL a program end also drives the pen output.
Pen up and pen down: your own commands
How a plotter lifts its pen depends on how it was built, which is why these two boxes are plain text. Whatever you type is written into the file each time the pen has to move, and each box can hold several lines, such as a move and a wait.
Two starting points are offered. For GRBL with a servo on the spindle output: M3 S20 up and M3 S30 down, each followed by G4 P0.5, a half-second wait for the servo to arrive. For GRBL with the pen on a Z axis: G0 Z2 up and G1 Z0 F1000 down. These are common defaults, not facts about your machine: send each command from your sender’s console first and watch what the pen does.
Mind the wait. In GRBL, G4 P0.5 is half a second. In Marlin and Klipper the same P is in milliseconds, so half a second is G4 P500. For a solenoid, a relay or a macro, type whatever your controller expects.
Size, origin and where zero is
The size comes from the SVG’s own width and height, read at 96 pixels to the inch when they are in pixels. Type another width and the drawing is scaled; the height follows.
An SVG counts y downwards from the top. Most plotters put X0 Y0 at the front left and count Y away from you, so with “front left” chosen the drawing is turned over to come out the right way up: the bottom left of the SVG’s page is X0 Y0. If your machine’s zero is at the back left, with Y running towards you, choose that and nothing is turned. If the plot comes out mirrored top to bottom, the other choice is the right one, or your sender is turning Y over as well.
The two “page corner” boxes move the whole drawing: put the distance from your machine’s zero to the corner of the paper there. Nothing in the file knows how big your machine is. The page shows how far the moves reach in X and Y, and warns when any go below zero.
What is drawn, and what is not
- Outlines. Every shape the SVG draws becomes its outline: paths, rectangles, circles, ellipses, lines, polylines and polygons, after all transforms and
<use>copies. A closed shape ends where it began. - No filling. A filled shape is drawn as its edge only. A plotter fills with hatching, which this tool does not add.
- Thick lines are drawn once along their centre, whatever their width, and dashed lines are drawn solid.
- Curves become short straight moves that stay within the tolerance, 0.05 mm unless you change it. A 50 mm circle is 56 moves. There are no
G2orG3arcs, so any firmware can run the file. - Order. With “Reorder paths” ticked, each path is followed by the one whose nearer end is closest, which cuts the pen-up travel; the page shows the distance. Unticked, paths are drawn in the SVG’s order.
- Left out: text that has not been converted to outlines, embedded pictures, and hidden shapes. Clip paths and masks are not applied, so a clipped shape is drawn whole. The notes beside the result count these.
Before you run it
Do a dry run first: pen cap on, or the pen raised off the paper, and a hand near the stop button. Check that the first move goes where you expect and that the pen lifts between shapes. The time shown is a rough guide from the distances and speeds; it does not count the pen lifts, and on GRBL a plain G0 runs at the machine’s own top rate, which the file cannot know.
This tool is written for pens. It has no laser power control and no spindle or depth handling, so do not use its files to drive a laser or a router.
Questions
Does it work with GRBL, Marlin and Klipper?
The moves do: G21, G90, G0 and G1 are understood by all three. The pen commands are whatever you type, so they must be the ones your firmware and your pen lifter use. The guide to G-code for pen plotters lists tested settings for each.
Can it fill shapes or shade a photo?
No. It follows outlines. To turn a photo into lines a plotter can draw, such as hatching or one continuous line, use the Plotcaster editor, which also writes G-code.
Why is my plot mirrored or upside down?
The file and the machine disagree about which way Y runs. Change “X0 Y0 is at” to the other corner. If your sender has its own setting to flip Y, use one or the other, not both.
How do I send the file to the plotter?
With a G-code sender on a computer connected to the machine, such as Universal Gcode Sender or cncjs for GRBL, or from an SD card or a web interface on printers running Marlin or Klipper.
Why does the pen draw a line between shapes?
The pen up command is not lifting the pen, or the machine moves on before the pen has finished rising. Test the command from the console, and add or lengthen the wait after it.