pub struct PdfFileLoader<'a, T> { /* private fields */ }pdf only.Expand description
Iterator pipeline for loading PDF documents and extracting text synchronously. Loading and extraction errors are yielded per item unless filtered.
Implementations§
Source§impl<'a, T: Loadable + 'a> PdfFileLoader<'a, T>
impl<'a, T: Loadable + 'a> PdfFileLoader<'a, T>
Sourcepub fn load(self) -> PdfFileLoader<'a, Result<Document, PdfLoaderError>>
pub fn load(self) -> PdfFileLoader<'a, Result<Document, PdfLoaderError>>
Parses each input as a PDF during iteration, yielding document-loading errors.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?.load().into_iter();
for result in content {
match result {
Ok(doc) => println!("{doc:?}"),
Err(e) => eprintln!("Error reading pdf: {e}"),
}
}Sourcepub fn load_with_path(
self,
) -> PdfFileLoader<'a, Result<(PathBuf, Document), PdfLoaderError>>
pub fn load_with_path( self, ) -> PdfFileLoader<'a, Result<(PathBuf, Document), PdfLoaderError>>
Parses each PDF and pairs it with its path, yielding loading errors.
In-memory inputs use the path <memory>.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?.load_with_path().into_iter();
for result in content {
match result {
Ok((path, doc)) => println!("{path:?} {doc:?}"),
Err(e) => eprintln!("Error reading pdf: {e}"),
}
}Source§impl<'a, T: Loadable + 'a> PdfFileLoader<'a, T>
impl<'a, T: Loadable + 'a> PdfFileLoader<'a, T>
Sourcepub fn read(self) -> PdfFileLoader<'a, Result<String, PdfLoaderError>>
pub fn read(self) -> PdfFileLoader<'a, Result<String, PdfLoaderError>>
Loads each PDF and concatenates its page text without separators. Yields a loading error or the first page-extraction error for each document.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?.read().into_iter();
for result in content {
match result {
Ok(content) => println!("{content}"),
Err(e) => eprintln!("Error reading pdf: {e}"),
}
}Sourcepub fn read_with_path(
self,
) -> PdfFileLoader<'a, Result<(PathBuf, String), PdfLoaderError>>
pub fn read_with_path( self, ) -> PdfFileLoader<'a, Result<(PathBuf, String), PdfLoaderError>>
Loads each PDF and pairs its path with concatenated page text.
Yields loading or extraction errors; in-memory inputs use <memory>.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?.read_with_path().into_iter();
for result in content {
match result {
Ok((path, content)) => println!("{path:?} {content}"),
Err(e) => eprintln!("Error reading pdf: {e}"),
}
}Source§impl<'a> PdfFileLoader<'a, Document>
impl<'a> PdfFileLoader<'a, Document>
Sourcepub fn by_page(self) -> PdfFileLoader<'a, Result<String, PdfLoaderError>>
pub fn by_page(self) -> PdfFileLoader<'a, Result<String, PdfLoaderError>>
Yields page text in document order, flattening all documents into one sequence of per-page extraction results.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?
.load()
.ignore_errors()
.by_page()
.into_iter();
for result in content {
match result {
Ok(page) => println!("{page}"),
Err(e) => eprintln!("Error reading pdf: {e}"),
}
}Source§impl<'a> PdfFileLoader<'a, (PathBuf, Document)>
impl<'a> PdfFileLoader<'a, (PathBuf, Document)>
Sourcepub fn by_page(
self,
) -> PdfFileLoader<'a, (PathBuf, Vec<(usize, Result<String, PdfLoaderError>)>)>
pub fn by_page( self, ) -> PdfFileLoader<'a, (PathBuf, Vec<(usize, Result<String, PdfLoaderError>)>)>
Pairs each source path with zero-based page numbers and extraction results.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?
.load_with_path()
.ignore_errors()
.by_page()
.into_iter();
for (path, pages) in content {
println!("{}", path.display());
for (pageno, result) in pages {
match result {
Ok(content) => println!("Page {pageno}: {content}"),
Err(e) => eprintln!("Error reading page: {e}"),
}
}
}Source§impl<'a> PdfFileLoader<'a, (PathBuf, Vec<(usize, Result<String, PdfLoaderError>)>)>
impl<'a> PdfFileLoader<'a, (PathBuf, Vec<(usize, Result<String, PdfLoaderError>)>)>
Sourcepub fn ignore_errors(self) -> PdfFileLoader<'a, (PathBuf, Vec<(usize, String)>)>
pub fn ignore_errors(self) -> PdfFileLoader<'a, (PathBuf, Vec<(usize, String)>)>
Drops failed pages while retaining each document’s path and original zero-based page numbers. Documents with no successful pages remain.
let content = PdfFileLoader::with_glob("tests/data/*.pdf")?
.load_with_path()
.ignore_errors()
.by_page()
.ignore_errors();
for (_path, pages) in content {
println!("{}", pages.len())
}Source§impl<'a, T: 'a> PdfFileLoader<'a, Result<T, PdfLoaderError>>
impl<'a, T: 'a> PdfFileLoader<'a, Result<T, PdfLoaderError>>
Sourcepub fn ignore_errors(self) -> PdfFileLoader<'a, T>
pub fn ignore_errors(self) -> PdfFileLoader<'a, T>
Discards error items and yields unwrapped successful values.
Source§impl<'a> PdfFileLoader<'a, Result<PathBuf, PdfLoaderError>>
impl<'a> PdfFileLoader<'a, Result<PathBuf, PdfLoaderError>>
Sourcepub fn with_glob(
pattern: &str,
) -> Result<PdfFileLoader<'_, Result<PathBuf, PdfLoaderError>>, PdfLoaderError>
pub fn with_glob( pattern: &str, ) -> Result<PdfFileLoader<'_, Result<PathBuf, PdfLoaderError>>, PdfLoaderError>
Creates a loader over glob matches. Invalid patterns fail immediately; traversal errors are yielded during iteration.
Sourcepub fn with_dir(
directory: &str,
) -> Result<PdfFileLoader<'_, Result<PathBuf, PdfLoaderError>>, PdfLoaderError>
pub fn with_dir( directory: &str, ) -> Result<PdfFileLoader<'_, Result<PathBuf, PdfLoaderError>>, PdfLoaderError>
Creates a new loader on all entries within a directory. Entries are not filtered: a non-file entry’s path is yielded too and surfaces as an error when loaded.
Source§impl<'a> PdfFileLoader<'a, Vec<u8>>
impl<'a> PdfFileLoader<'a, Vec<u8>>
Sourcepub fn from_bytes(bytes: Vec<u8>) -> PdfFileLoader<'a, Vec<u8>>
pub fn from_bytes(bytes: Vec<u8>) -> PdfFileLoader<'a, Vec<u8>>
Ingest a document as a byte array.
Sourcepub fn from_bytes_multi(bytes_vec: Vec<Vec<u8>>) -> PdfFileLoader<'a, Vec<u8>>
pub fn from_bytes_multi(bytes_vec: Vec<Vec<u8>>) -> PdfFileLoader<'a, Vec<u8>>
Ingest multiple byte arrays.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !RefUnwindSafe for PdfFileLoader<'a, T>
impl<'a, T> !Send for PdfFileLoader<'a, T>
impl<'a, T> !Sync for PdfFileLoader<'a, T>
impl<'a, T> !UnwindSafe for PdfFileLoader<'a, T>
impl<'a, T> Freeze for PdfFileLoader<'a, T>
impl<'a, T> Unpin for PdfFileLoader<'a, T>
impl<'a, T> UnsafeUnpin for PdfFileLoader<'a, T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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