pub struct PdfPages<'a> { /* private fields */ }
Expand description

The collection of PdfPage objects inside a PdfDocument.

Implementations§

source§

impl<'a> PdfPages<'a>

source

pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings used by this PdfPages collection.

source

pub fn len(&self) -> PdfPageIndex

Returns the number of pages in this PdfPages collection.

source

pub fn is_empty(&self) -> bool

Returns true if this PdfPages collection is empty.

source

pub fn as_range(&self) -> Range<PdfPageIndex>

Returns a Range from 0..(number of pages) for this PdfPages collection.

source

pub fn as_range_inclusive(&self) -> RangeInclusive<PdfPageIndex>

Returns an inclusive Range from 0..=(number of pages - 1) for this PdfPages collection.

source

pub fn get(&self, index: PdfPageIndex) -> Result<PdfPage<'a>, PdfiumError>

Returns a single PdfPage from this PdfPages collection.

source

pub fn first(&self) -> Result<PdfPage<'a>, PdfiumError>

Returns the first PdfPage in this PdfPages collection.

source

pub fn last(&self) -> Result<PdfPage<'a>, PdfiumError>

Returns the last PdfPage in this PdfPages collection.

source

pub fn create_page_at_start( &mut self, size: PdfPagePaperSize ) -> Result<PdfPage<'a>, PdfiumError>

Creates a new, empty PdfPage with the given PdfPagePaperSize and inserts it at the start of this PdfPages collection, shuffling down all other pages.

source

pub fn create_page_at_end( &mut self, size: PdfPagePaperSize ) -> Result<PdfPage<'a>, PdfiumError>

Creates a new, empty PdfPage with the given PdfPagePaperSize and adds it to the end of this PdfPages collection.

source

pub fn create_page_at_index( &mut self, size: PdfPagePaperSize, index: PdfPageIndex ) -> Result<PdfPage<'a>, PdfiumError>

Creates a new, empty PdfPage with the given PdfPagePaperSize and inserts it into this PdfPages collection at the given page index.

source

pub fn copy_page_from_document( &mut self, source: &PdfDocument<'_>, source_page_index: PdfPageIndex, destination_page_index: PdfPageIndex ) -> Result<(), PdfiumError>

Copies a single page with the given source page index from the given source PdfDocument, inserting it at the given destination page index in this PdfPages collection.

source

pub fn copy_pages_from_document( &mut self, source: &PdfDocument<'_>, pages: &str, destination_page_index: PdfPageIndex ) -> Result<(), PdfiumError>

Copies one or more pages, specified using a user-friendly page range string, from the given source PdfDocument, inserting the pages sequentially starting at the given destination page index in this PdfPages collection.

The page range string should be in a comma-separated list of indexes and ranges, for example "1,3,5-7". Pages are indexed starting at one, not zero.

source

pub fn copy_page_range_from_document( &mut self, source: &PdfDocument<'_>, source_page_range: RangeInclusive<PdfPageIndex>, destination_page_index: PdfPageIndex ) -> Result<(), PdfiumError>

Copies one or more pages with the given range of indices from the given source PdfDocument, inserting the pages sequentially starting at the given destination page index in this PdfPages collection.

source

pub fn append(&mut self, document: &PdfDocument<'_>) -> Result<(), PdfiumError>

Copies all pages in the given source PdfDocument, appending them sequentially to the end of this PdfPages collection.

For finer control over which pages are imported, and where they should be inserted, use one of the PdfPages::copy_page_from_document(), PdfPages::copy_pages_from_document(), or PdfPages::copy_page_range_from_document() functions.

source

pub fn tile_into_new_document( &self, rows_per_page: u8, columns_per_row: u8, size: PdfPagePaperSize ) -> Result<PdfDocument<'_>, PdfiumError>

Creates a new PdfDocument by copying the pages in this PdfPages collection into tiled grids, the size of each tile shrinking or expanding as necessary to fit the given PdfPagePaperSize.

For example, to output all pages in a PdfPages collection into a new A3 landscape document with six source pages tiled on each destination page arranged into a 2 row x 3 column grid, you would call:

PdfPages::tile_into_new_document(2, 3, PdfPagePaperSize::a3().to_landscape())
source

pub fn page_mode(&self) -> PdfPageMode

Returns the PdfPageMode setting embedded in the containing PdfDocument.

source

pub fn watermark<F>(&self, watermarker: F) -> Result<(), PdfiumError>

Applies the given watermarking closure to each PdfPage in this PdfPages collection.

The closure receives four arguments:

  • An empty PdfPageGroupObject for you to populate with the page objects that make up your watermark.
  • The zero-based index of the PdfPage currently being processed.
  • The width of the PdfPage currently being processed, in PdfPoints.
  • The height of the PdfPage currently being processed, in PdfPoints.

If the current page should not be watermarked, simply leave the group empty.

The closure can return a Result<(), PdfiumError>; this makes it easy to use the ? unwrapping operator within the closure.

For example, the following snippet adds a page number to the very top of every page in a document except for the first page.

    document.pages().watermark(|group, index, width, height| {
        if index == 0 {
            // Don't watermark the first page.

            Ok(())
        } else {
            let mut page_number = PdfPageTextObject::new(
                &document,
                format!("Page {}", index + 1),
                &PdfFont::helvetica(&document),
                PdfPoints::new(14.0),
            )?;

            page_number.translate(
                (width - page_number.width()?) / 2.0, // Horizontally center the page number...
                height - page_number.height()?, // ... and vertically position it at the page top.
            )?;

            group.push(&mut page_number.into())
        }
    })?;
source

pub fn iter(&self) -> PdfPagesIterator<'_>

Returns an iterator over all the pages in this PdfPages collection.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PdfPages<'a>

§

impl<'a> !Send for PdfPages<'a>

§

impl<'a> !Sync for PdfPages<'a>

§

impl<'a> Unpin for PdfPages<'a>

§

impl<'a> !UnwindSafe for PdfPages<'a>

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> 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.