Skip to main content

load

Function load 

Source
pub fn load(
    bytes: impl Into<ByteSpan>,
    opts: &LoadOptions,
) -> Result<Document, LoadError>
Expand description

Open a document.

bytes is the whole file. Every repair the reader performed is in Document::diags afterwards, and a document that opened with a rebuilt table reports so through Document::xref_was_rebuilt.

ยงErrors

LoadError::NotPdf for a file with no header, LoadError::WrongPassword and LoadError::UnsupportedEncryption for encryption the password or the reader cannot handle, and LoadError::Broken for damage recovery could not repair.

use std::sync::Arc;
use pdfrum_parser::{LoadError, LoadOptions, load};

let not_a_pdf: Arc<[u8]> = Arc::from(&b"just some bytes"[..]);
assert_eq!(load(not_a_pdf, &LoadOptions::default()).err(), Some(LoadError::NotPdf));