pub struct ContentEditor { /* private fields */ }Expand description
Editor for PDF content stream operations.
Decodes a raw content stream into Vec<Operation>, allows mutation
(remove, replace, insert), and encodes back to bytes.
Implementations§
Source§impl ContentEditor
impl ContentEditor
Sourcepub fn from_stream(stream: &[u8]) -> Result<Self>
pub fn from_stream(stream: &[u8]) -> Result<Self>
Decode a content stream from raw bytes.
Returns Err if the stream has pathological array nesting (depth >
MAX_CONTENT_ARRAY_DEPTH) to avoid a stack overflow in lopdf’s
recursive array parser. All callers handle Err gracefully (skip/continue).
Sourcepub fn from_operations(operations: Vec<Operation>) -> Self
pub fn from_operations(operations: Vec<Operation>) -> Self
Create an editor from a pre-existing list of operations.
Sourcepub fn operations(&self) -> &[Operation]
pub fn operations(&self) -> &[Operation]
Return a reference to the operations.
Sourcepub fn operations_mut(&mut self) -> &mut Vec<Operation>
pub fn operations_mut(&mut self) -> &mut Vec<Operation>
Return a mutable reference to the operations.
Sourcepub fn remove_range(&mut self, range: Range<usize>)
pub fn remove_range(&mut self, range: Range<usize>)
Remove operations in the given range.
Sourcepub fn replace_operation(&mut self, index: usize, ops: Vec<Operation>)
pub fn replace_operation(&mut self, index: usize, ops: Vec<Operation>)
Replace the operation at index with one or more operations.
Sourcepub fn insert_operations(&mut self, at: usize, ops: Vec<Operation>)
pub fn insert_operations(&mut self, at: usize, ops: Vec<Operation>)
Insert operations at the given position.
Sourcepub fn encode(&self) -> Result<Vec<u8>>
pub fn encode(&self) -> Result<Vec<u8>>
Encode operations back to content stream bytes.
Uses custom encoding for inline images (BI/ID/EI), because lopdf’s Content::encode() incorrectly serializes them as regular stream objects.
Sourcepub fn encode_compressed(&self) -> Result<Vec<u8>>
pub fn encode_compressed(&self) -> Result<Vec<u8>>
Encode and compress with flate.
Sourcepub fn track_state(&self) -> GraphicsStateTracker
pub fn track_state(&self) -> GraphicsStateTracker
Build a GraphicsStateTracker that walks all operations and
records the graphics state at each operation index.
Trait Implementations§
Source§impl Clone for ContentEditor
impl Clone for ContentEditor
Source§impl Debug for ContentEditor
impl Debug for ContentEditor
Auto Trait Implementations§
impl Freeze for ContentEditor
impl RefUnwindSafe for ContentEditor
impl Send for ContentEditor
impl Sync for ContentEditor
impl Unpin for ContentEditor
impl UnsafeUnpin for ContentEditor
impl UnwindSafe for ContentEditor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.