hayro-syntax 0.6.0

A low-level crate for reading PDF files.
Documentation
//! This example shows how you can iterate over the content stream of all pages in a PDF.

use hayro_syntax::Pdf;
use std::path::PathBuf;

fn main() {
    // First load the data that constitutes the PDF file.
    let data = std::fs::read(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../in.pdf")).unwrap();

    // Then create a new PDF file from it.
    //
    // Here we are just unwrapping in case reading the file failed, but you
    // might instead want to apply proper error handling.
    let pdf = Pdf::new(data).unwrap();

    // First access all pages, and then iterate over the operators of each page's
    // content stream and print them.
    let pages = pdf.pages();
    for page in pages.iter() {
        let mut ops = page.typed_operations();

        while let Some(op) = ops.next() {
            println!("{op:?}");
        }
    }
}