Sunday, December 30, 2012

Merge Multiple Presentations by Passing List of All Files in .NET Apps

This technical tip allows developers to merge multiple presentation files using Saaspose.Slides REST API in your .NET applications. You can pass a list of all the files you want to merge using this example. Developers need to upload all the input files (Presentation1.pptx, Presentation2.pptx and Presentation3.pptx in case of this example) before running this example. Please check Upload File to Saaspose for how to. Some important steps for performing this task are to specify product URI, build URI, build URI to download merged presentation and Save output file.
Sample Code for Adding Watermark Text to a Word Document
SaasposeApp.AppKey = "89**********************";
SaasposeApp.AppSID = "77***********************";
//specify product URI
Product.BaseProductUri = @"http://api.saaspose.com/v1.0";
string[] presentationsList = new string[] { "Presentation2.pptx", "Presentation3.pptx" };
PresentationsList list = new PresentationsList();
list.PresentationPaths = presentationsList;
string strJSON = JsonConvert.SerializeObject(list);
//build URI
string strURI = "http://api.saaspose.com/v1.0/slides/Presentation1.pptx/merge"; //Product.BaseProductUri + "/pdf/" + basePdf + "/appendDocument?appendFile=" + newPdf + "&startPage=1&endPage=" + iPageCount.ToString();
string signedURI = Utils.Sign(strURI);
Utils.ProcessCommand(signedURI, "POST", strJSON);
// build URI to download merged presentation
strURI = "http://api.saaspose.com/v1.0/storage/file/Presentation1.pptx";
signedURI = Utils.Sign(strURI);
using (Stream responseStream = Utils.ProcessCommand(signedURI, "GET"))
{
    //Save output file
    using (Stream fileStream = System.IO.File.OpenWrite("C:\\MergedPresentation.pptx"))
    {
        Utils.CopyStream(responseStream, fileStream);
    }
}
//Following is the PresentationsList class
/// <summary>
/// represents list of presentations to be merged
/// </summary>
class PresentationsList
{
    public PresentationsList() { }
    public string[] PresentationPaths { get; set; }
}
//build URI to upload file to Saaspose
            string strURI = "http://api.saaspose.com/v1.0/storage/file/MyRemoteFileName";
            string signedURI = Sign(strURI);
            UploadFileBinary(localfilepath, signedURI, "PUT");                        
Overview: Saaspose.Slides
Saaspose.Slides is a REST based API that allows developers to read, write & modify a PowerPoint presentations in cloud. It is platform independent API & can be used by developers in web, desktop, mobile & cloud applications alike. It provides a rich set of features like creating presentation from scratch, modify various aspect of a presentation & converting a presentation to PDF, XPS, TIFF, SVG, HTML, PNG, JPEG, GIF & BMP formats. It helps you add, modify or extract text from the presentation.
More about Saaspose.Slides
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465

No comments:

Post a Comment