Merge Multiple Word Documents into Single Doc in Cloud using Python REST API

Aspose.Words for Cloud shows developers how to merge multiple Word documents into a single document in cloud using Python. To merge documents, you need to upload input Word documents to Aspose for Cloud or any supported third party storage and then send a POST request to Aspose for Cloud service.

This post covers how developers can merge multiple Word documents into a single document in Python using Aspose.Words for Cloud. You can check Append a List of Word Documents for other languages on the following link.

http://www.aspose.com/docs/display/wordscloud/Append+a+List+of+Word+Documents

To merge documents, you need to upload input Word documents to Aspose for Cloud or any supported third party storage and then send a POST request to Aspose for Cloud service. If you are building applications to generate or process Word documents, merging multiple documents into one document is an important feature to have in such applications.

Aspose.Words for Cloud supports DOC, OOXML, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats and enables you to perform a wide range of document processing tasks in any language including .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. You can use it with any language or platform that supports REST. (Almost all platforms and languages support REST and provide native REST clients to work with REST APIs).

Following steps describe the process in detail.


Merge multiple Word documents using Python REST


This REST example uses pycurl library to send HTTP request and handle HTTP response so you need to install it to use this example. Once input Word documents are uploaded, you can use the following URI to merge documents on Aspose for Cloud or any supported third party storage.


http://api.aspose.com/v1.1/words/MainDocument.docx/appendDocument


You can use a couple of optional parameters with the above mentioned URI. All or specific parameters can be used according to your requirement.

After building URI, you need to go through the following steps:

• Set App SID and App Key and sign URI. See section 1 of the following code and Sign URI method for more details.
• Build JSON to post in the request body. A list of input documents including their paths and import format modes should be provided. See section 2 of the following code.
• Send a POST request to Aspose for Cloud service. See section 3 of the following code and process_command method for more details.
• Download merged document file if required. See section 4 of the following code.


Following is the code to merge multiple Word documents.


####### Section 1 ######
# specify App SID
AsposeApp.app_sid = '77****-****-****-****-80*********'
# specify App Key
AsposeApp.app_key = '******************'
#build URI to merge PDFs
str_uri = 'http://api.aspose.com/v1.1/words/MainDocument.docx/appendDocument'
#sign URI
signed_uri = Utils.sign(Utils(), str_uri)

####### End Section 1 ######

####### Section 2 ######
#Build JSON to post
json_document1 = json.dumps({'Href' : 'AppendDocument1.docx', 'ImportFormatMode' : 'KeepSourceFormatting'})
json_document2 = json.dumps({'Href' : 'AppendDocument2.docx', 'ImportFormatMode' : 'UseDestinationStyles'})
json_arr = '{\'DocumentEntries\':[' + json_document1 + ',' + json_document2 + ']}'

####### End Section 2 ######

####### Section 3 ######
Utils.process_command(Utils(), signed_uri, 'POST', 'JSON', json_arr)
####### End Section 3 ######

####### Section 4 ######

#build URI to download output file
str_uri = 'http://api.aspose.com/v1.1/storage/file/MainDocument.docx'
#sign URI
signed_uri = Utils.sign(Utils(), str_uri)
response_stream = Utils.process_command(Utils(),signed_uri, 'GET')
Utils.save_file(Utils(),response_stream, 'MergedFile.docx')

####### End Section 4 ######


Merge multiple Word documents using Python SDK


If you want to use our Python SDK to merge Word documents, you can download the following SDK from Aspose for Cloud SDK for Python.

https://github.com/asposeforcloud/Aspose_Cloud_SDK_For_Python

In order to use Python SDK, you need to perform following steps:


• Set base product URI, App SID, App Key and output location. See section 1 of the complete code.
• Create object of WordDocument class and call append_document method passing array of names of documents to merge, array of import format modes, and folder name where input documents are present. See section 3 of the complete code.


Following is the complete code.



####### Section 1 ######

# specify App SID
AsposeApp.app_sid = '77****-****-****-****-80*********'
# specify App Key
AsposeApp.app_key = '******************'
AsposeApp.output_location = '';
# set base product uri
Product.base_product_uri = 'http://api.aspose.com/v1.1'
####### End Section 1 ######

####### Section 2 ######

# set parameters
file_name = 'MainDocument.docx'
# create the string array to hold document names
append_docs = ['AppendDocument1.docx', 'AppendDocument2.docx']
# create the string array to hold import format modes
import_format_modes = ['KeepSourceFormatting', 'UseDestinationStyles']
folder_name = ""

####### End Section 2 ######

####### Section 3 ######

# Instantiate the WordDocument class
document = WordDocument(file_name)
# append a list of documents
printdocument.append_document(append_docs, import_format_modes, folder_name)

####### End Section 3 ######


Overview: Aspose for Cloud


Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols. It supports all features for file processing, document scanning, barcodes creation and recognition, and allows extracting text or images too. You can also work with SaaSpose APIs using REST SDKs that can be called from .NET, Java, PHP and Ruby etc.


More about Aspose for Cloud


- Learn More about Aspose.Words for Cloud: http://www.aspose.com/cloud/word-api.aspx

- Aspose.Words for Cloud Documentation: http://www.aspose.com/docs/display/wordscloud/Working+with+Mail+Merge

- Download Aspose Cloud SDK for Python: https://github.com/asposeforcloud/Aspose_Cloud_SDK_For_Python

- Aspose for Cloud Examples: http://www.aspose.com/docs/display/rest/Aspose+for+Cloud+REST+Live+Examples

- Ask technical questions/queries from Aspose for Cloud Support Team: http://www.aspose.com/community/forums/default.aspx?GroupID=15



Contact Details

Company Name: Aspose
Issued By: Zeeshan Haider
Phone: 888.277.6734
Address: Suite 163, 79 Longueville Road
City: Lane Cove
State: NSW
Zip: 2066
Country: Australia
Website: Visit the website

Keywords : mail merge in Python, simple mail merge in cloud, merging multiple documents in cloud, merge documents on Aspose for Cloud, Merge multiple Word documents using Python SDK, Aspose for Cloud SDK for Python, process Word documents in cloud, Aspose.Words for Cloud, REST API, Slides API, Cloud API,

by Zeeshan Haider (few years ago!)

Latest Press Releases

The Mad Hatter Now Offer a Full Line of Hearth Products and Full Line of Grills

Diabetes Insulin Delivery Pens Market Research Report 2018

Dr Kapadia Provides Tips to Patients Interested in Hair Transplant Procedures

love vashikaran specialist

Solar Blanket Sales Market Report 2018

Spring Bottled Water Market Insights, Forecast to 2025

Biochemical Incubator Sales Market Report 2018

Quinine Sulphate Sales Market Report 2018

Automotive Chassisc System Market Insights, Forecast to 2025

2,6-Dicarboxypyridine market size in key regions like North America, Europe, Asia Pacific an..

Remove this press release ?

Due to extra work required to remove the press-releases we have started charging $1.99 for press release removal.

Your press release will be removed in 24 hours, once the payment has been received.

Search Press Release
e.g. Business, Computer, etc.