PDFObject

Enum PDFObject 

Source
pub enum PDFObject {
    Bool(bool),
    Number(PDFNumber),
    Named(String),
    String(PDFString),
    Array(Vec<PDFObject>),
    Dict(Dictionary),
    Null,
    ObjectRef(u32, u16),
    IndirectObject(u32, u16, Box<PDFObject>),
    Stream(Stream),
}

Variants§

§

Bool(bool)

The keywords true and false represent boolean objects with values true and false.

§

Number(PDFNumber)

§Numbers

PDF provides two types of numbers, integer and real. Integers may be specified by signed or unsigned constants. Reals may only be in decimal format. Throughout this book, number means an object whose type is either integer or real.
Note Exponential format for numbers (such as 1.0E3) is not supported.

§

Named(String)

§Names

A name, like a string, is a sequence of characters. It must begin with a slash fol- lowed by a letter, followed by a sequence of characters. Names may contain any characters except linefeed, carriage return, %, (, ), <, >, [, ], {, and }. Examples of names are:

 /Name1
 /ASomewhatLongerName2
 /A;Name_With-various***characters?.
§

String(PDFString)

§

Array(Vec<PDFObject>)

§Arrays

An array is a sequence of PDF objects. An array may contain a mixture of object types. An array is represented as a left square bracket ( [ ), followed by a sequence of objects, followed by a right square bracket ( ] ). An example of an array is:

[ 0 (Higgs) false 3.14 3 549 /SomeName ]
§

Dict(Dictionary)

A dictionary is an associative table containing pairs of objects. The first element of each pair is called the key and the second element is called the value. Unlike dictio- naries in the PostScript language, a key must be a name. A value can be any kind of object, including a dictionary. A dictionary is generally used to collect and tie together the attributes of a complex object, with each key–value pair specifying the name and value of an attribute.

A dictionary is represented by two left angle brackets (<<), followed by a sequence of key–value pairs, followed by two right angle brackets (>>). For example: Example 4.1 Dictionary << /Type /Example /Key2 12 /Key3 (a string) >> Or, in an example of a dictionary within a dictionary:

<< /Type /AlsoAnExample
/Subtype /Bad
/Reason (unsure)
/Version 0.01
/MyInfo <<
/Item1 0.4
/Item2 true
/LastItem (not!)
/VeryLastItem (OK)
>>
>>

Dictionary objects are the main building blocks of a PDF document. Many parts of a PDF document, such as pages and fonts, are represented using dictionaries. By convention, the Type key of such a dictionary specifies the type of object being described by the dictionary. Its value is always a name. In some cases, the Subtype key is used to describe a specialization of a particular type. Its value is always a name. For a font, Type is Font and four Subtypes exist: Type1, MMType1, Type3, and TrueType.

§

Null

§

ObjectRef(u32, u16)

Any object used as an element of an array or as a value in a dictionary may be specified by either a direct object or an indirect reference. An indirect reference is a reference to an indirect object, and consists of the indirect object’s object number, generation number, and the R keyword:

<indirect reference> ::=
<object number>
<generation number>
R

Using an indirect reference to the stream’s length, a stream could be written as:

7 0 obj
<<
/Length 8 0 R
>>
stream
BT
/F1 12 Tf
72 712 Td (A stream with an indirect Length) Tj
ET
endstream
endobj
8 0 obj
64
endobj
§

IndirectObject(u32, u16, Box<PDFObject>)

A direct object is a boolean, number, string, name, array, dictionary, stream, or null, as described in the previous sections. An indirect object is an object that has been labeled so that it can be referenced by other objects. Any type of object may be an indirect object. Indirect objects are very useful; for example, if the length of a stream is not known before it is written, the value of the stream’s Length key may be specified as an indirect object that is stored in the file after the stream.
An indirect object consists of an object identifier, a direct object, and the endobj keyword. The object identifier consists of an integer object number, an integer gen- eration number, and the obj keyword:

<indirect object> ::=
<object ID> ::=
<object ID>
<direct object>
endobj
<object number>
<generation number>
obj

The combination of object number and generation number serves as a unique iden- tifier for an indirect object. Throughout its existence, an indirect object retains the object number and generation number it was initially assigned, even if the object is modified.
Each indirect object has a unique object number, and indirect objects are often but not necessarily numbered sequentially in the file, beginning with o

§

Stream(Stream)

§Streams

A stream, like a string, is a sequence of characters. However, an application can read a small portion of a stream at a time, while a string must be read in its entirety. For this reason, objects with potentially large amounts of data, such as images and page descriptions, are represented as streams.

A stream consists of a dictionary that describes a sequence of characters, followed by the keyword stream, followed by one or more lines of characters, followed by the keyword endstream.

<stream> ::= <dictionary>
stream
{<lines of characters>}*
endstream

Implementations§

Source§

impl PDFObject

Source

pub fn is_bool(&self) -> bool

Returns true if the object is a boolean.

Source

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

Returns the boolean value of the object if it is a boolean.

Source

pub fn is_number(&self) -> bool

Returns true if the object is a number.

Source

pub fn as_number(&self) -> Option<&PDFNumber>

Returns the number value of the object if it is a number.

Source

pub fn is_string(&self) -> bool

Returns true if the object is a string.

Source

pub fn as_string(&self) -> Option<&PDFString>

Returns the string value of the object if it is a string.

Source

pub fn is_array(&self) -> bool

Returns the string value of the object if it is a string.

Source

pub fn as_array(&self) -> Option<&[PDFObject]>

Returns the array of objects if it is an array.

Source

pub fn is_dict(&self) -> bool

Returns true if the object is a dictionary.

Source

pub fn as_dict(&self) -> Option<&Dictionary>

Returns the dictionary if it is one.

Source

pub fn to_dict(self) -> Option<Dictionary>

Returns the dictionary if it is one.

Source

pub fn is_object_ref(&self) -> bool

Returns true if the object is an indirect object.

Source

pub fn as_object_ref(&self) -> Option<(u32, u16)>

Returns the object reference if it is one.

Source

pub fn is_indirect_object(&self) -> bool

Returns true if the object is an indirect object.

Source

pub fn as_indirect_object(&self) -> Option<(u32, u16, &PDFObject)>

Returns the indirect object if it is one.

Source

pub fn is_null(&self) -> bool

Returns true if the object is null.

Source

pub fn is_stream(&self) -> bool

Returns true if the object is a stream.

Source

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

Returns the stream if it is one.

Source

pub fn is_name(&self) -> bool

Returns true if the object is a name.

Source

pub fn as_name(&self) -> Option<&String>

Returns the name if it is one.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.