pdf_rs/objects.rs
1use std::collections::HashMap;
2
3#[derive(PartialEq,Clone)]
4pub enum PDFNumber {
5 Signed(i64),
6 Unsigned(u64),
7 Real(f64),
8}
9
10pub struct XEntry {
11 /// The value of the entry.
12 pub(crate) value:u64,
13 /// The entry is either in use or deleted.
14 pub(crate) using:bool,
15 /// The object number of the entry.
16 pub(crate) obj_num:u64,
17 /// The generation number of the entry.
18 pub(crate) gen_num: u64,
19}
20
21pub enum PDFObject{
22 /// The keywords true and false represent boolean objects with values true and false.
23 Bool(bool),
24 /// ## Numbers
25 /// PDF provides two types of numbers, integer and real. Integers may be specified by
26 /// signed or unsigned constants. Reals may only be in decimal format. Throughout
27 /// this book, number means an object whose type is either integer or real.</br>
28 /// `Note Exponential format for numbers (such as 1.0E3) is not supported.`
29 Number(PDFNumber),
30 /// ## Names
31 /// A name, like a string, is a sequence of characters. It must begin with a slash fol-
32 /// lowed by a letter, followed by a sequence of characters. Names may contain any
33 /// characters except linefeed, carriage return, %, (, ), <, >, [, ], {, and }. Examples of
34 /// names are:
35 /// ```plaintext
36 /// /Name1
37 /// /ASomewhatLongerName2
38 /// /A;Name_With-various***characters?.
39 /// ```
40 Named(String),
41 String(Vec<u8>),
42 /// ## Arrays
43 /// An array is a sequence of PDF objects. An array may contain a mixture of object
44 /// types. An array is represented as a left square bracket ( [ ), followed by a sequence
45 /// of objects, followed by a right square bracket ( ] ). An example of an array is:</br>
46 /// ```plaintext
47 /// [ 0 (Higgs) false 3.14 3 549 /SomeName ]
48 /// ```
49 Array(Vec<PDFObject>),
50 /// A dictionary is an associative table containing pairs of objects. The first element of
51 /// each pair is called the key and the second element is called the value. Unlike dictio-
52 /// naries in the PostScript language, a key must
53 /// be a name. A value can be any kind of object, including a dictionary.
54 /// A dictionary is generally used to collect and tie together the attributes of a complex
55 /// object, with each key–value pair specifying the name and value of an attribute.
56 ///
57 /// A dictionary is represented by two left angle brackets (<<), followed by a sequence
58 /// of key–value pairs, followed by two right angle brackets (>>). For example:
59 /// Example 4.1 Dictionary
60 /// << /Type /Example /Key2 12 /Key3 (a string) >>
61 /// Or, in an example of a dictionary within a dictionary:
62 /// ```plaintext
63 /// << /Type /AlsoAnExample
64 /// /Subtype /Bad
65 /// /Reason (unsure)
66 /// /Version 0.01
67 /// /MyInfo <<
68 /// /Item1 0.4
69 /// /Item2 true
70 /// /LastItem (not!)
71 /// /VeryLastItem (OK)
72 /// >>
73 /// >>
74 /// ```
75 /// Dictionary objects are the main building blocks of a PDF document. Many parts of
76 /// a PDF document, such as pages and fonts, are represented using dictionaries. By
77 /// convention, the **Type** key of such a dictionary specifies the type of object being
78 /// described by the dictionary. Its value is always a name. In some cases, the **Subtype**
79 /// key is used to describe a specialization of a particular type. Its value is always a
80 /// name. For a font, Type is **Font** and four Subtypes exist: Type1, MMType1,
81 /// Type3, and TrueType.
82 Dict(HashMap<String, Option<PDFObject>>),
83 Null,
84 /// Any object used as an element of an array or as a value in a dictionary may be
85 /// specified by either a direct object or an indirect reference. An indirect reference is a
86 /// reference to an indirect object, and consists of the indirect object’s object number,
87 /// generation number, and the **R** keyword:
88 /// ```plaintext
89 /// <indirect reference> ::=
90 /// <object number>
91 /// <generation number>
92 /// R
93 /// ```
94 /// Using an indirect reference to the stream’s length, a stream could be written as:
95 /// ```plaintext
96 /// 7 0 obj
97 /// <<
98 /// /Length 8 0 R
99 /// >>
100 /// stream
101 /// BT
102 /// /F1 12 Tf
103 /// 72 712 Td (A stream with an indirect Length) Tj
104 /// ET
105 /// endstream
106 /// endobj
107 /// 8 0 obj
108 /// 64
109 /// endobj
110 /// ```
111 ObjectRef(u64, u64),
112 /// A direct object is a boolean, number, string, name, array, dictionary, stream, or null,
113 /// as described in the previous sections. An indirect object is an object that has been
114 /// labeled so that it can be referenced by other objects. Any type of object may be an
115 /// indirect object. Indirect objects are very useful; for example, if the length of a
116 /// stream is not known before it is written, the value of the stream’s **Length** key may
117 /// be specified as an indirect object that is stored in the file after the stream.</br>
118 /// An indirect object consists of an object identifier, a direct object, and the **endobj**
119 /// keyword. The object identifier consists of an integer object number, an integer gen-
120 /// eration number, and the **obj** keyword:
121 /// ```plaintext
122 /// <indirect object> ::=
123 /// <object ID> ::=
124 /// <object ID>
125 /// <direct object>
126 /// endobj
127 /// <object number>
128 /// <generation number>
129 /// obj
130 /// ```
131 /// The combination of object number and generation number serves as a unique iden-
132 /// tifier for an indirect object. Throughout its existence, an indirect object retains the
133 /// object number and generation number it was initially assigned, even if the object is
134 /// modified.</br>
135 /// Each indirect object has a unique object number, and indirect objects are often but
136 /// not necessarily numbered sequentially in the file, beginning with o
137 IndirectObject(u64, u64,Vec<PDFObject>),
138 Stream,
139 /// **Non-standard** pdf object only support current project parse temp storage xref table
140 Xref(Vec<XEntry>),
141}