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

namespace Aspose.PDF.Cloud.Examples.Kb
{
    public class PdfToPdfA
    {
        public static void ConvertPdfToPdfA()
        {
            try
            {
                PdfApi pdfApi = new PdfApi("Client Secret", "Client Id");

                string localPath = @"C:\PDF\";
                string srcFileName = "Sample.pdf";
                string outputFile = "PDFtoPdfA.pdf";

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

                // Convert PDF to PDFA
                AsposeResponse response =  pdfApi.PutPdfInStorageToPdfA(srcFileName, outputFile, PdfAType.PDFA1A.ToString());

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

                // Save output to file
                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);
            }
        }
    }
}