@@ -47,73 +47,3 @@ async function main() {
47
47
}
48
48
49
49
main ( ) ;
50
-
51
-
52
- /*
53
- import shutil
54
- import json
55
- import logging
56
- from pathlib import Path
57
- from asposepdfcloud import ApiClient, PdfApi, Signature, SignatureType, Rectangle
58
-
59
- # Configure logging
60
- logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
61
-
62
-
63
- class Config:
64
- """Configuration parameters."""
65
- CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json")
66
- LOCAL_FOLDER = Path(r"C:\Samples")
67
- PDF_DOCUMENT_NAME = "sample.pdf"
68
- SIGNATURE_FORM_FIELD = 'Signature_1'
69
-
70
-
71
- class PdfSignatures:
72
- """Class for managing PDF signatures using Aspose PDF Cloud API."""
73
- def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE):
74
- self.pdf_api = None
75
- self._init_api(credentials_file)
76
-
77
- def _init_api(self, credentials_file: Path):
78
- """Initialize the API client."""
79
- try:
80
- with credentials_file.open("r", encoding="utf-8") as file:
81
- credentials = json.load(file)
82
- api_key, app_id = credentials.get("key"), credentials.get("id")
83
- if not api_key or not app_id:
84
- raise ValueError("init_api(): Error: Missing API keys in the credentials file.")
85
- self.pdf_api = PdfApi(ApiClient(api_key, app_id))
86
- except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
87
- logging.error(f"init_api(): Failed to load credentials: {e}")
88
-
89
- def upload_document(self):
90
- """Upload a PDF document to the Aspose Cloud server."""
91
- if self.pdf_api:
92
- file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME
93
- try:
94
- self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path))
95
- logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.")
96
- except Exception as e:
97
- logging.error(f"Failed to upload file: {e}")
98
-
99
- def verify_signature(self):
100
- """Verify signature fields in the PDF document."""
101
- if self.pdf_api:
102
- try:
103
- response = self.pdf_api.get_verify_signature(Config.PDF_DOCUMENT_NAME, Config.SIGNATURE_FORM_FIELD)
104
- if response.code == 200:
105
- if response.valid == True:
106
- logging.info(f"verify_signature(): Signature is valid for the '{Config.PDF_DOCUMENT_NAME}' documen.")
107
- else:
108
- logging.error(f"verify_signature(): Signature is not valid for the '{Config.PDF_DOCUMENT_NAME}' documen.")
109
- else:
110
- logging.error(f"verify_signature(): Failed to verify signature for the document. Response code: {response.code}")
111
- except Exception as e:
112
- logging.error(f"verify_signature(): Error while verified signature: {e}")
113
-
114
-
115
- if __name__ == "__main__":
116
- pdf_sign = PdfSignatures()
117
- pdf_sign.upload_document()
118
- pdf_sign.verify_signature()
119
- */
0 commit comments