← Back

ofxPoDoFo

github.com/danoli3/ofxPoDoFo · @danoli3
OF 0.12 Utilities

openFrameworks addon for loading PDF files.

2 1 Last commit 1mo ago Created 2y ago

README

What this is

An openFrameworks addon that converts PDF files into vector paths for drawing and manipulation within the openFrameworks framework. It parses PDF graphics operators and converts geometric primitives (lines, curves, fills) into ofPath objects that can be rendered and transformed by the graphics framework.

Stack

How it's organized



src/
  ofxPoDoFo.h        Main public API: Document & Page classes for loading/drawing
  ofxPoDoFo.cpp      Document::load() implementation with page iteration
  ofxPoDoFoParse.h   Parser and Extractor base class for PDF operator handling
  ofxPoDoFoParse.cpp ~400 lines parsing PDF content operators (moveTo, lineTo, bezierTo, 
                       colors, fills, strokes, etc.) into ofPath commands
  
example/            Standard openFrameworks example project structure
  src/ofApp.h       ofxPoDoFo type alias and Document instance
  src/ofApp.cpp     Trivial example: load("tiger.pdf") in setup(), draw() in render loop
  
addon_config.mk     Addon metadata + dependency declaration (requires ofxClipper)
license.md          Dual licensed: MIT (addon code) + GPLv2 (PoDoFo library)


How it fits together: The example app calls Document::load() with a PDF path. This loads the PoDoFo PdfMemDocument, iterates pages, and creates a Parser::Context for each. The Parser::parse() method reads the PDF content stream using PdfContentStreamReader, extracts operators (like m for moveTo, c for cubic Bezier), and dispatches them through an inheritance hierarchy of Extractor subclasses (MoveTo, BezierTo, StrokeColor, etc.). Each applies transformations and builds ofPath objects. The populated paths are stored in Document::page_[] and rendered via Document::draw(), which calls ofPath::draw() on each path.

How to run it



This is an openFrameworks addon, not a standalone executable. To use it:

1. Clone into your openFrameworks addons/ directory:
   git clone https://github.com/danoli3/ofxPoDoFo.git addons/ofxPoDoFo
   


2. Ensure ofxClipper addon is also installed (declared in addon_config.mk).

3. Generate an example project using the openFrameworks Project Generator, add ofxPoDoFo as an addon, and build:
   # With the example provided in the repo
   cd example
   make
   


4. Place a PDF file (e.g., tiger.pdf) in the example's bin/data/ directory and run the resulting executable.

Try asking

Get this addon

HTTPS
SSH