Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active December 30, 2021 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/7c2ea628c36ce884d1e6f9ca066c6206 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/7c2ea628c36ce884d1e6f9ca066c6206 to your computer and use it in GitHub Desktop.
Merge Documents of Different File Types using REST API in Python

Learn how to merge documents of different file types into PDF using a REST API in Python.

The following topics are covered in this article:

  1. File Merger REST API and Python SDK
  2. Merge Multiple File Types using REST API in Python
  3. How to Merge PDF and Excel into PDF
  4. How to Merge PDF and PowerPoint into PDF
  5. Combine Specific Pages of Different File Types in Python
# This code example demonstrates how to add client id and secret in the code.
client_id = "659fe7da-715b-4744-a0f7-cf469a392b73"
client_secret = "b377c36cfa28fa69960ebac6b6e36421"
configuration = groupdocs_merger_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
my_storage = ""
# This code example demonstrates how to download a merged file from the cloud.
# API initialization
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration)
# Create download file request
request = groupdocs_merger_cloud.DownloadFileRequest("joined.pdf", my_storage)
# Download file
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\Merger\\")
# This code example demonstrates how to merge documents of different file types in Python.
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
# First file
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("sample.pdf")
# Page numbers to merge from first document
item1.pages = [1, 2]
# Second file
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("sample.docx")
# Page range to merge from second document
item2.start_page_number = 1
item2.end_page_number = 3
# Join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "joined.pdf"
# Create join request with JoinOptions
request = groupdocs_merger_cloud.JoinRequest(options)
# Join files
result = documentApi.join(request)
# This code example demonstrates how to merge documents of different file types in Python.
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
# First file
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("sample.pdf")
# Second file
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("sample.docx")
# Join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "joined.pdf"
# Create join request with JoinOptions
request = groupdocs_merger_cloud.JoinRequest(options)
# Join files
result = documentApi.join(request)
# This code example demonstrates how to merge Word and Excel file into PDF using Python.
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
# First file
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("sample.pdf")
# Second file
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("sample.xlsx")
# Join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "joined.pdf"
# Create join request with JoinOptions
request = groupdocs_merger_cloud.JoinRequest(options)
# Join files
result = documentApi.join(request)
# This code example demonstrates how to merge Word and JPG image into PDF using Python.
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
# First file
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("sample.pdf")
# Second file
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("sample.jpg")
# Join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "joined.pdf"
# Create join request with JoinOptions
request = groupdocs_merger_cloud.JoinRequest(options)
# Join files
result = documentApi.join(request)
# This code example demonstrates how to merge Word and PowerPoint presentation into PDF using Python.
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
# First file
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("sample.pdf")
# Second file
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("sample.pptx")
# Join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "joined.pdf"
# Create join request with JoinOptions
request = groupdocs_merger_cloud.JoinRequest(options)
# Join files
result = documentApi.join(request)
# This code example demonstrates how to upload files to the cloud.
# Create an instance of the APIs
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration)
# Upload sample files
for filename in glob.iglob("C:\\Files\\Merger\\upload\\*.*", recursive=True):
destFile = filename.replace("C:\\Files\\Merger\\upload", "", 1)
# Create upload file request
request = groupdocs_merger_cloud.UploadFileRequest(destFile, filename)
# Upload file
file_api.upload_file(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment