Skip to main content

read_pdf_page_box

Function read_pdf_page_box 

Source
pub fn read_pdf_page_box(path: &Path) -> Option<(f64, f64)>
Expand description

Read a PDF’s page box (width, height) in bp — CropBox (pdfTeX’s default), else MediaBox. Pure Rust, no external tool (this is what pdfTeX’s built-in reader does). Shared with LaTeXML::Post::Graphics.

Looks in the raw bytes first, then inside object streams. %PDF-1.5 and later — everything current pdflatex emits — may put the page tree in a /Type /ObjStm stream, where the box tokens do not appear as raw bytes at all: measured over 14 real PDFs in this repo, 5 were unreadable without this second pass, and ObjStm presence predicted it exactly.

First box wins, in file order, as the raw-byte scan has always done. A correct answer for page N would mean resolving the page tree through the xref stream; for the figures \includegraphics pulls in, which are single-page, the first box is the page’s own (or the /Pages node’s, which it inherits).