Convert Word Mail Merge Template results to PDF with Aspose.Words Cloud API

Hi,

Is there any possibility of setting the output format for the executeTemplate (online) api call? By default the api is returning a word document based on the template format. What if we want a PDF as output?

I know the api can also convert the document in a separate call. But as I can read on your pricing page, this will cost 2 credits instead of 1 when directly converting to a different format. Did also saw some older topics about this but not specific for the executeTemplate Online (so without your storage in between).

Thanks.

@sanderApp

Thank you for contacting us.

Unfortunately, at present with Mail Merge APIs you cannot save an output document in any format other than docx and doc. But I have logged the request (WORDSCLOUD-364) in our internal tracking software to discuss whether we can give a user an option to save Mail Merge documents in others formats (in a single API call). I will update you here once I have some information to share with you.

The issues you have found earlier (filed as WORDSCLOUD-364) have been fixed in this update. This message was posted using Bugs notification tool by Ivanov_John

@sanderApp

Recently we have introduced a feature for batch requests. It allows you to run a bunch of requests as one. For your scenario, please check the following code snippet and confirm if it fulfills your requirement or not?

string localDocumentFile = @"....Template.docx";
            string localTemplateData = @"....TemplateData.txt";
            string pdfFile = @"....result.pdf";

            // create requests
            using (var templateStream = File.OpenRead(localDocumentFile))
            {
                using (var dataStream = File.OpenRead(localTemplateData))
                {
                    // use online version, they can combine uploading and real work in one request
                    var mergeRequest = new BatchPartRequest(new ExecuteMailMergeOnlineRequest(
                        template: templateStream,
                        data: dataStream
                    ));

                    // note that you can use the previous request's response as a source for the next one
                    var convertRequest = new BatchPartRequest(new SaveAsOnlineRequest(
                        mergeRequest.UseAsSource(),
                        new SaveOptionsData
                        {
                            SaveFormat = "pdf",
                            FileName = "result.pdf"
                        }
                        ));

                    // don't forget to set dependency. It guarantees the correct order of execution.
                    convertRequest.DependsOn(mergeRequest);

                    var result = this.WordsApi.Batch(mergeRequest, convertRequest);

                    using (var fs = new FileStream(pdfFile, FileMode.OpenOrCreate))
                    {
                        (result[1] as SaveAsOnlineResponse).Document.CopyTo(fs);
                    }
                }
            }
        }