From 5db09e25f7a1eb382d4abc4c374b6124d878740a Mon Sep 17 00:00:00 2001 From: yaaakaaang <1639972003@qq.com> Date: Fri, 19 Apr 2024 21:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8pdf.py=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contributors/ CNSeniorious000/pdf.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/contributors/ CNSeniorious000/pdf.py b/contributors/ CNSeniorious000/pdf.py index ba9dddc..2ff4f5c 100644 --- a/contributors/ CNSeniorious000/pdf.py +++ b/contributors/ CNSeniorious000/pdf.py @@ -1,4 +1,5 @@ # from functools import cache, cached_property +# import requests # # # # PDF与栅格化 @@ -14,16 +15,28 @@ # """a path refers to only one document""" # return object.__new__(cls) # -# def __init__(self, path: str): +# def __init__(self, path: str) -> None: # """load from disk or internet""" -# if path.startswith("http"): -# import requests -# self.raw = requests.get(path).content -# else: -# self.raw = open(path, "rb").read() +# +# def __init__(self, path: str) -> None: +# """Load data from disk or the internet.""" +# try: +# if path.startswith("http"): +# # 从互联网加载数据 +# self.raw = requests.get(path).content +# else: +# # 从磁盘加载数据 +# with open(path, "rb") as file: +# self.raw = file.read() +# except requests.RequestException as e: +# print(f"Error fetching data from URL: {e}") +# except FileNotFoundError as e: +# print(f"Error opening file: {e}") +# except Exception as e: +# print(f"An unexpected error occurred: {e}") # # @cached_property -# def doc(self): +# def doc(self) -> fitz.Document: # import fitz # # noinspection PyUnresolvedReferences # return fitz.open(stream=self.raw) -- Gitee