Struct pdfium_render::pages::PdfPages
source · pub struct PdfPages<'a> { /* private fields */ }
Expand description
The collection of PdfPage objects inside a PdfDocument.
Implementations§
source§impl<'a> PdfPages<'a>
impl<'a> PdfPages<'a>
sourcepub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
Returns the PdfiumLibraryBindings used by this PdfPages collection.
sourcepub fn len(&self) -> PdfPageIndex
pub fn len(&self) -> PdfPageIndex
Returns the number of pages in this PdfPages collection.
sourcepub fn as_range(&self) -> Range<PdfPageIndex>
pub fn as_range(&self) -> Range<PdfPageIndex>
Returns a Range from 0..(number of pages)
for this PdfPages collection.
sourcepub fn as_range_inclusive(&self) -> RangeInclusive<PdfPageIndex>
pub fn as_range_inclusive(&self) -> RangeInclusive<PdfPageIndex>
Returns an inclusive Range from 0..=(number of pages - 1)
for this PdfPages collection.
sourcepub fn get(&self, index: PdfPageIndex) -> Result<PdfPage<'a>, PdfiumError>
pub fn get(&self, index: PdfPageIndex) -> Result<PdfPage<'a>, PdfiumError>
sourcepub fn first(&self) -> Result<PdfPage<'a>, PdfiumError>
pub fn first(&self) -> Result<PdfPage<'a>, PdfiumError>
sourcepub fn last(&self) -> Result<PdfPage<'a>, PdfiumError>
pub fn last(&self) -> Result<PdfPage<'a>, PdfiumError>
sourcepub fn create_page_at_start(
&mut self,
size: PdfPagePaperSize
) -> Result<PdfPage<'a>, PdfiumError>
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.
sourcepub fn create_page_at_end(
&mut self,
size: PdfPagePaperSize
) -> Result<PdfPage<'a>, PdfiumError>
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.
sourcepub fn create_page_at_index(
&mut self,
size: PdfPagePaperSize,
index: PdfPageIndex
) -> Result<PdfPage<'a>, PdfiumError>
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.
sourcepub fn copy_page_from_document(
&mut self,
source: &PdfDocument<'_>,
source_page_index: PdfPageIndex,
destination_page_index: PdfPageIndex
) -> Result<(), PdfiumError>
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.
sourcepub fn copy_pages_from_document(
&mut self,
source: &PdfDocument<'_>,
pages: &str,
destination_page_index: PdfPageIndex
) -> Result<(), PdfiumError>
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.
sourcepub fn copy_page_range_from_document(
&mut self,
source: &PdfDocument<'_>,
source_page_range: RangeInclusive<PdfPageIndex>,
destination_page_index: PdfPageIndex
) -> Result<(), PdfiumError>
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.
sourcepub fn append(&mut self, document: &PdfDocument<'_>) -> Result<(), PdfiumError>
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.
sourcepub fn tile_into_new_document(
&self,
rows_per_page: u8,
columns_per_row: u8,
size: PdfPagePaperSize
) -> Result<PdfDocument<'_>, PdfiumError>
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())
sourcepub fn page_mode(&self) -> PdfPageMode
pub fn page_mode(&self) -> PdfPageMode
Returns the PdfPageMode setting embedded in the containing PdfDocument.
sourcepub fn watermark<F>(&self, watermarker: F) -> Result<(), PdfiumError>where
F: Fn(&mut PdfPageGroupObject<'a>, PdfPageIndex, PdfPoints, PdfPoints) -> Result<(), PdfiumError>,
pub fn watermark<F>(&self, watermarker: F) -> Result<(), PdfiumError>where
F: Fn(&mut PdfPageGroupObject<'a>, PdfPageIndex, PdfPoints, PdfPoints) -> 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())
}
})?;
sourcepub fn iter(&self) -> PdfPagesIterator<'_> ⓘ
pub fn iter(&self) -> PdfPagesIterator<'_> ⓘ
Returns an iterator over all the pages in this PdfPages collection.