How to Combine DOCX Documents in Python
Creating a scalable file processing workflow often requires the use of specialized external resources. The below API solution will make it easy to quickly combine DOCX documents in your Python workflow, returning the file encoding for a newly combined DOCX document. The first input file in this operation will stack on top of the second file without any formatting changes to either.
To begin your API call, first install the SDK by running this command:
pip install cloudmersive-convert-api-client
Next, add the imports and call the function:
from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.MergeDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file1 = '/path/to/inputfile' # file | First input file to perform the operation on.
input_file2 = '/path/to/inputfile' # file | Second input file to perform the operation on (more than 2 can be supplied).
try:
# Merge Two Word DOCX Together
api_response = api_instance.merge_document_docx(input_file1, input_file2)
pprint(api_response)
except ApiException as e:
print("Exception when calling MergeDocumentApi->merge_document_docx: %s\n" % e)
To complete your API call, include a free-tier Cloudmersive API key (get one by registering a free account here). This will supply a limit of 800 API calls per month and no additional commitments.