Exporting Vector PDFs from Processing Sketches
Learn how to capture Processing drawing commands as resolution‑independent PDFs, with a concrete example, verification steps, and known limitations.
16 Dec 2025, 02:22 UTC

Problem: You need a scalable, editable output from a Processing sketch
When you want to send a sketch to a print house, import it into Illustrator, or include it in a LaTeX document, a raster image (PNG/JPEG) limits quality and editability. Processing can record the vector drawing commands directly into a PDF file, preserving lines, text, and stroke styles at any resolution.
Thesis: Using beginRecord(PDF, "filename.pdf") and endRecord() lets you generate true vector PDFs from a 2D Processing sketch, with a few practical constraints.
How PDF recording works in Processing
Processing’s beginRecord function starts capturing all subsequent drawing commands into a specified file format. When the format is PDF, the output is a PDF vector file. The recording stops when endRecord is called. Everything drawn between these two calls—shapes, text, stroke, fill, and transformations—is stored as PDF primitives.
Worked example: Exporting a simple logo
The following sketch draws a stylized logo consisting of a rectangle, a circle, and some text. It records a single frame into logo.pdf. Place the code in the Processing IDE and run it.
import processing.pdf.*;
void setup() {
size(400, 400);
// Start PDF recording on the first frame
beginRecord(PDF, "logo.pdf");
noLoop(); // we only need one frame
}
void draw() {
background(255);
// Logo elements
fill(200, 50, 50);
rect(50, 150, 300, 100, 20);
fill(50, 150, 200);
ellipse(200, 200, 120, 120);
fill(0);
textAlign(CENTER, CENTER);
textSize(48);
text("Proc", 200, 200);
// Stop recording after drawing this frame
endRecord();
}
Explanation:
- The PDF library is imported with
import processing.pdf.*;. beginRecordis called insetupso recording starts immediately.noLoopensuresdrawruns only once, preventing multiple pages.- After drawing the logo,
endRecordfinalizes the PDF.
Verifying the exported PDF
To confirm the output is truly vector:
- Open
logo.pdfin a PDF viewer and zoom in—edges should stay crisp. - Open the same file in a vector editor such as Inkscape or Adobe Illustrator.
- Select the rectangle, circle, or text; you should be able to edit the paths or text properties, confirming that the PDF contains vector primitives, not a raster bitmap.
Trade‑offs and limitations
- Renderer restriction: PDF recording only works with the default 2D renderer. Using
P3DorOPENGLwill ignore 3D transformations and produce a flat output. - Font handling: Fonts must be either Processing‑compatible
.vlwfiles or system fonts. Embedded fonts are not subsetted, so using many typefaces can increase file size. - Color space: Colors are stored in RGB. Direct CMYK profiles are not supported; if you need CMYK for print, you must convert the PDF externally.
- Single‑frame capture: By default each call to
beginRecord/endRecordcreates one page. Multi‑page PDFs require calling the pair multiple times, typically within a loop that advances to a new page vianextPage()(available in the PDF library).
Actionable next steps
If you need vector output from your Processing sketches:
- Ensure your sketch uses the default 2D renderer (
size(w, h)withoutP3DorOPENGL). - Wrap the drawing you want to capture with
beginRecord(PDF, "out.pdf")andendRecord(). - Run the sketch, inspect the PDF in a viewer, and verify editability in a vector tool.
- If you require multiple pages or CMYK output, plan for post‑processing with tools like
pdftk,Ghostscript, or Adobe Acrobat.
By following this approach you can move from screen‑only sketches to scalable, print‑ready vector files without leaving the Processing environment.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.