$ show yob/pdf-reader
This repository is a mature Ruby gem (`pdf-reader`) that provides a comprehensive PDF parsing library. It implements a low-level PDF parser conforming to the PDF specification, enabling programmatic access to PDF content without rendering. The library supports text extraction (with UTF-8 conversion), metadata retrieval, page geometry, font handling (Type1, TrueType, Type3, CID), encryption (RC4, AES), and various PDF features like Form XObjects, inline images, and content stream processing. It is designed for document processing, text mining, and automated analysis of PDF files. The architecture follows a receiver/callback pattern for processing content streams, with `PDF::Reader` as the main entry point. Key modules include `PDF::Reader::Page` for high-level page access, `PDF::Reader::ObjectHash` for low-level object access, `PDF::Reader::Parser` for tokenization, and `PDF::Reader::Filter` for stream decompression. The library uses Sorbet for static type checking and includes a comprehensive test suite with over 120 spec files and numerous real-world PDF test fixtures. The codebase demonstrates solid engineering practices: clean abstractions (value objects like `Point`, `Rectangle`, `TextRun`), thread-safe caching (`SynchronizedCache`), optimized matrix operations (`TransformationMatrix`), and a pluggable width calculator system. It is actively maintained with support for multiple Ruby versions (2.1–4.0, JRuby, TruffleRuby) and has a well-documented changelog spanning over a decade of development.
The LLM identified 5 files worth highlighting for reuse:
A thread-safe LRU cache implementation using a Mutex for concurrent access. It wraps a hash with a maximum size and provides get/set operations. This component is isolated (no internal dependencies) and can be reused in any Ruby project requiring a simple, thread-safe cache with eviction.
An immutable value object representing a 3x3 affine transformation matrix used in PDF graphics state. It provides optimized methods for common operations like translation, scaling, and rotation, with special-cased paths for performance. The class is self-contained and demonstrates a clean pattern for mathematical value objects with method chaining.
An immutable value object representing a run of text with font, font size, position, and color attributes. It includes Comparable and provides methods for merging runs. This component is isolated and can be reused in any text layout or rendering system.
A standalone module that reverses PNG and TIFF predictor algorithms used in PDF stream compression. It implements the 'Up', 'Average', 'Paeth', and 'None' predictors with clean, parameterized methods. This component has no internal dependencies and can be extracted for use in any project that needs to decompress PNG/TIFF filtered data.
A utility module providing methods for converting PDF character codes to Unicode strings, handling UTF-16BE, UTF-8, and various single-byte encodings. It includes support for surrogate pairs and invalid byte handling. This component is self-contained and reusable for any text processing task involving PDF encodings.