Export Resolution-Independent Vector PDFs from Processing
Record vector geometry from a Processing sketch to a resolution-independent PDF using built-in PDF recording, with checks and recovery steps.
12 Nov 2025, 23:28 UTC

Problem and useful takeaway
Exporting a Processing sketch as a PNG or with saveFrame() produces a raster image. It displays correctly at one size, but pixelates when printed large or zoomed in. If you need output for print, plotting, or scalable design assets, pixels are the wrong format.
Processing can record vector geometry directly to a PDF file. Drawing commands placed between beginRecord() and endRecord() are captured as resolution-independent drawing instructions rather than a pixel grid. Use a static draw cycle so the file is written once and not overwritten by animation.
Desired outcome
A single PDF file in the sketch folder that contains vector lines, shapes, and text. The file should remain crisp at any zoom level and be suitable for print or plotting workflows.
Prerequisites
- Processing installed and able to run a sketch.
- Write permission for the sketch folder.
- The PDF library available in your installed Processing release. Some versions require import processing.pdf.*; or a separate library installation—verify this before starting.
- A sketch whose output is mainly vector geometry, such as lines, rectangles, ellipses, and text.
Procedure: record one vector PDF page
- Open the sketch in the Processing editor.
- Add the PDF import if your release requires it:
import processing.pdf.*;
- Set the canvas size using the P2D renderer, which is the default for 2D PDF export:
size(600, 600, P2D);
- Stop continuous animation so recording happens once. In setup(), call noLoop():
noLoop();
- Begin PDF recording. Provide a filename; the file is written to the sketch folder unless you supply an explicit path:
beginRecord(PDF, "sketch_export.pdf");
- Place all drawing commands between beginRecord() and endRecord(). For example:
background(255);
stroke(0);
strokeWeight(2);
line(50, 50, 550, 550);
rect(100, 100, 200, 200);
fill(0);
text("Vector PDF export", 200, 300);
- Close the recording:
endRecord();
- Exit the sketch or rely on noLoop() so draw() does not run again and overwrite the PDF:
exit();
Where to run: the Processing sketch editor. Required permissions: write access to the sketch folder. Placeholder: replace "sketch_export.pdf" with your intended filename. Risk: calling beginRecord() again before endRecord() can leave an incomplete or corrupt PDF.
Expected checks
- Run the sketch once. Confirm a non-zero PDF file appears in the sketch folder.
- Open the PDF in a vector-capable viewer and zoom to 400% or higher. Lines and text should remain crisp without pixelation.
- Add a new shape, re-run the sketch, and confirm the PDF file size changes. A static file size suggests recording did not capture the new geometry.
- If the PDF is blank, verify that endRecord() was called and that noLoop() or exit() prevented draw() from running again.
Recovery options
- Delete an incomplete or corrupt PDF and re-run the sketch.
- Match every beginRecord() with exactly one endRecord(). Do not nest recording calls.
- If text appears pixelated at high zoom, the font may have been embedded as a bitmap. Try a standard font or convert text to curves in a vector editor after export.
Limitations
- PDF coordinates match sketch pixels. Set size() to match intended print dimensions rather than assuming 72 DPI.
- Image processing filters, image(), and pixel-level operations may embed as rasters and lose vector scalability.
- This produces static vector pages, not interactive PDF forms.
- Multi-page output requires beginRecord() and endRecord() for each page. saveFrame() is for raster sequences, not vector PDF export.
- Text recording behavior depends on the font, renderer, and Processing version. Verify complex fonts in your installed release.
Practical verification
After export, open the PDF in Inkscape, Adobe Acrobat, or another vector viewer. Select text with the text tool; if it selects as text rather than an image, it was recorded as vector outlines. Zoom in on a diagonal line; smooth edges indicate vector output, while stair-stepped pixels indicate a raster embed.
Version-dependent behavior: PDF import requirements and text-outlines support differ across Processing releases. Confirm import processing.pdf.*; and font behavior in your installed version before using this in a production workflow.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.