MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / extract_pdf_content

Method extract_pdf_content

core/src/document_loader.rs:684–706  ·  view source on GitHub ↗

Extract content from PDF files

(file_path: &str)

Source from the content-addressed store, hash-verified

682
683 /// Extract content from PDF files
684 async fn extract_pdf_content(file_path: &str) -> GraphBitResult<String> {
685 // Read the PDF file into memory
686 let bytes = std::fs::read(file_path).map_err(|e| {
687 GraphBitError::validation("document_loader", format!("Failed to read PDF file: {e}"))
688 })?;
689
690 // Use pdf-extract for better text extraction with proper Unicode support
691 let text_content = pdf_extract::extract_text_from_mem(&bytes).map_err(|e| {
692 GraphBitError::validation(
693 "document_loader",
694 format!("Failed to extract text from PDF: {e}"),
695 )
696 })?;
697
698 if text_content.trim().is_empty() {
699 return Err(GraphBitError::validation(
700 "document_loader",
701 "No text content could be extracted from the PDF",
702 ));
703 }
704
705 Ok(text_content.trim().to_string())
706 }
707
708 /// Extract content from DOCX files
709 async fn extract_docx_content(file_path: &str) -> GraphBitResult<String> {

Callers

nothing calls this directly

Calls 2

to_stringMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected