@@ -35,57 +35,49 @@ def _init_api(self, credentials_file: Path):
35
35
except (FileNotFoundError , json .JSONDecodeError , ValueError ) as e :
36
36
logging .error (f"init_api(): Failed to load credentials: { e } " )
37
37
38
- def _ensure_api_initialized (self ):
39
- """ Check if the API is initialized before making API calls. """
40
- if not self .pdf_api :
41
- logging .error ("ensure_api_initialized(): PDF API is not initialized. Operation aborted." )
42
- return False
43
- return True
44
-
45
38
def upload_document (self ):
46
39
""" Upload a PDF document to the Aspose Cloud server. """
47
- if not self ._ensure_api_initialized ():
48
- return
49
-
50
- file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
51
- try :
52
- self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
53
- logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
54
- except Exception as e :
55
- logging .error (f"upload_document(): Failed to upload file: { e } " )
40
+ if self .pdf_api :
41
+ file_path = Config .LOCAL_FOLDER / Config .PDF_DOCUMENT_NAME
42
+ try :
43
+ self .pdf_api .upload_file (Config .PDF_DOCUMENT_NAME , str (file_path ))
44
+ logging .info (f"upload_document(): File { Config .PDF_DOCUMENT_NAME } uploaded successfully." )
45
+ except Exception as e :
46
+ logging .error (f"upload_document(): Failed to upload file: { e } " )
56
47
57
48
def download_result (self ):
58
49
""" Download the processed PDF document from the Aspose Cloud server. """
59
- if not self ._ensure_api_initialized ():
60
- return
61
-
62
- try :
63
- temp_file = self .pdf_api .download_file (Config .PDF_DOCUMENT_NAME )
64
- local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
65
- shutil .move (temp_file , str (local_path ))
66
- logging .info (f"download_result(): File successfully downloaded: { local_path } " )
67
- except Exception as e :
68
- logging .error (f"download_result(): Failed to download file: { e } " )
50
+ if self .pdf_api :
51
+ try :
52
+ file_path = self .pdf_api .download_file (Config .PDF_DOCUMENT_NAME )
53
+ local_path = Config .LOCAL_FOLDER / Config .LOCAL_RESULT_DOCUMENT_NAME
54
+ shutil .move (file_path , str (local_path ))
55
+ logging .info (f"download_result(): File successfully downloaded: { local_path } " )
56
+ except Exception as e :
57
+ logging .error (f"download_result(): Failed to download file: { e } " )
69
58
70
59
def delete_page_stamps (self ):
71
60
""" Remove stamp in a specific page of the PDF document. """
72
-
73
- response : AsposeResponse = self .pdf_api .delete_page_stamps (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
74
-
75
- if response .code == 200 :
76
- logging .info (f"Stamps on page #{ Config .PAGE_NUMBER } was deleted for the document '{ Config .PDF_DOCUMENT_NAME } '." )
77
- else :
78
- logging .error (f"Failed to remove stamps on page #{ Config .PAGE_NUMBER } for the document '{ Config .PDF_DOCUMENT_NAME } '." )
61
+ if self . pdf_api :
62
+ response : AsposeResponse = self .pdf_api .delete_page_stamps (Config .PDF_DOCUMENT_NAME , Config .PAGE_NUMBER )
63
+
64
+ if response .code == 200 :
65
+ logging .info (f"Stamps on page #{ Config .PAGE_NUMBER } was deleted for the document '{ Config .PDF_DOCUMENT_NAME } '." )
66
+ else :
67
+ logging .error (f"Failed to remove stamps on page #{ Config .PAGE_NUMBER } for the document '{ Config .PDF_DOCUMENT_NAME } '." )
79
68
80
69
def delete_stamp_by_id (self ):
81
70
""" Remove stamp by Id in the PDF document. """
82
-
83
- response : AsposeResponse = self .pdf_api .delete_stamp (Config .PDF_DOCUMENT_NAME , Config .STAMP_ID )
84
-
85
- if response .code == 200 :
86
- logging .info (f"Stamps with Id '{ Config .STAMP_ID } ' was deleted for the document '{ Config .PDF_DOCUMENT_NAME } '." )
87
- else :
88
- logging .error (f"Failed to remove stamp with Id '{ Config .STAMP_ID } ' for the document '{ Config .PDF_DOCUMENT_NAME } '." )
71
+ if self .pdf_api :
72
+ try :
73
+ response : AsposeResponse = self .pdf_api .delete_stamp (Config .PDF_DOCUMENT_NAME , Config .STAMP_ID )
74
+
75
+ if response .code == 200 :
76
+ logging .info (f"Stamps with Id '{ Config .STAMP_ID } ' was deleted for the document '{ Config .PDF_DOCUMENT_NAME } '." )
77
+ else :
78
+ logging .error (f"Failed to remove stamp with Id '{ Config .STAMP_ID } ' for the document '{ Config .PDF_DOCUMENT_NAME } '." )
79
+ except Exception as e :
80
+ logging .error (f"delete_stamp_by_id(): Failed to download file: { e } " )
89
81
90
82
if __name__ == "__main__" :
91
83
pdf_stamps = PdfStamps ()
0 commit comments