Skip to main content

elizaos_plugin_pdf/
lib.rs

1#![allow(missing_docs)]
2
3pub mod client;
4pub mod error;
5pub mod service;
6pub mod types;
7
8pub use client::PdfClient;
9pub use error::{PdfError, Result};
10pub use service::PdfService;
11pub use types::*;
12
13#[allow(unused_imports)]
14use anyhow::Result as AnyhowResult;
15
16/// PDF plugin for elizaOS.
17///
18/// This struct wraps the PDF client and provides a simple interface
19/// for PDF processing operations.
20pub struct PdfPlugin {
21    client: PdfClient,
22}
23
24impl PdfPlugin {
25    /// Create a new PDF plugin.
26    pub fn new() -> Self {
27        Self {
28            client: PdfClient::new(),
29        }
30    }
31
32    pub async fn extract_text(
33        &self,
34        pdf_bytes: &[u8],
35        options: Option<PdfExtractionOptions>,
36    ) -> Result<String> {
37        self.client.extract_text(pdf_bytes, options).await
38    }
39
40    /// Extract text from a PDF file.
41    pub async fn extract_text_from_file(
42        &self,
43        file_path: &str,
44        options: Option<PdfExtractionOptions>,
45    ) -> Result<String> {
46        self.client.extract_text_from_file(file_path, options).await
47    }
48
49    pub async fn convert_to_text(
50        &self,
51        pdf_bytes: &[u8],
52        options: Option<PdfExtractionOptions>,
53    ) -> PdfConversionResult {
54        self.client.convert_to_text(pdf_bytes, options).await
55    }
56
57    /// Get full document information.
58    pub async fn get_document_info(&self, pdf_bytes: &[u8]) -> Result<PdfDocumentInfo> {
59        self.client.get_document_info(pdf_bytes).await
60    }
61
62    pub async fn get_page_count(&self, pdf_bytes: &[u8]) -> Result<usize> {
63        self.client.get_page_count(pdf_bytes).await
64    }
65
66    pub fn client(&self) -> &PdfClient {
67        &self.client
68    }
69}
70
71impl Default for PdfPlugin {
72    fn default() -> Self {
73        Self::new()
74    }
75}
76
77pub fn get_pdf_plugin() -> PdfPlugin {
78    PdfPlugin::new()
79}