What's New in this Release?
Mail merge allows you to produce document (potentially large numbers of documents) from a single template and a structured data source. The letter may be sent out to many recipients with small changes, such as a change of address or a change in the greeting line. It can also be used to generate business reports, purchase orders, receipts, catalogs, inventories, and invoices etc. Aspose.Words for Cloud Mail Merge allows you to generate documents from a template and XML 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 API). This post covers
mail merge in PHP, you can check Aspose.Words for Cloud documentation for other languages. To execute mail merge, you need to upload a template to Aspose for Cloud or any supported third party storage and then send a POST request (passing XML data in the request body) to generate documents based on template and data. The following steps describe the process in detail. Aspose.Words for Cloud supports simple mail merge and mail merge with regions. If you want to insert simple or non-repeating data, for example name, address and code fields on an envelope, or to and from fields in a letter, use simple mail merge (also called mail merge without regions). If you are preparing reports, invoices and purchase orders, or similar documents, and want to insert tables, rows or repeating data, or if you want your documents to dynamically grow based on your input data, use mail merge with regions.
Mail Merge using PHP REST
Before you execute mail merge, you need to upload your template Word file and XML data to Aspose for Cloud or any supported third party storage. See Upload File examples for more details. Once you upload your template and XML, you can use the URI to execute mail merge
There are several optional parameters you can use with the above mentioned URI. All or specific parameters can be used according to your requirement. Following is the detail of these optional parameters.
- withRegions — This parameter can be set to true if you want to execute mail merge with regions. See section 1 of the complete code.
- mailMergeDataFile — This parameter can be set to specify the XML data file. See section 1 of the complete code.
- cleanup — This parameter can be set specify different cleanup options e.g. if you want to remove empty paragraphs, unused fields and empty tables etc. See section 1 of the complete code and executeMailMerge resource.
- filename — This parameter can be used to specify name of the file generated as a result of mail merge.
- storage — This parameter can be used to set storage name if you are using a third party storage.
- folder — This parameter can be used to set the name/path of the folder where template file is uploaded.
After building the URI, go through the following steps:
- Set App SID and App Key and sign URI. See section 2 of the complete code and Sign URI method for more details.
- Send a POST request to Aspose for Cloud service. See section 3 of the complete code and ProcessCommand method for more details.
- Get output file name from the response stream. See section 4 of the complete code.
Mail Merge using PHP SDK
If you want to use our PHP SDK to execute mail merge, you can download this SDK from Aspose for Cloud SDK for PHP. In order to use PHP SDK, you need to perform following steps:
- Set base product URI, App SID and App Key. See section 1 of the complete code.
- Set output location, input file name and input XML. See section 2 of the complete code.
- Upload input file. See section 3 of the complete code.
- Create object of MailMerge class and call executeMailMerge method for simple mail merge and executeMailMergeWithRegions method for mail merge with regions. See section 4 of the complete code.
For XML & PDF Code Samples and other details please visit the main blog post page.
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.