Skip to main content

PlainTextExtractor

Struct PlainTextExtractor 

Source
pub struct PlainTextExtractor { /* private fields */ }
Expand description

Plain text extractor with simplified API

Extracts text from PDF pages without maintaining position information, providing a simpler API by returning String and Vec<String> instead of Vec<TextFragment>.

§Architecture

This extractor uses the same content stream parser as TextExtractor, but discards position metadata to provide a simpler output format. It tracks minimal position data (x, y coordinates) to determine spacing and line breaks, then returns clean text strings.

§Performance Characteristics

  • Memory: O(1) position tracking vs O(n) fragments
  • CPU: No fragment sorting, no width calculations
  • Performance: Comparable to TextExtractor (same parser)

§Thread Safety

PlainTextExtractor is thread-safe and can be reused across multiple pages and documents. Create once, use many times.

§Examples

§Basic Usage

use oxidize_pdf::parser::PdfReader;
use oxidize_pdf::text::plaintext::PlainTextExtractor;

let doc = PdfReader::open_document("document.pdf")?;

let mut extractor = PlainTextExtractor::new();
let result = extractor.extract(&doc, 0)?;

println!("{}", result.text);

§Custom Configuration

use oxidize_pdf::parser::PdfReader;
use oxidize_pdf::text::plaintext::{PlainTextExtractor, PlainTextConfig};

let doc = PdfReader::open_document("document.pdf")?;

let config = PlainTextConfig {
    space_threshold: 0.3,
    newline_threshold: 12.0,
    preserve_layout: true,
    line_break_mode: oxidize_pdf::text::plaintext::LineBreakMode::Normalize,
};

let mut extractor = PlainTextExtractor::with_config(config);
let result = extractor.extract(&doc, 0)?;

Implementations§

Source§

impl PlainTextExtractor

Source

pub fn new() -> Self

Create a new extractor with default configuration

§Examples
use oxidize_pdf::text::plaintext::PlainTextExtractor;

let extractor = PlainTextExtractor::new();
Source

pub fn with_config(config: PlainTextConfig) -> Self

Create a new extractor with custom configuration

§Examples
use oxidize_pdf::text::plaintext::{PlainTextExtractor, PlainTextConfig};

let config = PlainTextConfig::dense();
let extractor = PlainTextExtractor::with_config(config);
Source

pub fn extract<R: Read + Seek>( &mut self, document: &PdfDocument<R>, page_index: u32, ) -> ParseResult<PlainTextResult>

Extract plain text from a PDF page

Returns text with spaces and newlines inserted according to the configured thresholds. Position information is not included in the result.

§Output

Returns a PlainTextResult containing the extracted text as a String, along with character count and line count metadata. This is simpler than TextExtractor which returns Vec<TextFragment> with position data.

§Examples
use oxidize_pdf::parser::PdfReader;
use oxidize_pdf::text::plaintext::PlainTextExtractor;

let doc = PdfReader::open_document("document.pdf")?;

let mut extractor = PlainTextExtractor::new();
let result = extractor.extract(&doc, 0)?; // page index 0 = first page

println!("Extracted {} characters", result.char_count);
Source

pub fn extract_lines<R: Read + Seek>( &mut self, document: &PdfDocument<R>, page_index: u32, ) -> ParseResult<Vec<String>>

Extract text as individual lines

Returns a vector of strings, one for each line detected in the page. Useful for grep-like operations or line-based processing.

§Examples
use oxidize_pdf::parser::PdfReader;
use oxidize_pdf::text::plaintext::PlainTextExtractor;

let doc = PdfReader::open_document("document.pdf")?;

let mut extractor = PlainTextExtractor::new();
let lines = extractor.extract_lines(&doc, 0)?;

for (i, line) in lines.iter().enumerate() {
    println!("{}: {}", i + 1, line);
}
Source

pub fn config(&self) -> &PlainTextConfig

Get the current configuration

§Examples
use oxidize_pdf::text::plaintext::{PlainTextExtractor, PlainTextConfig};

let config = PlainTextConfig::dense();
let extractor = PlainTextExtractor::with_config(config.clone());
assert_eq!(extractor.config().space_threshold, 0.1);

Trait Implementations§

Source§

impl Default for PlainTextExtractor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more