@@ -34,50 +34,36 @@ def _init_api(self, credentials_file: Path):
34
34
except (FileNotFoundError , json .JSONDecodeError , ValueError ) as e :
35
35
logging .error (f"init_api(): Failed to load credentials: { e } " )
36
36
37
- def _ensure_api_initialized (self ):
38
- """ Check if the API is initialized before making API calls. """
39
- if not self .pdf_api :
40
- logging .error ("ensure_api_initialized(): PDF API is not initialized. Operation aborted." )
41
- return False
42
- return True
43
-
44
37
def upload_document (self ):
45
38
""" Upload a PDF document to the Aspose Cloud server. """
46
- if not self ._ensure_api_initialized ():
47
- return
48
-
49
- file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
50
- try :
51
- self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
52
- logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
53
- except Exception as e :
54
- logging .error (f"upload_document(): Failed to upload file: { e } " )
39
+ if self .pdf_api :
40
+ file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
41
+ try :
42
+ self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
43
+ logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
44
+ except Exception as e :
45
+ logging .error (f"upload_document(): Failed to upload file: { e } " )
55
46
56
47
def get_page_info (self ):
57
48
""" Get page information of the PDF document. """
58
- if not self ._ensure_api_initialized ():
59
- return
60
-
61
- result_pages : DocumentPagesResponse = self .pdf_api .get_page (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
49
+ if self .pdf_api :
50
+ result_pages : DocumentPagesResponse = self .pdf_api .get_page (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
62
51
63
- if result_pages .code == 200 :
64
- logging .info (f"Page #{ Config .PAGE_NUMBER } information: { result_pages .page } " )
65
- else :
66
- logging .error (f"Failed to get the page #{ Config .PAGE_NUMBER } ." )
52
+ if result_pages .code == 200 :
53
+ logging .info (f"Page #{ Config .PAGE_NUMBER } information: { result_pages .page } " )
54
+ else :
55
+ logging .error (f"Failed to get the page #{ Config .PAGE_NUMBER } ." )
67
56
68
57
def get_page_as_png (self ):
69
58
""" Get page information of the PDF document. """
70
- if not self ._ensure_api_initialized ():
71
- return
72
-
73
- try :
74
- result_pages = self .pdf_api .get_page_convert_to_png (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
75
- local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
76
- shutil .move (result_pages , str (local_path ))
77
- logging .info (f"download_result(): File successfully downloaded: { local_path } " )
78
- except Exception as e :
79
- logging .error (f"download_result(): Failed to download file: { e } " )
80
-
59
+ if self .pdf_api :
60
+ try :
61
+ result_pages = self .pdf_api .get_page_convert_to_png (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
62
+ local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
63
+ shutil .move (result_pages , str (local_path ))
64
+ logging .info (f"download_result(): File successfully downloaded: { local_path } " )
65
+ except Exception as e :
66
+ logging .error (f"download_result(): Failed to download file: { e } " )
81
67
82
68
if __name__ == "__main__" :
83
69
pdf_pages = PdfPages ()
0 commit comments