1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! `rusty_pdf_core` reads, edits and saves PDF files: the object layer that a
//! renderer and a writer are built on.
//!
//! ```
//! use rusty_pdf_core::{dictionary, Document, Object, SaveMode, Stream};
//!
//! // Build a one-page document, save it, and read it back.
//! let mut doc = Document::new();
//! let content = doc.add_object(Stream::new(dictionary! {}, b"0 0 100 100 re f".to_vec()));
//! let pages = doc.catalog()?.get(b"Pages").unwrap().as_reference()?;
//! let page = doc.add_object(dictionary! {
//! "Type" => "Page",
//! "Parent" => pages,
//! "MediaBox" => vec![0.into(), 0.into(), 612.into(), 792.into()],
//! "Contents" => content,
//! });
//! let tree = doc.get_object_mut(pages)?.as_dict_mut()?;
//! tree.set("Kids", vec![Object::Reference(page)]);
//! tree.set("Count", 1);
//! let bytes = doc.save(SaveMode::Rewrite)?;
//!
//! let doc = Document::load(&bytes)?;
//! assert_eq!(doc.page_count(), 1);
//! let page = doc.page(0)?;
//! assert_eq!(page.media_box().width(), 612.0);
//! assert_eq!(page.operations()?.last().unwrap().operator, "f");
//! # Ok::<_, rusty_pdf_core::Error>(())
//! ```
//!
//! # What it reads
//!
//! Classic cross-reference tables, cross-reference streams, hybrid files,
//! object streams and incremental updates. When the cross-reference data is
//! missing or wrong, the file is scanned and the table rebuilt
//! ([`Document::was_repaired`]). Encrypted files open with the standard
//! security handler: RC4 at 40 to 128 bits, AES-128 and AES-256.
//!
//! # Hostile input
//!
//! A PDF is attacker-controlled data. Malformed input returns an [`Error`]
//! or a bounded result; it does not panic, loop without progress, or
//! allocate past [`Limits`]. Every stream decode takes a byte cap, and no
//! allocation is sized from a number in the file without a check first.
pub use ToUnicode;
pub use ;
pub use ;
pub use ;
pub use flate_encode;
pub use ;
pub use ;
pub use ;
pub use SaveMode;
/// Bounds on what a file may ask of the reader.
///
/// The defaults admit every well-formed file within the format's own
/// implementation limits. Tighten them when the input is untrusted and
/// memory is scarce.