diff --git a/README.md b/README.md index 66545be..e45d917 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,8 @@ XLS, XLSX, PPTX, DOC, DOCX, MobiXML, JPEG, EMF, PNG, BMP, GIF, TIFF, Text ## Read PDF Formats MHT, PCL, PS, XSLFO, MD -## Enhancements in Version 25.1 +## Enhancements in Version 25.2 - A new version of Aspose.PDF Cloud was prepared using the latest version of Aspose.PDF for .NET. - ## Requirements. Python 2.7 and 3.4+ diff --git a/Uses-Cases/Attachments/add/appendAttachments.py b/Uses-Cases/Attachments/add/appendAttachments.py new file mode 100644 index 0000000..765f412 --- /dev/null +++ b/Uses-Cases/Attachments/add/appendAttachments.py @@ -0,0 +1,89 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, AttachmentInfo + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + NEW_ATTACHMENT_FILE = "sample_video.mp4" + NEW_ATTACHMENT_MIME = "video/mp4" + PAGE_NUMBER = 2 + +class PdfAttachments: + """Class for managing PDF attachments using Aspose PDF Cloud API.""" + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_file(self, fileName: str): + """ Upload a local fileName to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / fileName + try: + self.pdf_api.upload_file(fileName, str(file_path)) + logging.info(f"upload_file(): File '{fileName}' uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + self.upload_file(Config.PDF_DOCUMENT_NAME) + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def append_attachmnet(self): + """Append a new attachment to the PDF document.""" + if self.pdf_api: + new_attachment = AttachmentInfo( + path = Config.NEW_ATTACHMENT_FILE, + description = 'This is a sample attachment', + mime_type = Config.NEW_ATTACHMENT_MIME, + name = Config.NEW_ATTACHMENT_FILE + ) + + try: + response = self.pdf_api.post_add_document_attachment(Config.PDF_DOCUMENT_NAME, new_attachment) + if response.code == 200: + logging.info(f"append_attachment(): attachment '{Config.NEW_ATTACHMENT_FILE}' added to the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + logging.error(f"append_attachment(): Failed to add attachment to the document. Response code: {response.code}") + except Exception as e: + logging.error(f"append_attachment(): Error while adding attachment: {e}") + + +if __name__ == "__main__": + pdf_attachments = PdfAttachments() + pdf_attachments.upload_document() + pdf_attachments.upload_file(Config.NEW_ATTACHMENT_FILE) + pdf_attachments.append_attachmnet() + pdf_attachments.download_result() diff --git a/Uses-Cases/Attachments/get/getAttachmentAndSave.py b/Uses-Cases/Attachments/get/getAttachmentAndSave.py new file mode 100644 index 0000000..864d132 --- /dev/null +++ b/Uses-Cases/Attachments/get/getAttachmentAndSave.py @@ -0,0 +1,79 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, AttachmentsResponse, AttachmentResponse, Attachment + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample_file_with_attachment.pdf" + ATTACHMENT_PATH = "" + +class PdfAttachments: + """Class for managing PDF attachments using Aspose PDF Cloud API.""" + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def get_attachments(self): + """Get attachments for the PDF document.""" + if self.pdf_api: + try: + response : AttachmentsResponse = self.pdf_api.get_document_attachments(Config.PDF_DOCUMENT_NAME) + if response.code == 200: + logging.info(f"get_attachmnets(): attachments '{response.attachments}' for the document '{Config.PDF_DOCUMENT_NAME}'.") + Config.ATTACHMENT_PATH = response.attachments.list[0].links[0].href + else: + logging.error(f"get_attachmnets(): Failed to get attachments to the document. Response code: {response.code}") + except Exception as e: + logging.error(f"get_attachmnets(): Error while adding attachment: {e}") + + def get_attachment_by_id(self): + """Get attachment by Id for the PDF document and save it to local file.""" + if self.pdf_api: + try: + response : AttachmentResponse = self.pdf_api.get_document_attachment_by_index(Config.PDF_DOCUMENT_NAME, Config.ATTACHMENT_PATH) + if response.code == 200: + attachment: Attachment = response.attachment + temp_file = self.pdf_api.get_download_document_attachment_by_index(Config.PDF_DOCUMENT_NAME, Config.ATTACHMENT_PATH) + local_path = Config.LOCAL_FOLDER / attachment.name + shutil.copy(temp_file, local_path) + logging.info(f"get_attachment_by_id(): attachment '{local_path}' for the document '{Config.PDF_DOCUMENT_NAME}' successfuly saved.") + else: + logging.error(f"get_attachment_by_id(): Failed to get attachment for the document '{Config.PDF_DOCUMENT_NAME}'. Response code: {response.code}") + except Exception as e: + logging.error(f"get_attachment_by_id(): Error while get attachment: {e}") + + +if __name__ == "__main__": + pdf_attachments = PdfAttachments() + pdf_attachments.upload_document() + pdf_attachments.get_attachments() + pdf_attachments.get_attachment_by_id() \ No newline at end of file diff --git a/Uses-Cases/Bookmarks/add/appendBookmarks.py b/Uses-Cases/Bookmarks/add/appendBookmarks.py new file mode 100644 index 0000000..24fd0bc --- /dev/null +++ b/Uses-Cases/Bookmarks/add/appendBookmarks.py @@ -0,0 +1,93 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Color, Bookmark + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + NEW_BOOKMARK_TITLE = "• Increased performance.." #"• Productivity improvement" + PARENT_BOOKMARK_FOR_APPEND = "" #The parent bookmark path. Specify an empty string when adding a bookmark to the root. + NEW_BOOKMARK_PAGE_NUMBER = 3 + BOOKMARK_PAGE_POSITION_X = 89 + BOOKMARK_PAGE_POSITION_Y = 564 + + +class PdfBookmarks: + """Class for managing PDF bokkmarks using Aspose PDF Cloud API.""" + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def append_bookmark_link(self): + """Append a new bookmark link to a specific page in the PDF document.""" + if self.pdf_api: + newBookmark = Bookmark( + title = Config.NEW_BOOKMARK_TITLE, + italic = True, + bold = True, + color = Color(a=255,r=0,g=255,b=0), + level = 1, + page_display_left = Config.BOOKMARK_PAGE_POSITION_X, + page_display_top = Config.BOOKMARK_PAGE_POSITION_Y, + page_display_zoom = 2, + page_number = Config.NEW_BOOKMARK_PAGE_NUMBER + ) + + try: + response = self.pdf_api.post_bookmark( + Config.PDF_DOCUMENT_NAME, Config.PARENT_BOOKMARK_FOR_APPEND, [newBookmark] + ) + if response.code == 200: + logging.info(f"append_bookmark_link(): Bookmark '{response.bookmarks.list[0].action}'->'{Config.NEW_BOOKMARK_TITLE}' added to page #{Config.NEW_BOOKMARK_PAGE_NUMBER}.") + else: + logging.error(f"append_bookmark_link(): Failed to add bookmark '{Config.NEW_BOOKMARK_TITLE}' to the page #{Config.NEW_BOOKMARK_PAGE_NUMBER}. Response code: {response.code}") + except Exception as e: + logging.error(f"append_bookmark_link(): Error while adding bookmark: {e}") + + +if __name__ == "__main__": + pdf_bookmarks = PdfBookmarks() + pdf_bookmarks.upload_document() + pdf_bookmarks.append_bookmark_link() + pdf_bookmarks.download_result() diff --git a/Uses-Cases/Bookmarks/get/getBookmarkByPathAndShow.py b/Uses-Cases/Bookmarks/get/getBookmarkByPathAndShow.py new file mode 100644 index 0000000..fd4c6a6 --- /dev/null +++ b/Uses-Cases/Bookmarks/get/getBookmarkByPathAndShow.py @@ -0,0 +1,62 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, BookmarkResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + BOOKMARK_PATH = "/5" + +class PdfBookmarks: + """Class for managing PDF bookmarks using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def get_bookmark(self): + """Get bookmark for a specific PDF document using bookmark path.""" + if self.pdf_api: + try: + response : BookmarkResponse = self.pdf_api.get_bookmark( Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH) + if response.code == 200: + logging.info(f"Found bookmark => level: '{response.bookmark.level}' - action: '{response.bookmark.action}' - title: '{response.bookmark.title}'") + else: + logging.error(f"Failed to find bookmark for the document. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while find bookmark: {e}") + +if __name__ == "__main__": + pdf_bookmarks = PdfBookmarks() + pdf_bookmarks.upload_document() + pdf_bookmarks.get_bookmark() diff --git a/Uses-Cases/Bookmarks/get/getBookmarksAndShow.py b/Uses-Cases/Bookmarks/get/getBookmarksAndShow.py new file mode 100644 index 0000000..5d16514 --- /dev/null +++ b/Uses-Cases/Bookmarks/get/getBookmarksAndShow.py @@ -0,0 +1,67 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, BookmarksResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + +class PdfBookmarks: + """Class for managing PDF bookmarks using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def show_bookmarks_array(self, bookmarks, prefix): + for item in bookmarks.list: + logging.info(f"{prefix} => level: '{item.level}' - action: '{item.action}' - title: '{item.title}'") + if item.bookmarks and item.bookmarks.list and item.bookmarks.list.length > 0: + self.show_bookmarks_array(bookmarks=item.bookmarks, prefix=prefix) + + def get_all_bookmarks(self): + """Get all bookmarks for a specific PDF document.""" + if self.pdf_api: + try: + response : BookmarksResponse = self.pdf_api.get_document_bookmarks( Config.PDF_DOCUMENT_NAME) + if response.code == 200: + self.show_bookmarks_array(response.bookmarks, "All") + else: + logging.error(f"Failed to get bookmarks for the document. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while retrieving bookmarks array: {e}") + +if __name__ == "__main__": + pdf_bookmarks = PdfBookmarks() + pdf_bookmarks.upload_document() + pdf_bookmarks.get_all_bookmarks() diff --git a/Uses-Cases/Bookmarks/remove/removeBookmark.py b/Uses-Cases/Bookmarks/remove/removeBookmark.py new file mode 100644 index 0000000..f237d81 --- /dev/null +++ b/Uses-Cases/Bookmarks/remove/removeBookmark.py @@ -0,0 +1,73 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, AsposeResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + BOOKMARK_PATH = "/1" + + +class PdfBookmarks: + """Class for managing PDF bookmarks using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def remove_bookmark_by_path(self): + if self.pdf_api: + response: AsposeResponse = self.pdf_api.delete_bookmark(Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH) + + if response.code == 200: + logging.info(f"Bookmark with path: '{Config.BOOKMARK_PATH}' has been removed.") + else: + logging.erro(f"Failed to remove bookmark with path: '{Config.LINK_FIND_ID}") + +if __name__ == "__main__": + pdf_bookmarks = PdfBookmarks() + pdf_bookmarks.upload_document() + pdf_bookmarks.remove_bookmark_by_path() + pdf_bookmarks.download_result() diff --git a/Uses-Cases/Bookmarks/replace/replaceBookmark.py b/Uses-Cases/Bookmarks/replace/replaceBookmark.py new file mode 100644 index 0000000..3464d68 --- /dev/null +++ b/Uses-Cases/Bookmarks/replace/replaceBookmark.py @@ -0,0 +1,118 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Bookmark, BookmarksResponse, BookmarkResponse + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + NEW_BOOKMARK_TITLE = "• Increased performance." #"• Productivity improvement" + BOOKMARK_PATH = "/5" + NEW_BOOKMARK_PAGE_NUMBER = 3 + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class PdfBookmarks: + """Class for managing PDF bookmarkss using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def show_bookmarks_array(self, bookmarks, prefix): + for item in bookmarks.list: + logging.info(f"{prefix} => level: '{item.level}' - action: '{item.action}' - title: '{item.title}'") + if item.bookmarks and item.bookmarks.list and item.bookmarks.list.length > 0: + self.show_bookmarks_array(bookmarks=item.bookmarks, prefix=prefix) + + def get_all_bookmarks(self): + """Get all bookmarks for a specific PDF document.""" + if self.pdf_api: + try: + response : BookmarksResponse = self.pdf_api.get_document_bookmarks( Config.PDF_DOCUMENT_NAME) + if response.code == 200: + self.show_bookmarks_array(response.bookmarks, "All") + else: + logging.error(f"Failed to get bookmarks for the document. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while retrieving bookmarks array: {e}") + + def get_bookmark(self): + """Get bookmark for a specific PDF document using bookmark path.""" + if self.pdf_api: + try: + response : BookmarkResponse = self.pdf_api.get_bookmark( Config.PDF_DOCUMENT_NAME, Config.BOOKMARK_PATH) + if response.code == 200: + logging.info(f"Found bookmark => level: '{response.bookmark.level}' - action: '{response.bookmark.action}' - title: '{response.bookmark.title}'") + return response.bookmark + else: + logging.error(f"Failed to find bookmark for the document. Response code: {response.code}") + return None + except Exception as e: + logging.error(f"Error while find bookmark: {e}") + + def replace_bookmark(self): + if self.pdf_api: + _bookmark: BookmarkResponse = self.get_bookmark() + + if not _bookmark: + return + + _bookmark.title = Config.NEW_BOOKMARK_TITLE + + response: BookmarkResponse = self.pdf_api.put_bookmark( + Config.PDF_DOCUMENT_NAME, + Config.BOOKMARK_PATH, + bookmark=_bookmark, + ) + + if response.code == 200: + print("Bookmark replaced successfully.") + else: + print("Failed to replace Bookmark.") + + +if __name__ == "__main__": + pdf_bookmarks = PdfBookmarks() + pdf_bookmarks.upload_document() + pdf_bookmarks.get_all_bookmarks() + pdf_bookmarks.replace_bookmark() + pdf_bookmarks.download_result() diff --git a/Uses-Cases/Links/add/appendLink.py b/Uses-Cases/Links/add/appendLink.py new file mode 100644 index 0000000..f9c6251 --- /dev/null +++ b/Uses-Cases/Links/add/appendLink.py @@ -0,0 +1,89 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, LinkAnnotation, LinkActionType, LinkHighlightingMode, Color, Link, Rectangle + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + NEW_LINK_ACTION = "https://reference.aspose.cloud/pdf/" + PAGE_NUMBER = 2 + LINK_RECT = Rectangle(llx=244.914, lly=488.622, urx=284.776, ury=498.588) + + +class PdfLinks: + """Class for managing PDF links using Aspose PDF Cloud API.""" + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def append_link(self): + """Append a new hyperlink annotation to a specific page in the PDF document.""" + if self.pdf_api: + link_annotation = LinkAnnotation( + links=[Link(href=Config.NEW_LINK_ACTION)], + action_type= LinkActionType.GOTOURIACTION, + action=Config.NEW_LINK_ACTION, + highlighting=LinkHighlightingMode.INVERT, + color=Color(a=255, r=0, g=255, b=0), + rect=Config.LINK_RECT, + ) + + try: + response = self.pdf_api.post_page_link_annotations( + Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, [link_annotation] + ) + if response.code == 200: + logging.info(f"append_link(): Link '{Config.NEW_LINK_ACTION}' added to page #{Config.PAGE_NUMBER}.") + else: + logging.error(f"append_link(): Failed to add link to the page. Response code: {response.code}") + except Exception as e: + logging.error(f"append_link(): Error while adding link: {e}") + + +if __name__ == "__main__": + pdf_links = PdfLinks() + pdf_links.upload_document() + pdf_links.append_link() + pdf_links.download_result() diff --git a/Uses-Cases/Links/get/getLinksAndShow.py b/Uses-Cases/Links/get/getLinksAndShow.py new file mode 100644 index 0000000..f5994f8 --- /dev/null +++ b/Uses-Cases/Links/get/getLinksAndShow.py @@ -0,0 +1,80 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + LINK_FIND_ID = "GI5UO32UN5KVESKBMN2GS33OHMZTEMJMGUYDQLBTGYYCYNJSGE" + + +class PdfLinks: + """Class for managing PDF links using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def show_links_array(self, links, prefix): + for item in links: + logging.info(f"{prefix} Link ID: '{item.id}' - Link Action: '{item.action}'") + + def get_all_links(self): + """Get all hyperlink annotations for a specific PDF document.""" + if self.pdf_api: + try: + response = self.pdf_api.get_page_link_annotations( Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + if response.code == 200: + self.show_links_array(response.links.list, "All: ") + else: + logging.error(f"Failed to add link to the page. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while adding link: {e}") + + def get_link_by_id(self, link_id: str): + """Get hyperlink annotation using the specific Id in PDF document.""" + if self.pdf_api: + try: + result_link = self.pdf_api.get_link_annotation(Config.PDF_DOCUMENT_NAME, link_id) + if result_link.code == 200: + self.show_links_array([result_link.link], "Find: ") + except Exception as e: + logging.error(f"Error while adding link: {e}") + +if __name__ == "__main__": + pdf_links = PdfLinks() + pdf_links.upload_document() + pdf_links.get_all_links() + pdf_links.get_link_by_id(Config.LINK_FIND_ID) diff --git a/Uses-Cases/Links/remove/removeLink.py b/Uses-Cases/Links/remove/removeLink.py new file mode 100644 index 0000000..52f5a5a --- /dev/null +++ b/Uses-Cases/Links/remove/removeLink.py @@ -0,0 +1,91 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, AsposeResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + LINK_FIND_ID = "GI5UO32UN5KVESKBMN2GS33OHMZTEMJMGUYDQLBTGYYCYNJSGE" + + +class PdfLinks: + """Class for managing PDF links using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def show_links_array(self, links, prefix): + for item in links: + logging.info(f"{prefix} Link ID: '{item.id}' - Link Action: '{item.action}'") + + def get_all_links(self): + """Get all hyperlink annotations for a specific PDF document.""" + if self.pdf_api: + try: + response = self.pdf_api.get_page_link_annotations( Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + if response.code == 200: + self.show_links_array(response.links.list, "All: ") + else: + logging.error(f"Failed to add link to the page. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while adding link: No links found - {e}") + + def remove_link_by_id(self): + if self.pdf_api: + response: AsposeResponse = self.pdf_api.delete_link_annotation(Config.PDF_DOCUMENT_NAME, Config.LINK_FIND_ID) + + if response.code == 200: + logging.info("Link annotation with ID " + Config.LINK_FIND_ID + " has been removed.") + else: + logging.erro("Failed to remove link annotation with ID " + Config.LINK_FIND_ID) + +if __name__ == "__main__": + pdf_links = PdfLinks() + pdf_links.upload_document() + pdf_links.get_all_links() + pdf_links.remove_link_by_id() + pdf_links.download_result() diff --git a/Uses-Cases/Links/replace/replaceLink.py b/Uses-Cases/Links/replace/replaceLink.py new file mode 100644 index 0000000..209692c --- /dev/null +++ b/Uses-Cases/Links/replace/replaceLink.py @@ -0,0 +1,112 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, LinkAnnotationsResponse, LinkAnnotationResponse + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + NEW_LINK_ACTION = "https://reference.aspose.cloud/pdf/" + PAGE_NUMBER = 2 + LINK_FIND_ID = "GI5UO32UN5KVESKBMN2GS33OHMZTEMJMGUYDQLBTGYYCYNJSGE" + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class PdfLinks: + """Class for managing PDF links using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def download_result(self): + """Download the processed PDF document from the Aspose Cloud server.""" + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def show_links_array(self, links, prefix): + """Show all hyperlink annotations for a specific PDF document.""" + for item in links: + logging.info(f"{prefix} Link ID: '{item.id}' - Link Action: '{item.action}'") + + def get_all_links(self): + """Get all hyperlink annotations for a specific PDF document.""" + if self.pdf_api: + try: + response = self.pdf_api.get_page_link_annotations( Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + if response.code == 200: + self.show_links_array(response.links.list, "All: ") + else: + logging.error(f"Failed to add link to the page. Response code: {response.code}") + except Exception as e: + logging.error(f"Error while adding link: No links found - {e}") + + def get_link_by_id(self) -> LinkAnnotationResponse: + if self.pdf_api: + result_link: LinkAnnotationResponse = self.pdf_api.get_link_annotation(Config.PDF_DOCUMENT_NAME, Config.LINK_FIND_ID) + + if result_link.code == 200: + return result_link + + print("Link not found.") + return None + + def replace_link(self): + if self.pdf_api: + link_annotation: LinkAnnotationResponse = self.get_link_by_id() + + if not link_annotation: + return + + link_annotation.link.action = Config.NEW_LINK_ACTION + + response: LinkAnnotationsResponse = self.pdf_api.put_link_annotation( + Config.PDF_DOCUMENT_NAME, + Config.LINK_FIND_ID, + link_annotation.link, + ) + + if response.code == 200: + print("Link annotation replaced successfully.") + else: + print("Failed to replace link annotation.") + +if __name__ == "__main__": + pdf_links = PdfLinks() + pdf_links.upload_document() + pdf_links.get_all_links() + pdf_links.replace_link() + pdf_links.download_result() diff --git a/Uses-Cases/Pages/add/appendNewPage.py b/Uses-Cases/Pages/add/appendNewPage.py new file mode 100644 index 0000000..8bfcb7a --- /dev/null +++ b/Uses-Cases/Pages/add/appendNewPage.py @@ -0,0 +1,71 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, DocumentPagesResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def add_new_page(self): + """ Add new page to end of the PDF document. """ + if self.pdf_api: + result_pages: DocumentPagesResponse = self.pdf_api.put_add_new_page(Config.PDF_DOCUMENT_NAME) + + if result_pages.code == 200 and result_pages.pages: + logging.info(f"Added a new page: {result_pages.pages.list[-1]}") + else: + logging.error("Failed to add a new page.") + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.add_new_page() + pdf_pages.download_result() diff --git a/Uses-Cases/Pages/get/getPageInfoAndSavePng.py b/Uses-Cases/Pages/get/getPageInfoAndSavePng.py new file mode 100644 index 0000000..b8cf4bf --- /dev/null +++ b/Uses-Cases/Pages/get/getPageInfoAndSavePng.py @@ -0,0 +1,72 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, DocumentPagesResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.png" + PAGE_NUMBER = 2 + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def get_page_info(self): + """ Get page information of the PDF document. """ + if self.pdf_api: + result_pages: DocumentPagesResponse = self.pdf_api.get_page(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + + if result_pages.code == 200: + logging.info(f"Page #{Config.PAGE_NUMBER} information: {result_pages.page}") + else: + logging.error(f"Failed to get the page #{Config.PAGE_NUMBER}.") + + def get_page_as_png(self): + """ Get page information of the PDF document. """ + if self.pdf_api: + try: + result_pages = self.pdf_api.get_page_convert_to_png(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(result_pages, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.get_page_info() + pdf_pages.get_page_as_png() diff --git a/Uses-Cases/Pages/move/movePageNewPosition.py b/Uses-Cases/Pages/move/movePageNewPosition.py new file mode 100644 index 0000000..ef32686 --- /dev/null +++ b/Uses-Cases/Pages/move/movePageNewPosition.py @@ -0,0 +1,71 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, AsposeResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def move_page(self): + """ Moves a page to a new location in the PDF document. """ + if self.pdf_api: + response: AsposeResponse = self.pdf_api.post_move_page(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, Config.PAGE_NUMBER + 1) + + if response.code == 200: + logging.info(f"Page #{Config.PAGE_NUMBER} has been moved to position #{Config.PAGE_NUMBER + 1}.") + else: + logging.error("Failed to move a new page.") + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.move_page() + pdf_pages.download_result() diff --git a/Uses-Cases/Pages/remove/removePage.py b/Uses-Cases/Pages/remove/removePage.py new file mode 100644 index 0000000..fa09657 --- /dev/null +++ b/Uses-Cases/Pages/remove/removePage.py @@ -0,0 +1,70 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def delete_page(self): + """ Deletes a specific page from a PDF document. """ + if self.pdf_api: + result = self.pdf_api.delete_page(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + if result.code == 200: + logging.info(f"Page #{Config.PAGE_NUMBER} deleted.") + else: + logging.error(f"Failed to delete page #{Config.PAGE_NUMBER}.") + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.delete_page() + pdf_pages.download_result() diff --git a/Uses-Cases/Pages/stamp/pageAppendTextStamp.py b/Uses-Cases/Pages/stamp/pageAppendTextStamp.py new file mode 100644 index 0000000..ec99ba3 --- /dev/null +++ b/Uses-Cases/Pages/stamp/pageAppendTextStamp.py @@ -0,0 +1,81 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Stamp, AsposeResponse, HorizontalAlignment, StampType + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + STAMP_TEXT = "NEW TEXT STAMP" + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def add_page_text_stamp(self): + """ Adds a text stamp to a specific page in a PDF document. """ + if self.pdf_api: + page_stamp: Stamp = Stamp( + type = StampType.TEXT, + background = True, + horizontal_alignment = HorizontalAlignment.CENTER, + text_alignment = HorizontalAlignment.CENTER, + value = Config.STAMP_TEXT, + page_index = Config.PAGE_NUMBER, + ) + + response: AsposeResponse = self.pdf_api.put_page_add_stamp(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, page_stamp) + + if response.code == 200: + logging.info(f"Text stamp '{Config.STAMP_TEXT}' added to page #{Config.PAGE_NUMBER}.") + else: + logging.error(f"Failed to add text stamp '{Config.STAMP_TEXT}' to page #{Config.PAGE_NUMBER}.") + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.add_page_text_stamp() + pdf_pages.download_result() diff --git a/Uses-Cases/Pages/wordsCount/wordsCountOnPages.py b/Uses-Cases/Pages/wordsCount/wordsCountOnPages.py new file mode 100644 index 0000000..634d7d2 --- /dev/null +++ b/Uses-Cases/Pages/wordsCount/wordsCountOnPages.py @@ -0,0 +1,59 @@ + import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, WordCountResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + +class PdfPages: + """ Class for managing PDF pages using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def get_document_words_count_on_pages(self): + """ Retrieves the word count for each page in a PDF document. """ + if self.pdf_api: + response: WordCountResponse = self.pdf_api.get_words_per_page(Config.PDF_DOCUMENT_NAME) + + if response.code == 200: + logging.info(response.words_per_page.list) + else: + logging.error("Failed to retrieve word count.") + return + +if __name__ == "__main__": + pdf_pages = PdfPages() + pdf_pages.upload_document() + pdf_pages.get_document_words_count_on_pages() diff --git a/Uses-Cases/Stamps/add/appendStamps.py b/Uses-Cases/Stamps/add/appendStamps.py new file mode 100644 index 0000000..a31846f --- /dev/null +++ b/Uses-Cases/Stamps/add/appendStamps.py @@ -0,0 +1,107 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Stamp, AsposeResponse, HorizontalAlignment, StampType + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + IMAGE_STAMP_FILE ="sample.png" + PAGE_NUMBER = 2 + STAMP_TEXT = "NEW TEXT STAMP" + IMAGE_STAMP_LLY = 800 + IMAGE_STAMP_WIDTH = 24 + IMAGE_STAMP_HEIGHT = 24 + +class PdfStamps: + """ Class for managing PDF stamps using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_file(self, fileName: str): + """ Upload a local fileName to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / fileName + try: + self.pdf_api.upload_file(fileName, str(file_path)) + logging.info(f"upload_file(): File '{fileName}' uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + self.upload_file(Config.PDF_DOCUMENT_NAME) + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + file_path = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(file_path, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def add_document_stamps(self): + """ Adds a text stamp to a specific page in a PDF document. """ + if self.pdf_api: + text_stamp: Stamp = Stamp( + type = StampType.TEXT, + background = True, + horizontal_alignment = HorizontalAlignment.CENTER, + text_alignment = HorizontalAlignment.CENTER, + value=Config.STAMP_TEXT + ) + + image_stamp: Stamp = Stamp( + type = StampType.IMAGE, + background = True, + horizontal_alignment = HorizontalAlignment.CENTER, + text_alignment = HorizontalAlignment.CENTER, + value = "NEW IMAGE STAMP", + file_name = Config.IMAGE_STAMP_FILE, + y_indent = Config.IMAGE_STAMP_LLY, + width = Config.IMAGE_STAMP_WIDTH, + height = Config.IMAGE_STAMP_HEIGHT + ) + try: + responseTextStamp: AsposeResponse = self.pdf_api.post_document_text_stamps(Config.PDF_DOCUMENT_NAME, [ text_stamp ]) + responseImageStamp: AsposeResponse = self.pdf_api.post_document_image_stamps(Config.PDF_DOCUMENT_NAME, [ image_stamp ]) + + if responseTextStamp.code == 200 and responseImageStamp.code == 200: + logging.info(f"add_document_stamps(): Text stamp '{Config.STAMP_TEXT}' and image stamp '{Config.IMAGE_STAMP_FILE}' added to the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + if responseTextStamp.code != 200: + logging.error(f"add_document_stamps(): Failed to add text stamp '{Config.STAMP_TEXT}' to the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + logging.error(f"add_document_stamps(): Failed to add image stamp '{Config.IMAGE_STAMP_FILE}' to the document '{Config.PDF_DOCUMENT_NAME}'.") + except Exception as e: + logging.error(f"add_document_stamps(): Failed to download file: {e}") + +if __name__ == "__main__": + pdf_stamps = PdfStamps() + pdf_stamps.upload_document() + pdf_stamps.upload_file(Config.IMAGE_STAMP_FILE) + pdf_stamps.add_document_stamps() + pdf_stamps.download_result() diff --git a/Uses-Cases/Stamps/remove/removeStamps.py b/Uses-Cases/Stamps/remove/removeStamps.py new file mode 100644 index 0000000..4807828 --- /dev/null +++ b/Uses-Cases/Stamps/remove/removeStamps.py @@ -0,0 +1,87 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Stamp, AsposeResponse + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "pdf_stamps.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + IMAGE_STAMP_FILE ="sample.png" + PAGE_NUMBER = 2 + STAMP_ID = "GE5TCOZQ" + +class PdfStamps: + """ Class for managing PDF stamps using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + file_path = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(file_path, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def delete_page_stamps(self): + """ Remove stamp in a specific page of the PDF document. """ + if self.pdf_api: + response: AsposeResponse = self.pdf_api.delete_page_stamps(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + + if response.code == 200 : + logging.info(f"Stamps on page #{Config.PAGE_NUMBER} was deleted for the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + logging.error(f"Failed to remove stamps on page #{Config.PAGE_NUMBER} for the document '{Config.PDF_DOCUMENT_NAME}'.") + + def delete_stamp_by_id(self): + """ Remove stamp by Id in the PDF document. """ + if self.pdf_api: + try: + response: AsposeResponse = self.pdf_api.delete_stamp(Config.PDF_DOCUMENT_NAME, Config.STAMP_ID) + + if response.code == 200 : + logging.info(f"Stamps with Id '{Config.STAMP_ID}' was deleted for the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + logging.error(f"Failed to remove stamp with Id '{Config.STAMP_ID}' for the document '{Config.PDF_DOCUMENT_NAME}'.") + except Exception as e: + logging.error(f"delete_stamp_by_id(): Failed to download file: {e}") + +if __name__ == "__main__": + pdf_stamps = PdfStamps() + pdf_stamps.upload_document() + pdf_stamps.delete_stamp_by_id() + pdf_stamps.delete_page_stamps() + pdf_stamps.download_result() diff --git a/Uses-Cases/Tables/add/appendTable.py b/Uses-Cases/Tables/add/appendTable.py new file mode 100644 index 0000000..bdb3462 --- /dev/null +++ b/Uses-Cases/Tables/add/appendTable.py @@ -0,0 +1,142 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Table, Row, Cell, FontStyles, GraphInfo, TextRect, TextState, Color, BorderInfo +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + +class PdfTables: + """ Class for managing PDF tables using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def _init_table (self): + """ Initialize new table """ + num_of_cols = 5 + num_of_rows = 5 + + header_text_state = TextState( + font = "Arial Bold", + font_size = 11, + foreground_color = Color( a = 255, r = 255, g = 255, b = 255 ), + font_style = FontStyles.BOLD, + ) + + common_text_state = TextState ( + font = "Arial Bold", + font_size = 11, + foreground_color = Color( a=255, r = 112, g = 112, b = 112 ), + font_style=FontStyles.REGULAR + ) + + col_widths = "" + for col_index in range(0,num_of_cols): + col_widths += " 70" + + table_rows = []; + + border_table_border = GraphInfo( + color = Color(a = 255, r = 0, g = 255, b = 0 ), + line_width = 0.5 + ) + + for row_index in range(0, num_of_rows): + row_cells = [] + + for col_index in range(0, num_of_cols): + cell = Cell( default_cell_text_state = common_text_state) + + if row_index == 0: # header cells + cell.background_color = Color(a = 255, r = 128, g = 128, b=128) + cell.default_cell_text_state = header_text_state + else: + cell.background_color = Color(a =255, r =255, g =255, b =255) + + text_rect = TextRect() + if row_index == 0: + text_rect.text = f"header #{col_index}" + else: + text_rect.text = f"value '({row_index},{col_index})'" + cell.paragraphs = [ text_rect] + + row_cells.append(cell) + + row = Row(cells=row_cells) + + table_rows.append(row) + + table = Table(left=150,top=250, column_widths=col_widths, rows=table_rows) + + table.default_cell_border = BorderInfo( + top = border_table_border, + right = border_table_border, + bottom = border_table_border, + left = border_table_border, + rounded_border_radius = 2 + ) + + return table + + def add_table_on_page (self): + """ Append table to the PDF document page. """ + if self.pdf_api: + try: + new_table = self._init_table() + + resultTabs = self.pdf_api.post_page_tables( Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER, [ new_table ]) + + if resultTabs.code == 200: + logging.info(f"add_table_on_page(): Table was appended to the document '{Config.PDF_DOCUMENT_NAME}' on page #'{Config.PAGE_NUMBER}'.") + else: + logging.error(f"add_table_on_page(): Failed to add new table to the document '{Config.PDF_DOCUMENT_NAME}'.") + except Exception as e: + logging.error(f"add_table_on_page(): Failed to append table: {e}") + +if __name__ == "__main__": + pdf_tables = PdfTables() + pdf_tables.upload_document() + pdf_tables.add_table_on_page() + pdf_tables.download_result() diff --git a/Uses-Cases/Tables/get/getTablesAndShow.py b/Uses-Cases/Tables/get/getTablesAndShow.py new file mode 100644 index 0000000..c559a2b --- /dev/null +++ b/Uses-Cases/Tables/get/getTablesAndShow.py @@ -0,0 +1,79 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Table, Row, Cell, FontStyles, GraphInfo, TextRect, TextState, Color, BorderInfo +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + TABLE_ID = "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA" + +class PdfTables: + """ Class for managing PDF tables using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def _show_tables_info(self, tables, prefix): + if tables and len(tables) > 0 : + for table in tables: + logging.info(f"{prefix} => id: '{table.id}', page: '{table.page_num}', rows: '{len(table.row_list)}', columns: '{len(table.row_list[0].cell_list)}'") + else: + logging.error(f"showBoormarks() error: array of tables is empty!") + + def get_all_tables(self): + if self.pdf_api: + resultTabs = self.pdf_api.get_document_tables(Config.PDF_DOCUMENT_NAME) + + if resultTabs.code == 200 and resultTabs.tables: + if not resultTabs.tables.list or len(resultTabs.tables.list) == 0: + logging.error("get_all_tables(): Unexpected error - tables is null or empty!!!") + self._show_tables_info(resultTabs.tables.list, "All tables") + return resultTabs.tables.list + else: + logging.error("get_all_tables(): Unexpected error - can't get links!!!") + + def get_table_by_id (self): + if self.pdf_api: + resultTabs =self.pdf_api.get_table(Config.PDF_DOCUMENT_NAME, Config.TABLE_ID) + + if resultTabs.code == 200 and resultTabs.table: + self._show_tables_info( [ resultTabs.table ], "Table by Id") + return resultTabs.table + else: + logging.error("get_table_by_id(): Unexpected error - can't get links!!!") + +if __name__ == "__main__": + pdf_tables = PdfTables() + pdf_tables.upload_document() + pdf_tables.get_all_tables() + pdf_tables.get_table_by_id() diff --git a/Uses-Cases/Tables/remove/removeTables.py b/Uses-Cases/Tables/remove/removeTables.py new file mode 100644 index 0000000..1736b8f --- /dev/null +++ b/Uses-Cases/Tables/remove/removeTables.py @@ -0,0 +1,104 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Table, Row, Cell, FontStyles, GraphInfo, TextRect, TextState, Color, BorderInfo +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 1 + TABLE_ID = "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA" + +class PdfTables: + """ Class for managing PDF tables using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + + def _show_tables_info(self, tables, prefix): + if tables and len(tables) > 0 : + for table in tables: + logging.info(f"{prefix} => id: '{table.id}', page: '{table.page_num}', rows: '{len(table.row_list)}', columns: '{len(table.row_list[0].cell_list)}'") + else: + logging.error(f"_show_tables_info() error: array of tables is empty!") + + def get_all_tables(self, prefix): + if self.pdf_api: + resultTabs = self.pdf_api.get_document_tables(Config.PDF_DOCUMENT_NAME) + + if resultTabs.code == 200 and resultTabs.tables: + if not resultTabs.tables.list or len(resultTabs.tables.list) == 0: + logging.error("get_all_tables(): Unexpected error - tables is null or empty!!!") + self._show_tables_info(resultTabs.tables.list, prefix) + else: + logging.error("get_all_tables(): Unexpected error - can't get links!!!") + + def delete_table(self): + if self.pdf_api: + resultTabs = self.pdf_api.delete_table(Config.PDF_DOCUMENT_NAME, Config.TABLE_ID) + if resultTabs.code == 200: + logging.info(f"delete_table(): Table #{Config.TABLE_ID} deleted!") + else: + logging.error("delete_table(): Unexpected error - can't delete table!") + + def delete_tables(self): + if self.pdf_api: + resultTabs = self.pdf_api.delete_page_tables(Config.PDF_DOCUMENT_NAME, Config.PAGE_NUMBER) + + if resultTabs.code == 200: + logging.info(f"delete_tables(): Tables on page #{Config.PAGE_NUMBER} deleted!") + else: + logging.error("delete_tables(): Unexpected error - can't get tables!!!") + +if __name__ == "__main__": + pdf_tables = PdfTables() + pdf_tables.upload_document() + + pdf_tables.get_all_tables("All tables") + pdf_tables.delete_table() + pdf_tables.get_all_tables("Tables after drop one") + + pdf_tables.delete_tables() + pdf_tables.get_all_tables("Tables after drop all") + + pdf_tables.download_result() diff --git a/Uses-Cases/Tables/replace/replaceTable.py b/Uses-Cases/Tables/replace/replaceTable.py new file mode 100644 index 0000000..eb5ecdf --- /dev/null +++ b/Uses-Cases/Tables/replace/replaceTable.py @@ -0,0 +1,143 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, Table, Row, Cell, FontStyles, GraphInfo, TextRect, TextState, Color, BorderInfo +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + TABLE_ID = "GE5TCOZSGAYCYNRQGUWDINZVFQ3DGMA" + +class PdfTables: + """ Class for managing PDF tables using Aspose PDF Cloud API. """ + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """ Initialize the API client. """ + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("init_api(): Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"init_api(): Failed to load credentials: {e}") + + def upload_document(self): + """ Upload a PDF document to the Aspose Cloud server. """ + if self.pdf_api: + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"upload_document(): File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"upload_document(): Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server. """ + if self.pdf_api: + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def _init_table (self): + """ Initialize new table """ + num_of_cols = 5 + num_of_rows = 5 + + header_text_state = TextState( + font = "Arial Bold", + font_size = 11, + foreground_color = Color( a = 255, r = 255, g = 255, b = 255 ), + font_style = FontStyles.BOLD, + ) + + common_text_state = TextState ( + font = "Arial Bold", + font_size = 11, + foreground_color = Color( a=255, r = 112, g = 112, b = 112 ), + font_style=FontStyles.REGULAR + ) + + col_widths = "" + for col_index in range(0,num_of_cols): + col_widths += " 70" + + table_rows = [] + + border_table_border = GraphInfo( + color = Color(a = 255, r = 0, g = 255, b = 0 ), + line_width = 0.5 + ) + + for row_index in range(0, num_of_rows): + row_cells = [] + + for col_index in range(0, num_of_cols): + cell = Cell( default_cell_text_state = common_text_state) + + if row_index == 0: # header cells + cell.background_color = Color(a = 255, r = 128, g = 128, b=128) + cell.default_cell_text_state = header_text_state + else: + cell.background_color = Color(a =255, r =255, g =255, b =255) + + text_rect = TextRect() + if row_index == 0: + text_rect.text = f"header #{col_index}" + else: + text_rect.text = f"value '({row_index},{col_index})'" + cell.paragraphs = [ text_rect] + + row_cells.append(cell) + + row = Row(cells=row_cells) + + table_rows.append(row) + + table = Table(left=150,top=250, column_widths=col_widths, rows=table_rows) + + table.default_cell_border = BorderInfo( + top = border_table_border, + right = border_table_border, + bottom = border_table_border, + left = border_table_border, + rounded_border_radius = 2 + ) + + return table + + def replace_table (self): + """ Replace table in the PDF document page. """ + if self.pdf_api: + try: + new_table = self._init_table() + + resultTabs = self.pdf_api.put_table( Config.PDF_DOCUMENT_NAME, Config.TABLE_ID, new_table) + + if resultTabs.code == 200: + logging.info(f"replace_table(): Table #'{Config.TABLE_ID}' was replaced in the document '{Config.PDF_DOCUMENT_NAME}'.") + else: + logging.error(f"replace_table(): Failed to replace table in the document '{Config.PDF_DOCUMENT_NAME}'.") + except Exception as e: + logging.error(f"replace_table(): Failed to append table: {e}") + + +if __name__ == "__main__": + pdf_tables = PdfTables() + pdf_tables.upload_document() + pdf_tables.replace_table() + pdf_tables.download_result() diff --git a/Uses-Cases/Texts/replace/replaceTexts.py b/Uses-Cases/Texts/replace/replaceTexts.py new file mode 100644 index 0000000..df0c465 --- /dev/null +++ b/Uses-Cases/Texts/replace/replaceTexts.py @@ -0,0 +1,116 @@ +import shutil +import json +import logging +from pathlib import Path +from asposepdfcloud import ApiClient, PdfApi, TextReplace, TextReplaceListRequest + +class Config: + """Configuration parameters.""" + CREDENTIALS_FILE = Path(r"C:\\Projects\\ASPOSE\\Pdf.Cloud\\Credentials\\credentials.json") + LOCAL_FOLDER = Path(r"C:\\Samples") + PDF_DOCUMENT_NAME = "sample.pdf" + LOCAL_RESULT_DOCUMENT_NAME = "output_sample.pdf" + PAGE_NUMBER = 2 + TEXT_SOURCE_FOR_REPLACE = "YOUR source text" + TEXT_NEW_VALUE = "YOUR new text" + +# Configure logging +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") + +class PdfTexts: + """Class for managing PDF texts using Aspose PDF Cloud API.""" + + def __init__(self, credentials_file: Path = Config.CREDENTIALS_FILE): + self.pdf_api = None + self._init_api(credentials_file) + + def _init_api(self, credentials_file: Path): + """Initialize the API client.""" + try: + with credentials_file.open("r", encoding="utf-8") as file: + credentials = json.load(file) + api_key, app_id = credentials.get("key"), credentials.get("id") + if not api_key or not app_id: + raise ValueError("Error: Missing API keys in the credentials file.") + self.pdf_api = PdfApi(ApiClient(api_key, app_id)) + except (FileNotFoundError, json.JSONDecodeError, ValueError) as e: + logging.error(f"Failed to load credentials: {e}") + + def _ensure_api_initialized(self): + """Check if the API is initialized before making API calls.""" + if not self.pdf_api: + logging.error("PDF API is not initialized. Operation aborted.") + return False + return True + + def upload_document(self): + """Upload a PDF document to the Aspose Cloud server.""" + if not self._ensure_api_initialized(): + return + + file_path = Config.LOCAL_FOLDER / Config.PDF_DOCUMENT_NAME + try: + self.pdf_api.upload_file(Config.PDF_DOCUMENT_NAME, str(file_path)) + logging.info(f"File {Config.PDF_DOCUMENT_NAME} uploaded successfully.") + except Exception as e: + logging.error(f"Failed to upload file: {e}") + + def download_result(self): + """ Download the processed PDF document from the Aspose Cloud server """ + if not self._ensure_api_initialized(): + return + + try: + temp_file = self.pdf_api.download_file(Config.PDF_DOCUMENT_NAME) + local_path = Config.LOCAL_FOLDER / Config.LOCAL_RESULT_DOCUMENT_NAME + shutil.move(temp_file, str(local_path)) + logging.info(f"download_result(): File successfully downloaded: {local_path}") + except Exception as e: + logging.error(f"download_result(): Failed to download file: {e}") + + def replace_document_texts(self): + """ Replace text in the PDF document """ + if not self.pdf_api: + return + + text_replace_obj = TextReplace(old_value=Config.TEXT_SOURCE_FOR_REPLACE, new_value=Config.TEXT_NEW_VALUE, regex=False) + + text_replace_request = TextReplaceListRequest([text_replace_obj]) + + response = self.pdf_api.post_document_text_replace( + Config.PDF_DOCUMENT_NAME, text_replace_request + ) + + if response.code == 200: + print(f"Text '{Config.TEXT_SOURCE_FOR_REPLACE}' replaced with '{Config.TEXT_NEW_VALUE}' - successfully.") + else: + print("Failed to replace text in document.") + + def replace_page_texts(self): + """ Replace text on the page in PDF document """ + if not self.pdf_api: + return + + text_replace_obj = TextReplace(old_value=Config.TEXT_NEW_VALUE, new_value=Config.TEXT_SOURCE_FOR_REPLACE, regex=False) + + text_replace_request = TextReplaceListRequest([text_replace_obj]) + + response = self.pdf_api.post_page_text_replace( + Config.PDF_DOCUMENT_NAME, + Config.PAGE_NUMBER, + text_replace_request + ) + + if response.code == 200: + print(f"Text '{Config.TEXT_NEW_VALUE}' replaced with '{Config.TEXT_SOURCE_FOR_REPLACE}' - successfully.") + else: + print("Failed to replace text in document.") + + + +if __name__ == "__main__": + pdf_texts = PdfTexts() + pdf_texts.upload_document() + pdf_texts.replace_document_texts() + pdf_texts.replace_page_texts() + pdf_texts.download_result() diff --git a/asposepdfcloud/api_client.py b/asposepdfcloud/api_client.py index 20a0a8c..2d20495 100644 --- a/asposepdfcloud/api_client.py +++ b/asposepdfcloud/api_client.py @@ -83,7 +83,7 @@ def __init__(self, app_key, app_sid, host=None, self_host=False): self.rest_client = RESTClientObject() self.default_headers = {} self.default_headers['x-aspose-client'] = 'python sdk' - self.default_headers['x-aspose-client-version'] = '25.1.0' + self.default_headers['x-aspose-client-version'] = '25.2.0' self.self_host = self_host self.app_key = app_key diff --git a/asposepdfcloud/configuration.py b/asposepdfcloud/configuration.py index f127234..376bee9 100644 --- a/asposepdfcloud/configuration.py +++ b/asposepdfcloud/configuration.py @@ -199,5 +199,5 @@ def to_debug_report(self): "OS: {env}\n"\ "Python Version: {pyversion}\n"\ "Version of the API: 3.0\n"\ - "SDK Package Version: 25.1.0".\ + "SDK Package Version: 25.2.0".\ format(env=sys.platform, pyversion=sys.version) diff --git a/setup.py b/setup.py index e5becaa..7df9e40 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ from setuptools import setup, find_packages NAME = "asposepdfcloud" -VERSION = "25.1.0" +VERSION = "25.2.0" # To install the library, run the following # # python setup.py install