pub struct DocumentModifier { /* private fields */ }Expand description
Modifier for existing PDF documents. Loads all objects from a PdfDocument, allows modification, then saves.
Implementations§
Source§impl DocumentModifier
impl DocumentModifier
Sourcepub fn from_document(doc: &PdfDocument) -> Result<Self>
pub fn from_document(doc: &PdfDocument) -> Result<Self>
Create a modifier from an existing PdfDocument. Copies all objects from the document into the writer.
Sourcepub fn writer(&mut self) -> &mut PdfWriter
pub fn writer(&mut self) -> &mut PdfWriter
Get a reference to the internal writer for low-level modifications.
Sourcepub fn catalog_ref(&self) -> &IndirectRef
pub fn catalog_ref(&self) -> &IndirectRef
Get the catalog reference.
Sourcepub fn set_object(&mut self, obj_num: u32, obj: PdfObject)
pub fn set_object(&mut self, obj_num: u32, obj: PdfObject)
Replace an object at a given object number.
Sourcepub fn add_object(&mut self, obj: PdfObject) -> IndirectRef
pub fn add_object(&mut self, obj: PdfObject) -> IndirectRef
Add a new object and return its reference.
Sourcepub fn find_object_pub(&self, obj_num: u32) -> Option<&PdfObject>
pub fn find_object_pub(&self, obj_num: u32) -> Option<&PdfObject>
Find an object by object number (public accessor).
Sourcepub fn delete_page(&mut self, page_index: usize) -> Result<()>
pub fn delete_page(&mut self, page_index: usize) -> Result<()>
Delete a page by index (0-based). Modifies the Pages tree to remove the page reference.
Sourcepub fn insert_page(
&mut self,
page_index: usize,
page: PageBuilder,
) -> Result<()>
pub fn insert_page( &mut self, page_index: usize, page: PageBuilder, ) -> Result<()>
Insert a new page at the given index.
Sourcepub fn reorder_pages(&mut self, order: &[usize]) -> Result<()>
pub fn reorder_pages(&mut self, order: &[usize]) -> Result<()>
Reorder pages. order is a list of 0-based page indices in the desired order.
Sourcepub fn set_info(&mut self, key: &[u8], value: &str)
pub fn set_info(&mut self, key: &[u8], value: &str)
Set or update a metadata field in the Info dictionary.
Sourcepub fn garbage_collect(&mut self)
pub fn garbage_collect(&mut self)
Perform garbage collection: remove unreachable objects.
Traverses all objects reachable from the catalog (and info dict), then removes any objects that are not reachable.
Sourcepub fn build_with_xref_stream(
self,
compressed: &[CompressedObjInfo],
) -> Result<Vec<u8>>
pub fn build_with_xref_stream( self, compressed: &[CompressedObjInfo], ) -> Result<Vec<u8>>
Serialize to PDF bytes using xref streams (PDF 1.5+).
compressed contains info about objects packed into object streams.
Auto Trait Implementations§
impl Freeze for DocumentModifier
impl RefUnwindSafe for DocumentModifier
impl Send for DocumentModifier
impl Sync for DocumentModifier
impl Unpin for DocumentModifier
impl UnsafeUnpin for DocumentModifier
impl UnwindSafe for DocumentModifier
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> 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 more