pub struct ContentChunks<'a> { /* private fields */ }Expand description
A content stream read a window at a time (module docs).
§Examples
use pdfcer_model::content::ContentChunks;
use pdfcer_model::object::Dict;
let dict = Dict::new();
let mut chunks = ContentChunks::from_stream(&dict, b"0 0 m 10 10 l S");
let mut ops = 0;
while let Some(window) = chunks.next_chunk()? {
ops += window.operations().count();
}
assert_eq!(ops, 3);Implementations§
Source§impl<'a> ContentChunks<'a>
impl<'a> ContentChunks<'a>
Sourcepub fn from_page(
view: &DocumentView<'a>,
page: &Page,
) -> Result<Self, ContentError>
pub fn from_page( view: &DocumentView<'a>, page: &Page, ) -> Result<Self, ContentError>
A page’s /Contents, concatenated exactly as
ContentStream::from_page concatenates them.
§Errors
ContentError::NotAStream when a /Contents entry does not
resolve to a stream. Decoding has not started yet.
Sourcepub fn from_form(
view: &DocumentView<'a>,
id: ObjId,
) -> Result<Self, ContentError>
pub fn from_form( view: &DocumentView<'a>, id: ObjId, ) -> Result<Self, ContentError>
A form XObject’s own content, as ContentStream::from_form reads it.
§Errors
ContentError::NotAStream when id is absent or not a stream.
Sourcepub fn from_stream(dict: &'a Dict, raw: &'a [u8]) -> Self
pub fn from_stream(dict: &'a Dict, raw: &'a [u8]) -> Self
One stream given by its dictionary and encoded bytes.
Sourcepub fn prime(&mut self) -> Result<(), ContentError>
pub fn prime(&mut self) -> Result<(), ContentError>
Read the first window now, so a caller can report an error in it
before committing to the content; Self::next_chunk then returns
that window first.
§Errors
As Self::next_chunk for its first window.
Sourcepub fn truncation(&self) -> Option<ChunkTruncation>
pub fn truncation(&self) -> Option<ChunkTruncation>
Why reading stopped early, once it has.
Sourcepub fn next_chunk(&mut self) -> Result<Option<ContentStream>, ContentError>
pub fn next_chunk(&mut self) -> Result<Option<ContentStream>, ContentError>
The next window, or None after the last.
§Errors
A decode or syntax error. In the first window every error is
returned, as ContentStream::from_page would return it. After
that, a decode error ends the content: the windows decoded before it
are returned first, then the error once.