using System;
using System.IO;
using Aspose.Pdf.Cloud.Sdk.Api;

namespace Aspose.PDF.Cloud.Examples.Kb
{
    public class PdfToXls
    {
        public static void ConvertPdfToXls()
        {
            try
            {
                PdfApi pdfApi = new PdfApi("Client Secret", "Client Id");
                
                string localPath = @"C:\Words\";
                string srcFileName = "Sample.pdf";
                string outputFile = "PDFtoXls.xls";

                // Upload source file to the cloud storage
                pdfApi.UploadFile(srcFileName, File.Open(localPath + srcFileName, FileMode.Open));

                pdfApi.PutPdfInStorageToXls(srcFileName,  outputFile);

                // Download the output file from Cloud Storage
                var stream = pdfApi.DownloadFile(outputFile, null, null);

                using (var fileStream = File.Create(localPath + outputFile))
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.CopyTo(fileStream);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
        }
    }
}