PdfAttachments

Struct PdfAttachments 

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

The collection of PdfAttachment objects embedded in a PdfDocument.

Implementations§

Source§

impl<'a> PdfAttachments<'a>

Source

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

Returns the PdfiumLibraryBindings used by this PdfAttachments collection.

Source

pub fn len(&self) -> PdfAttachmentIndex

Returns the number of attachments in this PdfAttachments collection.

Source

pub fn is_empty(&self) -> bool

Returns true if this PdfAttachments collection is empty.

Source

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

Returns a Range from 0..(number of attachments) for this PdfAttachments collection.

Source

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

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

Source

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

Returns a single PdfAttachment from this PdfAttachments collection.

Source

pub fn create_attachment_from_bytes( &mut self, name: &str, bytes: &[u8], ) -> Result<PdfAttachment<'_>, PdfiumError>

Attempts to add a new PdfAttachment to this collection, using the given name and the data in the given byte buffer. An error will be returned if the given name is not unique in the list of attachments already present in the containing PDF document.

Source

pub fn create_attachment_from_file( &mut self, name: &str, path: &(impl AsRef<Path> + ?Sized), ) -> Result<PdfAttachment<'_>, PdfiumError>

Attempts to add a new PdfAttachment to this collection, using the given name and file path. Byte data from the given file path will be embedded directly into the containing document. An error will be returned if the given name is not unique in the list of attachments already present in the containing PDF document.

This function is not available when compiling to WASM. You have several options for loading attachment data in WASM:

  • Use the PdfAttachments::create_attachment_from_fetch() function to download attachment data from a URL using the browser’s built-in fetch() API. This function is only available when compiling to WASM.
  • Use the PdfAttachments::create_attachment_from_blob() function to load attachment data from a Javascript File or Blob object (such as a File object returned from an HTML <input type="file"> element). This function is only available when compiling to WASM.
  • Use another method to retrieve the bytes of the target attachment over the network, then load those bytes into Pdfium using the PdfAttachments::create_attachment_from_bytes() function.
  • Embed the bytes of the target attachment directly into the compiled WASM module using the include_bytes!() macro.
Source

pub fn create_attachment_from_reader<R: Read>( &mut self, name: &str, reader: R, ) -> Result<PdfAttachment<'_>, PdfiumError>

Attempts to add a new PdfAttachment to this collection, using the given name and the given reader. Byte data from the given reader will be embedded directly into the containing document. An error will be returned if the given name is not unique in the list of attachments already present in the containing PDF document.

Source

pub async fn create_attachment_from_fetch( &'a mut self, name: &str, url: impl ToString, ) -> Result<PdfAttachment<'a>, PdfiumError>

Attempts to add a new PdfAttachment to this collection by loading attachment data from the given URL. The Javascript fetch() API is used to download data over the network. Byte data retrieved from the given URL will be embedded directly into the containing document. An error will be returned if the given name is not unique in the list of attachments already present in the containing PDF document.

This function is only available when compiling to WASM.

Source

pub async fn create_attachment_from_blob( &'a mut self, name: &str, blob: Blob, ) -> Result<PdfAttachment<'a>, PdfiumError>

Attempts to create a new PdfAttachment to this collection, using the given name and the given Blob. Byte data from the given Blob will be embedded directly into the containing document. An error will be returned if the given name is not unique in the list of attachments already present in the containing PDF document. A File object returned from a FileList is a suitable Blob:

<input id="filePicker" type="file">

const file = document.getElementById('filePicker').files[0];

This function is only available when compiling to WASM.

Source

pub fn delete_at_index( &mut self, index: PdfAttachmentIndex, ) -> Result<(), PdfiumError>

Deletes the attachment at the given index from this PdfAttachments collection.

Pdfium’s current implementation of this action does not remove the attachment data from the document; it simply removes the attachment’s index entry from the document, so that the attachment no longer appears in the list of attachments. This behavior may change in the future.

Source

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

Returns an iterator over all the attachments in this PdfAttachments collection.

Auto Trait Implementations§

§

impl<'a> Freeze for PdfAttachments<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for PdfAttachments<'a>

§

impl<'a> !UnwindSafe for PdfAttachments<'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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

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

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.