Skip to main content

PdfPageText

Struct PdfPageText 

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

The collection of Unicode characters visible on a single PdfPage.

Use the PdfPageText::all() function to easily return all characters in the containing PdfPage in the order in which they are defined in the PDF file.

Use the PdfPageText::search() function to initialise a new PdfPageTextSearch object, yielding the results of searching for a target string within the character collection.

In complex custom layouts, the order in which characters are defined in the document and the order in which they appear visually during rendering (and thus the order in which they are read by a user) may not necessarily match.

PdfPageText implements both the ToString and the Display traits.

Implementations§

Source§

impl<'a> PdfPageText<'a>

Source

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

Returns the PdfiumLibraryBindings used by this PdfPageText.

Source

pub fn len(&self) -> i32

Returns the total number of characters in all text segments in the containing PdfPage.

The character count includes whitespace and newlines, and so may differ slightly from the result of calling PdfPageText::all().len().

Source

pub fn is_empty(&self) -> bool

Returns true if there are no characters in any text box collection in the containing PdfPage.

Source

pub fn segments(&self) -> PdfPageTextSegments<'_>

Returns a collection of all the PdfPageTextSegment text segments in the containing PdfPage.

Source

pub fn segments_subset( &self, start: PdfPageTextCharIndex, count: PdfPageTextCharIndex, ) -> PdfPageTextSegments<'_>

Returns a subset of the PdfPageTextSegment text segments in the containing PdfPage. Only text segments containing characters in the given index range will be included.

Source

pub fn chars(&self) -> PdfPageTextChars<'_>

Returns a collection of all the PdfPageTextChar characters in the containing PdfPage.

Source

pub fn chars_for_object( &self, object: &PdfPageTextObject<'_>, ) -> Result<PdfPageTextChars<'_>, PdfiumError>

Returns a collection of all the PdfPageTextChar characters in the given PdfPageTextObject.

The return result will be empty if the given PdfPageTextObject is not attached to the containing PdfPage.

Source

pub fn chars_for_annotation( &self, annotation: &PdfPageAnnotation<'_>, ) -> Result<PdfPageTextChars<'_>, PdfiumError>

Returns a collection of all the PdfPageTextChar characters in the given PdfPageAnnotation.

The return result will be empty if the given PdfPageAnnotation is not attached to the containing PdfPage.

Source

pub fn chars_inside_rect( &self, rect: PdfRect, ) -> Result<PdfPageTextChars<'_>, PdfiumError>

Returns a collection of all the PdfPageTextChar characters that lie within the bounds of the given PdfRect in the containing PdfPage.

Source

pub fn all(&self) -> String

Returns all characters that lie within the containing PdfPage, in the order in which they are defined in the document, concatenated into a single string.

In complex custom layouts, the order in which characters are defined in the document and the order in which they appear visually during rendering (and thus the order in which they are read by a user) may not necessarily match.

Source

pub fn all_respaced(&self, space_ratio: f32) -> String

Returns all page text with corrected word spacing, filtering out spurious spaces that pdfium inserts mid-word due to aggressive inter-glyph heuristics.

For each generated space character (is_generated() == true), checks whether the horizontal gap between the preceding character’s right edge and the following character’s left edge exceeds font_size * space_ratio. Only inserts a space when the gap is large enough to represent a true word boundary.

space_ratio controls sensitivity: 0.25 matches MinerU’s threshold.

Source

pub fn inside_rect(&self, rect: PdfRect) -> String

Returns all characters that lie within the bounds of the given PdfRect in the containing PdfPage, in the order in which they are defined in the document, concatenated into a single string.

In complex custom layouts, the order in which characters are defined in the document and the order in which they appear visually during rendering (and thus the order in which they are read by a user) may not necessarily match.

Source

pub fn inside_rect_respaced(&self, rect: PdfRect, space_ratio: f32) -> String

Returns text within the given rectangle with corrected word spacing.

Like [inside_rect()] but reconstructs text from individual characters, filtering out spurious spaces that pdfium inserts mid-word. See [all_respaced()] for details on the space_ratio parameter.

Source

pub fn for_object(&self, object: &PdfPageTextObject<'_>) -> String

Returns all characters assigned to the given PdfPageTextObject in this PdfPageText object, concatenated into a single string.

Source

pub fn text_object_for_char_index(&self, index: usize) -> Option<usize>

Returns the raw FPDF_PAGEOBJECT handle for the text object that contains the character at the given index, or None if the index is out of range or the character is not associated with a text object (e.g. generated chars).

The returned handle is an opaque pointer suitable for identity comparison (same pointer = same text object). Cast to usize for storage.

Source

pub fn for_annotation( &self, annotation: &PdfPageAnnotation<'_>, ) -> Result<String, PdfiumError>

Returns all characters that lie within the bounds of the given PdfPageAnnotation in the containing PdfPage, in the order in which they are defined in the document, concatenated into a single string.

In complex custom layouts, the order in which characters are defined in the document and the order in which they appear visually during rendering (and thus the order in which they are read by a user) may not necessarily match.

Source

pub fn search( &self, text: &str, options: &PdfSearchOptions, ) -> Result<PdfPageTextSearch<'_>, PdfiumError>

Starts a search for the given text string, returning a new PdfPageTextSearch object that can be used to step through the search results.

Source

pub fn search_from( &self, text: &str, options: &PdfSearchOptions, index: PdfPageTextCharIndex, ) -> Result<PdfPageTextSearch<'_>, PdfiumError>

Starts a search for the given test string from the given character position, returning a new PdfPageTextSearch object that can be used to step through the search results.

Trait Implementations§

Source§

impl<'a> Display for PdfPageText<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Drop for PdfPageText<'a>

Source§

fn drop(&mut self)

Closes the PdfPageText collection, releasing held memory.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> Freeze for PdfPageText<'a>

§

impl<'a> Unpin for PdfPageText<'a>

§

impl<'a> UnsafeUnpin for PdfPageText<'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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.