pub struct PageEdit { /* private fields */ }Expand description
One page’s object graph, opened for editing.
Obtained from the facade’s Page::edit. Holds the objects the page draws, in painting
order, plus a record of what has changed — which is what tells the save
which content streams to write again and which to leave alone.
§Nothing is mutated until you save
Page::edit hands back an owned graph, you change that, and
Document::save_pages turns the changes
into replacement objects on the way out. The document is never touched,
which is why editing a page needs no &mut Document and why two threads
can edit two pages at once.
§Saving an edited page rewrites it, and rewriting loses things
A page whose objects you changed is written again from the object
graph, not patched. Only rg/RG colours survive, so a CMYK or
ICC-based fill comes back black; patterns, shadings and Type 3 text are
lost; text keeps only its matrix, font, render mode and strings, so
character and word spacing go. The pdfrum-edit documentation lists them in full. This applies only to pages you edited — every other page
is copied through byte-for-byte.
use pdfrum::{Document, SaveOptions};
let doc = Document::open("in.pdf")?;
let mut page = doc.page(0)?.edit();
page.remove(0);
doc.save_pages("out.pdf", &[page], &SaveOptions::default())?;Implementations§
Source§impl PageEdit
impl PageEdit
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
How many objects the page draws, including any switched off with
PageEdit::hide.
Sourcepub fn objects(&self) -> &[PageObject]
pub fn objects(&self) -> &[PageObject]
The objects, in painting order.
Sourcepub fn object_mut(&mut self, index: usize) -> Option<&mut PageObject>
pub fn object_mut(&mut self, index: usize) -> Option<&mut PageObject>
The object at index, for a caller who wants to change it in place.
Taking this reference is the edit — the object is marked changed on
the way out, so its content stream is rewritten whether or not you go
on to touch it. Read with PageEdit::objects when you only want to
look.
Sourcepub fn push(&mut self, object: PageObject)
pub fn push(&mut self, object: PageObject)
Append an object, drawn last and therefore on top.
Sourcepub fn insert(
&mut self,
index: usize,
object: PageObject,
) -> Result<(), IndexOutOfRange>
pub fn insert( &mut self, index: usize, object: PageObject, ) -> Result<(), IndexOutOfRange>
Insert an object at index, pushing the ones there and after later in
the painting order. An index equal to PageEdit::len appends.
§Errors
IndexOutOfRange when index is past the end.
Sourcepub fn remove(&mut self, index: usize) -> Option<PageObject>
pub fn remove(&mut self, index: usize) -> Option<PageObject>
Remove the object at index and hand it back.
Sourcepub fn show(&mut self, index: usize) -> Result<(), IndexOutOfRange>
pub fn show(&mut self, index: usize) -> Result<(), IndexOutOfRange>
Show the object at index without removing it.
A hidden object keeps its place and its index, so it can be shown again — but it contributes nothing to the saved page, and reloading the saved file will not find it.
§Errors
IndexOutOfRange when there is no object at index.
Sourcepub fn hide(&mut self, index: usize) -> Result<(), IndexOutOfRange>
pub fn hide(&mut self, index: usize) -> Result<(), IndexOutOfRange>
Hide the object at index without removing it.
See PageEdit::show.
§Errors
IndexOutOfRange when there is no object at index.
Sourcepub fn is_visible(&self, index: usize) -> Option<bool>
pub fn is_visible(&self, index: usize) -> Option<bool>
Whether the object at index is drawn.
Sourcepub fn transform(
&mut self,
index: usize,
transform: Affine,
) -> Result<(), IndexOutOfRange>
pub fn transform( &mut self, index: usize, transform: Affine, ) -> Result<(), IndexOutOfRange>
Move the object at index by transform.
The transform is applied before the object’s existing one, so
Affine::translate((10.0, 0.0)) moves it ten points right in page
space whatever it was already doing.
§Errors
IndexOutOfRange when there is no object at index.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Whether anything has been changed since the page was opened.
A false here means the save will not rewrite this page’s content at
all, and its bytes will come through untouched.
Source§impl PageEdit
impl PageEdit
Sourcepub fn font_of(&self, index: usize) -> Option<ObjRef>
pub fn font_of(&self, index: usize) -> Option<ObjRef>
The /Font resource the text object at index uses, for a
TextBuilder that wants to write in the same font.
None when there is no such object, when it is not text, or when its
font was written inline in the resource dictionary and so has no object
to name.