diff --git a/contributors/ CNSeniorious000/pdf.py b/contributors/ CNSeniorious000/pdf.py index ba9dddc49ae161bf0a5964079b825e7098be0f8a..2ff4f5c7271dc611c417f3c01300c5ee601d8109 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)