Convert Gerber Files to DXF, PDF, PNG, and TIFF with scConverter
Use the scConverter SDK to convert one or more Gerber layers into vector formats such as DXF, PDF, and SVG, or raster formats such as PNG and TIFF. Create layered output, place each layer on a separate page, or merge Gerber and Excellon files programmatically.
Gerber Conversion Functions in the scConverter SDK
scConverter provides several specific functions for converting from Gerber and Excellon file formats to other file formats.
With these functions you can either convert one or more Gerber files to a vector DXF or PDF file, or to an image format like PNG and TIFF.
The following functions are specifically made for Gerber, and Excellon, conversion:
- AddGerberLayer
Add a Gerber, Excellon or HPGL/2 file to be included in the output as a separate layer. - ClearGerberLayers
Clear all currently loaded layers. - ConvertGerberLayersToImageEx
Convert all currently loaded layers to an image and return it as IPictureDisp interface.
You can easily convert the returned IPictureDisp to a .NET Image class. - ConvertGerberLayersToImage
Convert all currently loaded layers to an image file. - ConvertGerberLayersArea
Convert all currently loaded layers to an image file using a specified area. - ConvertGerberLayersToCAD
Convert all currently loaded layers to a vector format file. Sample vector output formats include DXF, SVG and PDF. - ConvertGerberLayersToMP
Convert all currently loaded layers to a multipage file. Each layer will be placed on a separate page. This function do support PDF, DWF, PLT and TIFF output formats. - SetGerberLayerVisible
Toggle the visibility for one of the currently loaded layers.
In addition there are two support functions that are used when converting older RS-274D (legacy) Gerber format files:
- GerberApertureFileName
The name of an aperture definition file to use when loading RS-274D Gerber files. - GerberFormatSettings
Configure file format settings to use when loading RS-274D Gerber files.
The following function will make it possible to add Excellon drill files that doesn't contain full format description:
- DrillFormatSettings
Configure file format settings to use when loading Excellon drill files.
You will find more information about the listed functions in the scConverter documentation.
In this tutorial you will find out how you can use some of these functions to create different types of output.
Convert Gerber files to an image file
Included in the SDK you will find a sample application named scGerberDemo, this application demonstrates how to load Gerber files and then convert
these files to different output formats. It will also display the layers with their color and transparency setting.
Among the available output formats are Adobe PDF, and Gerber files exported to this format will maintain vector geometry and layer information.
Here is a code example that will load Gerber files from our WEB site:
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/LAYER4.gbx", 0x80FF00FF, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/LAYER3.gbx", 0x80FF0000, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/LAYER2.gbx", 0x8000FF00, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/LAYER1.gbx", 0x800000FF, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/CMASK.gbx", 0x80FFFF00, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/SMASK.gbx", 0x8000FFFF, 0x01);
scconverter.AddGerberLayer("https://www.gerbview.com/demo/project1/SILK.gbx", 0x800000aa, 0x01);
The above code will add each layer with transparency. The color reference is using 0xAABBGGRR format, where AA can be from 0x00 (full transparency) to 0xFF (255 - full opacity).
Remember to add the transparency flag (0x01) if you're using transparent color references.
When all the required Gerber files are added you can then convert them to an image. There are two functions that can create image output, one of them to a file and the
other can return the image as an IPictureDisp. The returned IPictureDisp value can easily be converted to an Image class object. In the demo application
mentioned above you will find code for creating an IPictureDisp, convert it to an Image object and then display it in a PictureBox:
sconverter.BackgroundColor = 0; //Use black background scconverter.SetMargins(true, 5.0, 5.0, 5.0, 5.0); //Add a 5mm margin around the Gerber data stdole.IPictureDisp scPicture = null; scconverter.ConvertGerberLayersToImageEx(1.0, 24, 96, 0x01, ref scPicture); Image scImage = PictureDispHost.GetPictureFromIPicture(scPicture); pictureBox1.Image = scImage;
The created Image will then look like this in our sample application:
To create an image output file you can either use the scImage.Save() function with the Image object that was created above, or you can also use the other conversion function named ConvertGerberLayersToImage, as show below:
double w = 0.0; double h = 0.0; scconverter.ConvertGerberLayersToImage( "output.png", "PNG", 1.0, 24, 200, 0, ref w, ref h);
This code will create a output PNG file named "output.png" using 24-bit color (true color) and 200 DPI resolution, as shown below:
Convert one or more Gerber layers to a vector (CAD) file
Instead of converting the Gerber files to an image, you can also use scConverter to create vector formats files like PDF, DXF, SVG and PLT.
If you convert to PDF and SVG formats any set transparency may also be included, you can control if it should be included or not by using the SetConfigValue() function.
For DXF and PDF output each Gerber file will be placed on a separate layer.
scconverter.PDFWriteFormat = 0; //Output standard PDF (editable) scconverter.PDFLayers = 1; //Enable PDF layers scconverter.SetConfigValue(17, 0); //Disable transparent layers for exported PDF scconverter.ConvertGerberLayersToCAD( "output.pdf", "PDF");
The picture below show the created PDF in Adobe Acrobat with a separate layer for each added file.
scconverter.SetConfigValue(17, 1); //Enable transparent layers for exported PDF scconverter.ConvertGerberLayersToCAD( "output.pdf", "PDF");
This code will create a PDF with the transparency set using the AddGerberLayer method as shown below:
Finally we will convert our Gerber files to a SVG file with transparency enabled and display it in Chrome.
Conversion to SVG code:
scconverter.SetConfigValue(17, 1); //Enable transparent layers for exported SVG scconverter.ConvertGerberLayersToCAD( "output.svg", "SVG");
The resulting SVG file displayed in Chrome:
To create an Autodesk DXF file you only have to replace the format description string as shown here:
scconverter.ConvertGerberLayersToCAD( "output.dxf", "DXF");
Convert two or more layers to a multi-page file
Instead of converting the loaded layers to a layered file, you can also use scConverter to create multipage files, where each layer is placed on a separate page.
The ConvertGerberLayersToMP can be used for this purpose and do support the following output formats: DWF, PDF, PLT and TIFF.
Sample code for creating a multi-page PDF file:
scconverter.PDFWriteFormat = 0; //Output standard PDF (editable) scconverter.ConvertGerberLayersToMP( "output.pdf", "PDF", 1, 200);
The bits per pixel and dpi parameters are only used for TIFF output.
The following sample code will create a true color TIFF using 200 dots per inch resolution:
scconverter.ConvertGerberLayersToMP( "output.tif", "TIFF", 24, 200);
Merging Gerber files into a single Gerber file
The above-described functions may be used to merge two or more Gerber files into a single Gerber file.
The following sample code shows how to merge two Gerber layers into a new file:
scconverter.AddGerberLayer("layer1.gbx", 0x000000, 0);
scconverter.AddGerberLayer("layer2.gbx", 0x000000, 0);
scconverter.ConvertGerberLayersToCAD( "merged.gbx", "GERBER");
Merging Excellon files into a single drill file
With scConverter you can merge several different Excellon drill files into a single Excellon file.
The following sample code shows how to merge two Excellon files into a new file:
scconverter.AddGerberLayer("drill-pth.drl", 0x000000, 0);
scconverter.AddGerberLayer("drill-npth.drl", 0x000000, 0);
scconverter.ConvertGerberLayersToCAD( "drill-merged.drl", "EXCELLON");
Resources
Open scConverter Documentation (PDF) in a new window.