public Stream Convert(Stream file, string fileName, string outputFileName)
        {
            // Upload input file to cloud storage
            StorageCloudApi.UploadFile(path: fileName, file: file);

            SaveOptionsRequest request = new SaveOptionsRequest()
            {
                FileName = outputFileName,
                Folder   = ""
            };

            // Convert input file (format) to output file (format).
            // Output file will be saved to cloud storage.
            DiagramCloudApi.SaveAs(name: fileName, saveOptionsRequest: request);

            // After conversion, download output file from cloud storage.
            Stream convertResult = StorageCloudApi.DownloadFile(path: outputFileName);

            // Delete both input and output files from cloud storage.
            StorageCloudApi.DeleteFile(path: fileName);
            StorageCloudApi.DeleteFile(path: outputFileName);

            // Return the converted stream
            return(convertResult);
        }
コード例 #2
0
        public ActionResult TestHtml()
        {
            string fileName    = Guid.NewGuid().ToString();
            string pdfFileName = fileName + ".pdf";

            string pdfFileNamePage2 = fileName + "_Page2.pdf";

            using (var file = System.IO.File.OpenRead(Path.Combine(_hostingEnvironment.WebRootPath, "second_page.html")))
            {
                _htmlApi.PostConvertDocumentToPdf(file, pdfFileNamePage2);
            }
            string bearerToken = string.Empty;
            string token       = _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
            Regex  regexp      = new Regex(@"Bearer\s+(?<token>\S+)", RegexOptions.IgnoreCase);
            Match  match       = regexp.Match(token);

            if (match.Success)
            {
                bearerToken = match.Groups["token"].Value;
            }
            StorageApi sa = new StorageApi(new Aspose.Html.Cloud.Sdk.Client.Authentication.JwtToken
            {
                Token            = bearerToken,
                IssuedOn         = DateTime.Today,
                ExpiresInSeconds = 86400
            }, basePath);

            Aspose.Html.Cloud.Sdk.Api.Model.StreamResponse sr = sa.DownloadFile(pdfFileNamePage2);
            return(new FileStreamResult(sr.ContentStream, "application/pdf"));
        }
コード例 #3
0
        public void Run()
        {
            // setup the file name to copy
            string name = "testpage1.html";
            // setup the folder where is the file to copy
            string folder = "/Html/TestData";
            // setup storage name (default storage if null, source and target storages may be different)
            string storage = null;
            // setup file version to download (the latest version if null)
            string versionId = null;

            // setup local directory to save downloaded file.
            string destDir = @"d:\testout";

            var srcPath  = Path.Combine(folder, name).Replace('\\', '/');
            var destPath = Path.Combine(destDir, name);

            IStorageFileApi stApi    = new StorageApi(CommonSettings.ClientId, CommonSettings.ClientSecret, CommonSettings.BasePath);
            var             response = stApi.DownloadFile(srcPath, storage, versionId);

            if (response.Code == 200)
            {
                Console.Out.WriteLine($"File {srcPath} downloaded from storage");
                Stream respStream = response.ContentStream;
                respStream.Position = 0;
                using (Stream fstr = new FileStream(destPath, FileMode.Create, FileAccess.Write))
                {
                    respStream.CopyTo(fstr);
                    fstr.Flush();
                    Console.Out.WriteLine($"Saved as {destDir}");
                }
            }
        }