@@ -33,50 +33,36 @@ def _init_api(self, credentials_file: Path):
3333 except (FileNotFoundError , json .JSONDecodeError , ValueError ) as e :
3434 logging .error (f"init_api(): Failed to load credentials: { e } " )
3535
36- def _ensure_api_initialized (self ):
37- """ Check if the API is initialized before making API calls. """
38- if not self .pdf_api :
39- logging .error ("ensure_api_initialized(): PDF API is not initialized. Operation aborted." )
40- return False
41- return True
42-
4336 def upload_document (self ):
4437 """ Upload a PDF document to the Aspose Cloud server. """
45- if not self ._ensure_api_initialized ():
46- return
47-
48- file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
49- try :
50- self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
51- logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
52- except Exception as e :
53- logging .error (f"upload_document(): Failed to upload file: { e } " )
38+ if self .pdf_api :
39+ file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
40+ try :
41+ self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
42+ logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
43+ except Exception as e :
44+ logging .error (f"upload_document(): Failed to upload file: { e } " )
5445
5546 def download_result (self ):
5647 """ Download the processed PDF document from the Aspose Cloud server. """
57- if not self ._ensure_api_initialized ():
58- return
59-
60- try :
61- temp_file = self .pdf_api .download_file (Config .PDF_DOCUMENT_NAME )
62- local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
63- shutil .move (temp_file , 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 } " )
48+ if self .pdf_api :
49+ try :
50+ temp_file = self .pdf_api .download_file (Config .PDF_DOCUMENT_NAME )
51+ local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
52+ shutil .move (temp_file , str (local_path ))
53+ logging .info (f"download_result(): File successfully downloaded: { local_path } " )
54+ except Exception as e :
55+ logging .error (f"download_result(): Failed to download file: { e } " )
6756
6857 def move_page (self ):
6958 """ Moves a page to a new location in the PDF document. """
70- if not self ._ensure_api_initialized ():
71- return
72-
73- response : AsposeResponse = self .pdf_api .post_move_page (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER , Config .PAGE_NUMBER + 1 )
59+ if self .pdf_api :
60+ response : AsposeResponse = self .pdf_api .post_move_page (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER , Config .PAGE_NUMBER + 1 )
7461
75- if response .code == 200 :
76- logging .info (f"Page #{ Config .PAGE_NUMBER } has been moved to position #{ Config .PAGE_NUMBER + 1 } ." )
77- else :
78- logging .error ("Failed to move a new page." )
79-
62+ if response .code == 200 :
63+ logging .info (f"Page #{ Config .PAGE_NUMBER } has been moved to position #{ Config .PAGE_NUMBER + 1 } ." )
64+ else :
65+ logging .error ("Failed to move a new page." )
8066
8167if __name__ == "__main__" :
8268 pdf_pages = PdfPages ()
0 commit comments