pdf2gerb: Convert PDF to Gerber and NC Drill formats

New! Version 1.6 is a massive update courtesy of DJ. The tool now auto-generates soldermask and outline layers, supports polygon fills, can read compresed PDF 1.4 format, and is much more robust. It also has proper documentation — read it here. Thanks DJ!

I prefer to design circuit board layouts in Adobe Illustrator — it's a familiar tool and I get results quickly. PCB manufacturers expect designs in Gerber + NC Drill format, however, and the best Illustrator can do is export to PDF.

pdf2gerb is a Perl script that converts specially-formatted PDF files to Gerber and NC Drill format. I used it to order PCB designs from BatchPCB for my POV clock with great success.

Converting PDF to Gerber

The PDF and Gerber file formats are very similar. PDF commands move a pen from point to point, drawing lines and changing stroke weights. Similarly, Gerber commands move a photoplotter head around a circuit board, exposing lines and changing apertures. The concept is the same but the grammar is different.

For example, the PDF command "350 450 m" moves the pen to coordinate (350, 450). The Gerber equivalent is "X350Y450D02". ".5 w" changes the PDF stroke weight; "G54D10" changes the Gerber aperture.

pdf2gerb reads a PDF file line-by-line, converting each command to its Gerber equivalent.

Converting PDF to NC Drill

An NC (aka Excellon) Drill file specifies drill coordinates and diameters for the circuit board. In my PDF file, I represent each drill hole as a solid white circle placed atop the corresponding solder pad (a solid black circles).

pdf2gerb looks for filled white circles in a PDF and outputs their coordinates and diameters as NC Drill commands.

Multi-layer boards

pdf2gerb creates a Gerber and NC Drill file for each layer in the PDF file. Simply draw the board in Illustrator using multiple layers as though you were looking top-down through the board with x-ray vision.


Here is a double-sided board I drew in Illustrator and converted with pdf2gerb:

...and here's the board I received from BatchPCB:

Here's how I prepared the board —

  1. Did a rough layout of the board on graph paper
  2. Redrew the layout in Illustrator:
    • Created several layers: Top Copper, Bottom Copper, Top Silkscreen, Soldermask, and Drill.
    • Drew holes in the Drill layer as a solid black circle (for the pad) with a solid white circle on top (for the drill location and diameter)
    • Used the pen tool on the Top and Bottom layers to add traces between pads
    • Drew solid black circles in the Soldermask layer to cover each pad
    • Drew a rectangle around the board in the Silkscreen layer
  3. Copied the Drill layer into top and bottom layers (may not have been necessary)
  4. Exported the layout in PDF format:
    • Selected PDF 1.3 format
    • Unchecked "Preserve Illustrator Editing Capabilities"
    • Unchecked "Embed Page Thumbnails"
    • On the Compression page, unchecked "Compress Text and Line Art"
  5. Ran 'pdf2gerb.pl /path/to/circuit.pdf'
  6. Renamed 'Top Copper.drd' to 'Drill.drd'
  7. Made a .zip file of Top Copper.grb, Bottom Copper.grb, Top Silkscreen.grb, Soldermask.grb, and Drill.drd
  8. Submitted the .zip file to BatchPCB
You can download the files from this project here.

Curious whether this tool works? It's been proven in real-world use — I used it to design three circuit boards for my discrete logic POV clock, and Luca De Rosso used it to design the board for OTOH.


Download the script here. Right-click on the download link and save it to your computer. Open a Terminal window, navigate to the file you downloaded, and type chmod 755 pdf2gerb.pl to make it executable.

To use pdf2gerb, type ./pdf2gerb.pl /path/to/circuit.pdf. Gerber and NC Drill files will be output to the same location as the PDF file.

Support, licensing, and caveats

pdf2gerb is released as open-source software under the GNU GPL 3.0. Source code is available at GitHub.


If you have comments, suggestions, or issues — or if pdf2gerb helped you build something cool — send me an email at swannman@mac.com.

Version history

1.6: Massive update courtesy of DJ — now auto-generates an outline and soldermask, supports compression and polygon fills, and has proper documentation.

1.4: Improved support for CMYK input files. Change drill file format to decimal (no leading/trailing zeroes suppression) to make the file easier to parse.

1.3: Added support for the 'v' and 'y' Bézier curve operators. Download an example file with supported curves here.

1.2: Added a workaround for TurboCAD users who cannot create filled circles. When TurboCAD support is enabled, pdf2gerb will interpret stroked circles as a drill hole and copper pad as shown in this diagram. The default stacked-filled-circles approach is still preferred, as it gives you the most control over hole and pad size.

1.1: Improved compatibility with Illustrator CS3, which uses the cm command to transform the coordinate plane. Also approximate Bézier curves as two straight lines rather than ignoring them.