Skip to main content

read_xref

Function read_xref 

Source
pub fn read_xref(
    file: &[u8],
    limits: &Limits,
    diags: &mut Diagnostics,
) -> Result<(Xref, Dict), Error>
Expand description

Read a document’s cross-reference information, rebuilding it if needed.

file is the document from its %PDF header onwards, so every offset this returns indexes straight into it. Failure means neither the structured paths nor the full-file scan found anything usable.

§Errors

Error::XrefBroken when no section could be read and the rebuild found no objects or no trailer.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_parser::{Entry, read_xref};

let file = b"%PDF-1.7\n\
             1 0 obj << /Type /Catalog >> endobj\n\
             trailer << /Root 1 0 R >>\n\
             startxref\n0\n%%EOF\n";
let mut diags = Diagnostics::default();
let (xref, trailer) = read_xref(file, &Limits::default(), &mut diags)?;
// No usable startxref, so the file was scanned for object headers.
assert!(matches!(xref.entry(1), Some(Entry::Offset(_))));
assert!(trailer.raw(pdfrum_object::names::ROOT).is_some());