Created
May 18, 2021 07:26
-
-
Save groupdocs-cloud-gists/a3ca0a016a85bcb0c9abd7bca43bc9e6 to your computer and use it in GitHub Desktop.
Extract Specific Pages from PDF documents using a REST API in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extract Specific Pages | |
1. Programmatically upload a PDF file on the cloud | |
2. Extract Specific Pages by Page Numbers using a REST API in Python | |
3. Extract Specific Pages by Page Range using a REST API in Python | |
4. Download extracted PDF Pages from Cloud |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client_id = "da0c487d-c1c0-45ae-b7bf-43eaf53c5ad5" | |
client_secret = "479db2b01dcb93a3d4d20efb16dea971" | |
configuration = groupdocs_merger_cloud.Configuration(client_id, client_secret) | |
configuration.api_base_url = "https://api.groupdocs.cloud" | |
my_storage = "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# api initialization | |
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration) | |
my_storage = "" | |
# download file request | |
request = groupdocs_merger_cloud.DownloadFileRequest("Output\\ten-pages_1.pdf", my_storage) | |
response = file_api.download_file(request) | |
# move downloaded file to your working directory | |
shutil.move(response, "C:\\Files\\") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# api initialization | |
documentApi = groupdocs_merger_cloud.DocumentApi.from_config(configuration) | |
# define split options | |
options = groupdocs_merger_cloud.SplitOptions() | |
options.file_info = groupdocs_merger_cloud.FileInfo("ten-pages.pdf") | |
options.output_path = "Output" | |
options.pages = [1, 3] | |
options.mode = "Pages" | |
# create split request | |
split_request = groupdocs_merger_cloud.SplitRequest(options) | |
result = documentApi.split(split_request) | |
print("Documents count = " + str(len(result.documents))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# api initialization | |
documentApi = groupdocs_merger_cloud.DocumentApi.from_config(configuration) | |
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration) | |
my_storage = "" | |
# define split options | |
options = groupdocs_merger_cloud.SplitOptions() | |
options.file_info = groupdocs_merger_cloud.FileInfo("ten-pages.pdf") | |
options.output_path = "Output" | |
options.start_page_number = 4 | |
options.end_page_number = 7 | |
options.mode = "Pages" | |
# create split request | |
split_request = groupdocs_merger_cloud.SplitRequest(options) | |
result = documentApi.split(split_request) | |
print("Documents count = " + str(len(result.documents))) | |
# show results and download files one by one | |
for data in result.documents: | |
print("Document Url = " + str(data)) | |
# create download file request | |
request = groupdocs_merger_cloud.DownloadFileRequest(data.path, my_storage) | |
response = file_api.download_file(request) | |
# Move downloaded file to your working directory | |
shutil.move(response, "C:\\Files\\") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create instance of the API | |
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration) | |
my_storage = "" | |
# upload sample files | |
request = groupdocs_merger_cloud.UploadFileRequest("ten-pages.pdf", "C:\\Files\\ten-pages.pdf", my_storage) | |
response = file_api.upload_file(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment