Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract Specific Pages from PDF documents using a REST API in Python
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
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 = ""
# 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\\")
# 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)))
# 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\\")
# 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