Struct pdfium_render::attachments::PdfAttachments
source · [−]pub struct PdfAttachments<'a> { /* private fields */ }Expand description
The collection of PdfAttachment objects embedded in a PdfDocument.
Implementations
sourceimpl<'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(
&self,
name: &str,
bytes: &[u8]
) -> Result<PdfAttachment<'_>, PdfiumError>
pub fn create_attachment_from_bytes(
&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(
&self,
name: &str,
path: &impl AsRef<Path> + ?Sized
) -> Result<PdfAttachment<'_>, PdfiumError>
pub fn create_attachment_from_file(
&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-infetch()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.
sourcepub fn create_attachment_from_reader<R: Read>(
&self,
name: &str,
reader: R
) -> Result<PdfAttachment<'_>, PdfiumError>
pub fn create_attachment_from_reader<R: Read>(
&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 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<'_>ⓘNotable traits for PdfAttachmentsIterator<'a>impl<'a> Iterator for PdfAttachmentsIterator<'a> type Item = PdfAttachment<'a>;
pub fn iter(&self) -> PdfAttachmentsIterator<'_>ⓘNotable traits for PdfAttachmentsIterator<'a>impl<'a> Iterator for PdfAttachmentsIterator<'a> type Item = PdfAttachment<'a>;
Returns an iterator over all the attachments in this PdfAttachments collection.