pub struct PdfAttachments<'a> { /* private fields */ }Expand description
The collection of PdfAttachment objects embedded in a PdfDocument.
Implementations§
Source§impl<'a> PdfAttachments<'a>
impl<'a> PdfAttachments<'a>
Sourcepub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings
Returns the PdfiumLibraryBindings used by this PdfAttachments collection.
Sourcepub fn len(&self) -> PdfAttachmentIndex
pub fn len(&self) -> PdfAttachmentIndex
Returns the number of attachments in this PdfAttachments collection.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this PdfAttachments collection is empty.
Sourcepub fn as_range(&self) -> Range<PdfAttachmentIndex>
pub fn as_range(&self) -> Range<PdfAttachmentIndex>
Returns a Range from 0..(number of attachments) for this PdfAttachments collection.
Sourcepub fn as_range_inclusive(&self) -> RangeInclusive<PdfAttachmentIndex>
pub fn as_range_inclusive(&self) -> RangeInclusive<PdfAttachmentIndex>
Returns an inclusive Range from 0..=(number of attachments - 1)
for this PdfAttachments collection.
Sourcepub fn get(
&self,
index: PdfAttachmentIndex,
) -> Result<PdfAttachment<'a>, PdfiumError>
pub fn get( &self, index: PdfAttachmentIndex, ) -> Result<PdfAttachment<'a>, PdfiumError>
Returns a single PdfAttachment from this PdfAttachments collection.
Sourcepub fn create_attachment_from_bytes(
&mut self,
name: &str,
bytes: &[u8],
) -> Result<PdfAttachment<'_>, PdfiumError>
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.
Sourcepub fn create_attachment_from_file(
&mut self,
name: &str,
path: &(impl AsRef<Path> + ?Sized),
) -> Result<PdfAttachment<'_>, PdfiumError>
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
FileorBlobobject (such as aFileobject 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.
Sourcepub fn create_attachment_from_reader<R: Read>(
&mut self,
name: &str,
reader: R,
) -> Result<PdfAttachment<'_>, PdfiumError>
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.
Sourcepub async fn create_attachment_from_fetch(
&'a mut self,
name: &str,
url: impl ToString,
) -> Result<PdfAttachment<'a>, PdfiumError>
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.
Sourcepub async fn create_attachment_from_blob(
&'a mut self,
name: &str,
blob: Blob,
) -> Result<PdfAttachment<'a>, PdfiumError>
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.
Sourcepub fn delete_at_index(
&mut self,
index: PdfAttachmentIndex,
) -> Result<(), PdfiumError>
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.
Sourcepub fn iter(&self) -> PdfAttachmentsIterator<'_> ⓘ
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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