Skip to main content

PageEdit

Struct PageEdit 

Source
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

Source

pub fn new(index: PageIndex, page: Page) -> Self

An editable graph for the page at index.

Source

pub fn len(&self) -> usize

How many objects the page draws, including any switched off with PageEdit::hide.

Source

pub fn is_empty(&self) -> bool

Whether the page draws nothing at all.

Source

pub fn index(&self) -> PageIndex

The zero-based index of the page being edited.

Source

pub fn objects(&self) -> &[PageObject]

The objects, in painting order.

Source

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.

Source

pub fn push(&mut self, object: PageObject)

Append an object, drawn last and therefore on top.

Source

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.

Source

pub fn remove(&mut self, index: usize) -> Option<PageObject>

Remove the object at index and hand it back.

Source

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.

Source

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.

Source

pub fn is_visible(&self, index: usize) -> Option<bool>

Whether the object at index is drawn.

Source

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.

Source

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

pub fn graph(&self) -> &Page

Escape hatch — requires pdfrum-page. The object graph underneath, for a caller reaching past this surface.

Matches the facade’s Page::objects and Document::parser.

Source

pub fn graph_mut(&mut self) -> &mut Page

Escape hatch — requires pdfrum-page. The graph, mutably.

Marks nothing: a caller reaching here is responsible for saying what it changed.

Source§

impl PageEdit

Source

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.

Source

pub fn image_of(&self, index: usize) -> Option<ObjRef>

The image XObject the object at index draws, for an ImageBuilder that wants to place the same image again.

None for anything that is not an image, and for an inline image, which has no indirect object to name.

Trait Implementations§

Source§

impl Clone for PageEdit

Source§

fn clone(&self) -> PageEdit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PageEdit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.