This commit is contained in:
yumoqing 2025-05-20 13:15:12 +08:00
parent 91ed098680
commit df664fd29c

View File

@ -9,7 +9,7 @@ from bs4 import BeautifulSoup
from pptx import Presentation from pptx import Presentation
from openpyxl import load_workbook from openpyxl import load_workbook
import mobi import mobi
import PyPDF2 from pypdf import PdfReader
import html2text import html2text
class MyMobiLoader: class MyMobiLoader:
@ -48,16 +48,16 @@ class MyChmLoader:
class MyPdfLoader: class MyPdfLoader:
def __init__(self, file_path, **kw): def __init__(self, file_path, **kw):
self.filepath = file_path self.filepath = file_path
self.reader = None
def load(self): def load(self):
"""Reads the PDF file and returns all text as a single string.""" """Reads the PDF file and returns all text as a single string."""
text = '' text = ''
with open(self.filepath, 'rb') as file: reader = PdfReader(self.filepath)
self.reader = PyPDF2.PdfReader(file) pts = []
for page in self.reader.pages: for page in reader.pages:
text += page.extract_text() or '' t = page.extract_text() or ''
return ' '.join(text.split('\t')) pts.append(' '.join(t.split('\t')))
return ' '.join(pts)
class MyDocLoader: class MyDocLoader:
def __init__(self, file_path): def __init__(self, file_path):