Introduction
gerber2pdf.py is a Python program that converts Gerber files (used to fabricate printed circuit boards) into a PDF document that can be viewed and printed with the freely available Acrobat viewer. Gerber files must conform to the RS-274X specification. My intention is to provide complete support for the full RS-274X specification. However, this early version has seen only limited testing so far. If you find an example Gerber file that is not handled correctly, or discover bugs in the program, please e-mail me at jchavez@swcp.com.
Dependencies
- Python (Tested with Version 2.6)
- Plex (Tested with Version 2.0.0)
- ReportLab Toolkit (Tested with Release 2.5)
Usage
This program can be run as a stand-alone routine or imported as an external module. Invoking the program stand-alone with no command line arguments launches an interactive session that lets you specify the list of Gerber files to be converted (wildcards are supported), and also the page size, the scale, and the offset. The files are converted to a single multi-page PDF document named "gerber.pdf", which is placed in the same directory as your Gerber files, with one page for each Gerber file.
If command line arguments are provided, they are interpreted as Gerber file path names (wildcards are supported). The specified files are converted to a single PDF document (one page per file) using the following module variables:
Variable | Default Value | Comment |
---|---|---|
gerberPageSize | 8.5 * inch, 11.0 * inch | Width, Height |
gerberOutputFile | "gerber.pdf" | |
gerberFitPage | 0 | If true, automatically fit plot to page |
gerberMargin | 0.75 * inch | Margin used if gerberFitPage is true |
gerberScale | 1.0, 1.0 | X scale, Y scale |
gerberOffset | 0.0 * inch, 0.0 * inch | X offset, Y offset |
If a file named "gerber2pdf.cfg" exists in the same directory as the Gerber files, its contents are executed as Python statements before translation begins. Therefore, you can use this file as a configuration file to change the value of any of the above module variables. For example, this file could contain something like this:
gerberPageSize = (6.0*inch, 6.0*inch)
gerberOffset = (1.0*inch, 1.0*inch)
gerberOutputFile = "myGerberFileName.pdf"
gerberScale = (1.0,1.0)
Alternatively, if you wish to automatically fill the page with the plot, this file could contain something like this:
gerberPageSize = (11.0*inch,8.5*inch)
gerberFitPage = 1
gerberMargin = 0.5*inch
gerberOutputFile = "yourFileName.pdf"
If you would prefer not to include all the Gerber file path names in the command line arguments, you can supply them in the configuration file by including a command like this:
fileList = [ file1.gbr, file2.gbr, file3.gbr ]
If you import this program as an external module, you have access to the above mentioned module variables and to the function Interact(), which launches the interactive session described above. You also have access to the function Translate( gerberFileNameList ), which translates the specified list of Gerber files into a PDF document using the current values of the module variables.
License
Copyright (c) 2011 Joseph C Chavez
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
1) the latest version of plex (2.0.0) uses a lowercase 'p' for the module name 2) exec on line 336 fails if the aperture macro contains dos newlines (\r\n) 3) HandleLineCenter computes the coordinates incorrectly (cx and cy
should not be multiplied by costheta/sintheta) Thanks to Igor Izyumin Lines made with rectangular apertures are now handled correctly. Polygon
aperture definitions are now handled correctly.
Allow terminating M02 token without final asterisk.
Allow G74 and G75 blocks prior to aperture selection.
Fixed a problem with Python 2.3 by removing line termination characters from strings supplied to the eval function.
Outline macros and multi-line macros are now handled correctly.
Macro primitives with trailing commas in their variable lists are now
handled correctly.
Comment blocks beginning with "G4" are now handled correctly.
Thanks to Martin Thompson, macro definitions containing assignment operators now work correctly.
Calculated extents and offsets are now expressed in inches.
Martin Thompson added the ability to automatically scale and offset the plot to fill a given page size.
Fixed a circular interpolation bug.
Fixed several problems with Polygon apertures.
Now handles the Mode command correctly. Fixed a problem with some polygon fills containing circular interpolation entities. Now permits value string lengths to extend beyond the strict limits set by the Format Statement.
Now accepts negative numbers for aperture definition modifiers.
Handles zero width aperture.
Paths can now use rectangular apertures.
D-codes with leading zeros are now handled correctly in aperture definitions.
Fixed bugs within the AD block. The program now correctly handles an aperture type that consists of a macro that requires no modifiers. Also, leading spaces are now permitted in aperture type modifiers.
Fixed a bug with the circle aperture macro primitive. The program now correctly handles the exposure off condition.
The program now correctly interprets the M2 code.
Within an FS block, if the L/T designator is not present, L is assumed; if the A/T designator is not present, A is assumed.
During an interactive session, the configuration file (if present) is now read correctly immediately after the Gerber file list is determined.
Fixed a problem with the incorrect interpretation of the X operator in an Aperture Macro.
Fixed a bug with outline and polygon macro elements.
Bug fix: Initial G36 area fill block handled incorrectly.
Initial Release
Back to J C Chavez Home Page.
Download
Version History
Version 1.7 - January 14, 2011
Version 1.6 - September 17, 2006
Version 1.5 - March 3, 2006
Version 1.4 - October 31, 2004
Version 1.3 - March 29, 2004
Version 1.2 - March 28, 2004
Version 1.1 - October 7, 2003
Version 1.0 - September 1, 2003
Version 0.9 - July 26, 2003
Version 0.8 - July 13, 2003
Version 0.7 - July 12, 2003
Version 0.6 - March 10, 2003
Version 0.5 - March 7, 2003
Version 0.4 - February 22, 2003
Version 0.3 - January 11, 2003
Version 0.2 - December 10, 2002
Version 0.1 - December 9, 2002
jchavez@swcp.com