Processing Month, Day 19 - Exporting PDF Files for Lasercutting

Posted on 2011-05-19 by Jan Vantomme
Tags: processing, tutorial

Today, we'll take a look at how we can use the PDF library to export our sketch for lasercutting. This sketch won't display anything on the screen. It will save a PDF file directly to your sketch folder. For lasercutting, we need to define two colors: one for cutting (RGB Red) and one for engraving (RGB Black).

color cutColor = color( 255, 0, 0 );
color engraveColor = color( 0 );

You also need to import the PDF library to your sketch. Go to the Sketch > Import Library > PDF Export. This line will be added to your sketch.

import processing.pdf.*;

We'll output a single page PDF without screen output so our size() function will look a little different. We need to add two parameters: PDF to set the renderer for the sketch, and a filename for our PDF file. I usually save my PDF files in a separate directory.

size( 800, 800, PDF, "pdf/lines.pdf" );

You can draw anything within the draw() function using the two colors we defined earlier. Be sure to use them with stroke() in combination with noFill(). It's also important to use exit() at the end of draw() to close the application and save the PDF file. In the first sketch, I wrote a small algorithm to calculate random points within a circle. I used these points to draw black lines for engraving, and I used a red line to draw the circle for cutting. You'll find the exported PDF in the sketch folder.

A circle filled with lines, ready for lasercutting

In the second example, I've used the regular polygon function from day 13. It's very important to use the CLOSE parameter when you create custom shapes with beginShape() and endShape(). The first example below shows you a polygon drawn without using the CLOSE parameter. If you would send this to a lasercutter, the shape wouldn't be cut out of the material. The second example is how everything should be done.

An open polygon. This would be a problem for lasercutting

A closed polygon. This would be ok for lasercutting

If we want to play with typography and lasercutting, we need to use textMode(SHAPE) right after we set the size of the sketch. This will make outlines of the font when they are drawn to the PDF file. Another problem is t hat we can't use stroke() to outline the font. So we'll need to fill the text with the color we'll use to cut out the shape. The end result will look like the image below.

Two characters filled with the color for cutting with the lasercutter

If we want to use this one for lasercutting, we'll need to clean this PDF file a little with a tool like Adobe Illustrator to get a result like the one on the image below. It's usually useful to use Illustrator to clean every file you want to send to a lasercutter or vinyl plotter. Software like this makes it very easy to scale your artwork to the right size in milimeters, a thing that is hard in Processing since you usually work in pixels.

Cleaning the PDF file with Illustrator

Downloads

The zip-file for today contains all three examples to design for lasercutting with Processing.

Tweet this article