The PDF library makes it possible to write PDF files directly from Processing. These vector graphics files can be scaled to any size and output at very high resolutions. The PDF library can flatten 3D data into a 2D vector file, but to export 3D data, use the DXF library. The source code is available on the Processing GitHub repository. Please report bugs here. This library is frequently used with the core Processing function size(), with a combination of beginRecord() and endRecord(), or with beginRaw() and endRaw(). The createGraphics() function can also be useful. See the examples below for different techniques. Single Frame (No Screen Display) This example draws a single frame to a PDF file and quits. (Note that no display window will open, this helps when you’re trying to create massive PDF images that are far larger than the screen size.) Multiple Pages (No Screen Display) It’s possible to write every frame as a new page in the PDF document. This example creates a 100 page document: Single Frame (With Screen Display) To draw to the screen while also saving a PDF, use the beginRecord() and endRecord() functions. This is slower, but is useful when you need to see what you’re working on as it saves. Single Frame from an Animation (With Screen Display) It’s also possible to save one frame from a program with moving elements. Create a boolean variable to turn the PDF recording process on and off Many Frames Into One File (With Screen Display) The following example records absolutely everything that happens while a sketch is running. Hitting the ‘q’ key will quit the sketch. The sketch calls exit(), which is necessary to make sure that the file is properly written when complete. Pausing While Recording (With Screen Display) It’s also possible to pause/resume recording along the way. The following example toggles recording on/off each time you hit the ‘r’ key. Pressing the ‘q’ key will quit the sketch. PDF Files from 3D Geometry (With Screen Display) To create vectors from 3D data, use the beginRaw() and endRaw() commands. These commands will grab the shape data just before it is rendered to the screen. At this stage, your entire scene is nothing but a long list of lines and triangles. This means that a shape created with sphere() method will be made up of hundreds of triangles, rather than a single object. When using beginRaw() and endRaw(), it’s possible to write to either a 2D or 3D renderer. For instance, beginRaw() with the PDF library will write the geometry as flattened triangles and lines. Using createGraphics() to Create a PDF File To write a PDF file using only the createGraphics() command, rather than as part of a sketch, it’s necessary to call dispose() on the PGraphicsPDF object. This is the same as calling exit(), but it won’t quit the sketch. Source.