JFLib

pdf/src/read/object.rs#

Source: lib/pdf/src/read/object.rs

The objects of a PDF file as the reader gives them (ISO 32000-1, 7.3): null, booleans,
integers, reals, strings (bytes; text strings are decoded by text_string), names, arrays,
dictionaries, streams and references to indirect objects.  A stream holds its dictionary and
where its data lies in the file; Document::decode gives the data with the filters applied.
  • struct Ref a reference to an indirect object: its number and generation

    • num: u32
    • generation: u16
  • struct Name(pub Vec<u8>) a name (/Type): its bytes with #xx escapes resolved

impl Name

  • fn as_bytes(&self) -> &[u8]

  • fn to_text(&self) -> String the name as text (bytes that are not UTF-8 become U+FFFD)

  • struct Dict(pub(crate) Arc<BTreeMap<Name, Object>>) a dictionary; a key given twice keeps its last value. Copies share their entries until one of them changes (inherited resources, the pages of a tree and the caches of drawing copy dictionaries freely; a hostile file must not turn that into memory without end)

impl Dict

  • fn new() -> Dict

  • fn get(&self, key: &str) -> Option<&Object> the value of a key (without the slash: "Type")

  • fn get_bytes(&self, key: &[u8]) -> Option<&Object>

  • fn contains(&self, key: &str) -> bool

  • fn insert(&mut self, key: &str, value: Object)

  • fn remove(&mut self, key: &str) -> Option<Object> the value of a key, taken out

  • fn len(&self) -> usize

  • fn is_empty(&self) -> bool

  • fn iter(&self) -> impl Iterator<Item = (&Name, &Object)>

  • fn name(&self, key: &str) -> Option<&[u8]> the name under a key (Type, Subtype, ...), if it is one

  • fn is(&self, key: &str, v: &str) -> bool a key whose value is the name v

  • fn int(&self, key: &str) -> Option<i64>

  • fn num(&self, key: &str) -> Option<f64>

  • struct Stream a stream: its dictionary, and where its (still encoded) data lies in the file

    • dict: Dict

impl Stream

  • fn raw_len(&self) -> usize the number of encoded bytes

  • enum Object one object of a PDF file

    • Null
    • Bool(bool)
    • Int(i64)
    • Real(f64)
    • String(Vec<u8>) -- a string's bytes (decrypted); text strings decode with text_string
    • Name(Name)
    • Array(Vec<Object>)
    • Dict(Dict)
    • Stream(alloc::boxed::Box<Stream>) -- boxed: keeps every object at 32 bytes
    • Ref(Ref)

impl Object

  • fn name(s: &str) -> Object

  • fn is_null(&self) -> bool

  • fn as_bool(&self) -> Option<bool>

  • fn as_int(&self) -> Option<i64> an integer, or a real that is one (some writers put 1.0 where an integer belongs)

  • fn as_f64(&self) -> Option<f64> a number

  • fn as_name(&self) -> Option<&[u8]>

  • fn as_bytes(&self) -> Option<&[u8]> a string's bytes

  • fn as_array(&self) -> Option<&[Object]>

  • fn as_dict(&self) -> Option<&Dict> a dictionary, or a stream's dictionary

  • fn as_stream(&self) -> Option<&Stream>

  • fn as_ref(&self) -> Option<Ref>

  • fn as_rect(&self) -> Option<[f64; 4]> a rectangle [x0 y0 x1 y1], normalized so that x0 <= x1 and y0 <= y1

  • fn text_string(b: &[u8]) -> String a text string (7.9.2.2) as text: UTF-16BE after FE FF, UTF-16LE after FF FE (seen in the wild), UTF-8 after EF BB BF (PDF 2.0), else PDFDocEncoding

Source: docs/API.md in the JFLib repository.