Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
a3a5739
PDFAPPS-6709: added use cases for Links
Dmitriy-Xawstov Jan 27, 2025
08ecebd
PDFAPPS-6710: added use cases for Pages
Dmitriy-Xawstov Jan 27, 2025
86e0603
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
7d025a1
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
bf5c6b1
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
74e34ed
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
2a026db
Delete Uses-Cases/Links/get_common.py
Dmitriy-Xawstov Feb 13, 2025
282d877
Delete Uses-Cases/Links/replace/replace.py
Dmitriy-Xawstov Feb 13, 2025
01c8e31
Delete Uses-Cases/Links/remove/remove.py
Dmitriy-Xawstov Feb 13, 2025
810c0ac
Delete Uses-Cases/Links/get/get.py
Dmitriy-Xawstov Feb 13, 2025
969ca2f
Delete Uses-Cases/Links/add/add.py
Dmitriy-Xawstov Feb 13, 2025
92df415
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
f6637d3
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
666cd0d
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
ca69439
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
fb1136d
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
8bfb23a
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
afa127e
Delete Uses-Cases/Pages/get_common.py
Dmitriy-Xawstov Feb 13, 2025
3f6132a
Delete Uses-Cases/Pages/wordsCount/words_count.py
Dmitriy-Xawstov Feb 13, 2025
6127538
Delete Uses-Cases/Pages/stamp/page_stamp.py
Dmitriy-Xawstov Feb 13, 2025
86d6565
Delete Uses-Cases/Pages/remove/remove.py
Dmitriy-Xawstov Feb 13, 2025
51a7f15
Delete Uses-Cases/Pages/move/move_page.py
Dmitriy-Xawstov Feb 13, 2025
ca7452e
Delete Uses-Cases/Pages/get/get.py
Dmitriy-Xawstov Feb 13, 2025
816d5c8
Delete Uses-Cases/Pages/add/add.py
Dmitriy-Xawstov Feb 13, 2025
fbf4603
Update pageAppendTextStamp.py
Dmitriy-Xawstov Feb 13, 2025
a427868
PDFAPPS-6714: added use cases for Stamps
Dmitriy-Xawstov Feb 13, 2025
27ec91a
Add files via upload
Dmitriy-Xawstov Feb 13, 2025
bbf5463
Delete Stamps/add/appendStamps.py
Dmitriy-Xawstov Feb 13, 2025
0cad31c
Delete Stamps/remove/removeStamps.py
Dmitriy-Xawstov Feb 13, 2025
3e2eef3
PDFAPPS-6711: added use cases for Attachments
Dmitriy-Xawstov Feb 13, 2025
fded853
Update appendStamps.py
Dmitriy-Xawstov Feb 17, 2025
b15ff10
Update pageAppendTextStamp.py
Dmitriy-Xawstov Feb 17, 2025
89387dd
Update getAttachmentAndSave.py
Dmitriy-Xawstov Feb 19, 2025
ab2a21b
PDFAPPS-6716: added use cases for Bookmarks
Dmitriy-Xawstov Feb 20, 2025
97308dd
Merge pull request #84 from aspose-pdf-cloud/pdfapps-6711-added-use-c…
kaferi Feb 20, 2025
1f084b8
Update appendBookmarks.py
Dmitriy-Xawstov Feb 20, 2025
013fd11
Update appendBookmarks.py
Dmitriy-Xawstov Feb 20, 2025
7e18599
Update removeBookmark.py
Dmitriy-Xawstov Feb 20, 2025
e7e89f5
Update replaceLink.py
Dmitriy-Xawstov Feb 20, 2025
4fd0bf3
Update appendStamps.py
Dmitriy-Xawstov Feb 20, 2025
dc69444
Update removeStamps.py
Dmitriy-Xawstov Feb 20, 2025
05d70f7
Update appendNewPage.py
Dmitriy-Xawstov Feb 20, 2025
bf6c0dc
Update movePageNewPosition.py
Dmitriy-Xawstov Feb 20, 2025
6a85382
Update removePage.py
Dmitriy-Xawstov Feb 20, 2025
ec663b1
Update getPageInfoAndSavePng.py
Dmitriy-Xawstov Feb 20, 2025
96bb199
Update pageAppendTextStamp.py
Dmitriy-Xawstov Feb 20, 2025
070d8f5
Update appendLink.py
Dmitriy-Xawstov Feb 20, 2025
56af233
Update removeLink.py
Dmitriy-Xawstov Feb 20, 2025
a48c38d
Update replaceLink.py
Dmitriy-Xawstov Feb 20, 2025
5027002
PDFAPPS-6885: added use cases for replace texts
Dmitriy-Xawstov Feb 21, 2025
da44c3a
Update replaceTexts.py
Dmitriy-Xawstov Feb 21, 2025
19f8657
Merge pull request #87 from aspose-pdf-cloud/pdfapps-6885-added-use-c…
kaferi Feb 21, 2025
6f16ca2
Merge pull request #83 from aspose-pdf-cloud/pdfapps-6714-added-use-c…
kaferi Feb 24, 2025
4df414e
Update appendLink.py
Dmitriy-Xawstov Feb 24, 2025
c00fbb6
PDFAPPS-6715: added use cases for Tables
Dmitriy-Xawstov Feb 27, 2025
9cf821c
Update appendTable.py
Dmitriy-Xawstov Feb 27, 2025
8a55b95
Delete Uses-Cases/Tables/get_common.js
Dmitriy-Xawstov Feb 27, 2025
d20fbe6
Update appendTable.py
Dmitriy-Xawstov Feb 27, 2025
69ff9a1
Update appendTable.py
Dmitriy-Xawstov Feb 27, 2025
d153f4c
Update getTablesAndShow.py
Dmitriy-Xawstov Feb 27, 2025
bed218e
Update removeTables.py
Dmitriy-Xawstov Feb 27, 2025
544fa14
Update replaceTable.py
Dmitriy-Xawstov Feb 27, 2025
3f53504
Update replaceTable.py
Dmitriy-Xawstov Feb 27, 2025
76feb7d
Update removeTables.py
Dmitriy-Xawstov Feb 27, 2025
326ab91
Update getTablesAndShow.py
Dmitriy-Xawstov Feb 27, 2025
03b5e68
Update appendTable.py
Dmitriy-Xawstov Feb 27, 2025
883f005
Update appendStamps.py
Dmitriy-Xawstov Feb 27, 2025
888d561
Update removeStamps.py
Dmitriy-Xawstov Feb 27, 2025
5685245
Merge pull request #89 from aspose-pdf-cloud/Dmitriy-Xawstov-patch-1
kaferi Feb 27, 2025
94a71a3
Merge pull request #90 from aspose-pdf-cloud/Dmitriy-Xawstov-patch-2
kaferi Feb 27, 2025
d013485
Update replaceTable.py
Dmitriy-Xawstov Feb 27, 2025
7f25172
Update removeTables.py
Dmitriy-Xawstov Feb 27, 2025
72cde37
Update removeTables.py
Dmitriy-Xawstov Feb 27, 2025
c5b4e90
Update appendTable.py
Dmitriy-Xawstov Feb 27, 2025
325baec
Merge pull request #88 from aspose-pdf-cloud/pdfapps-6715-added-use-c…
kaferi Feb 28, 2025
6cdb434
Update Attachments uses cases
Dmitriy-Xawstov Feb 28, 2025
df0f7d3
update-attachmants-get-uses-cases
Dmitriy-Xawstov Feb 28, 2025
4ea1703
Delete getAttachmentAndSave.py
Dmitriy-Xawstov Feb 28, 2025
ebb42f5
update-attachments-get-uses-cases
Dmitriy-Xawstov Feb 28, 2025
85da872
Merge pull request #91 from aspose-pdf-cloud/Dmitriy-Xawstov-patch-At…
kaferi Feb 28, 2025
7e9f1fa
Update appendBookmarks.py
Dmitriy-Xawstov Mar 3, 2025
d7f357d
Update getBookmarkByPathAndShow.py
Dmitriy-Xawstov Mar 3, 2025
0ed660f
Update getBookmarksAndShow.py
Dmitriy-Xawstov Mar 3, 2025
6e6eee3
Update removeBookmark.py
Dmitriy-Xawstov Mar 3, 2025
e591b2d
Delete Uses-Cases/Bookmarks/replace/replaceLink.py
Dmitriy-Xawstov Mar 3, 2025
43f5619
Add files via upload
Dmitriy-Xawstov Mar 3, 2025
2e775cf
Update replaceBookmark.py
Dmitriy-Xawstov Mar 3, 2025
ab69362
Merge pull request #85 from aspose-pdf-cloud/pdfapps-6716-added-use-c…
kaferi Mar 3, 2025
0ac4857
Update appendLink.py
Dmitriy-Xawstov Mar 3, 2025
97b802c
Update getLinksAndShow.py
Dmitriy-Xawstov Mar 3, 2025
0f0a966
Update removeLink.py
Dmitriy-Xawstov Mar 3, 2025
219ef85
Update replaceLink.py
Dmitriy-Xawstov Mar 3, 2025
1900cbe
Update appendNewPage.py
Dmitriy-Xawstov Mar 3, 2025
c6fabcb
Update getPageInfoAndSavePng.py
Dmitriy-Xawstov Mar 3, 2025
c2b5ed0
Update movePageNewPosition.py
Dmitriy-Xawstov Mar 3, 2025
8893c21
Update removePage.py
Dmitriy-Xawstov Mar 3, 2025
9812b08
Update pageAppendTextStamp.py
Dmitriy-Xawstov Mar 3, 2025
f12c3c7
Update wordsCountOnPages.py
Dmitriy-Xawstov Mar 3, 2025
f961136
Update removePage.py
Dmitriy-Xawstov Mar 3, 2025
e25ea86
Merge pull request #81 from aspose-pdf-cloud/pdfapps-6709-added-use-c…
kaferi Mar 4, 2025
258356a
Merge pull request #82 from aspose-pdf-cloud/pdfapps-6710-added-use-c…
kaferi Mar 4, 2025
0f63d86
update to 25.2
Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+

Expand Down
89 changes: 89 additions & 0 deletions Uses-Cases/Attachments/add/appendAttachments.py
Original file line number Diff line number Diff line change
@@ -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()
79 changes: 79 additions & 0 deletions Uses-Cases/Attachments/get/getAttachmentAndSave.py
Original file line number Diff line number Diff line change
@@ -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()
93 changes: 93 additions & 0 deletions Uses-Cases/Bookmarks/add/appendBookmarks.py
Original file line number Diff line number Diff line change
@@ -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()
62 changes: 62 additions & 0 deletions Uses-Cases/Bookmarks/get/getBookmarkByPathAndShow.py
Original file line number Diff line number Diff line change
@@ -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()
Loading