Advertisement
andruhovski

Aspose.PDF for Cloud 3

May 29th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1.      private static void Main()
  2.         {
  3.             PdfApi.ExceptionFactory = CustomExceptionFactory;
  4.             BatchConversionHtml2PdfEx02().Wait();
  5.             Console.WriteLine("The conversion completed.");
  6.             Console.ReadLine();
  7.         }
  8.        
  9.         private static async Task BatchConversionHtml2PdfEx02()
  10.         {
  11.             var res = StorageApi.GetListFiles(new GetListFilesRequest(FolderHTML, FirstStorage));
  12.             res.Files[0].Path = "badfile";
  13.             var tasks = res.Files.Select(item => PdfApi.PutCreateDocumentAsync(
  14.                      name: $"{Path.GetFileNameWithoutExtension(item.Name)}.pdf",
  15.                      templateFile: item.Path,
  16.                      templateType: "html",
  17.                      folder: "Pdf-Demo",
  18.                      storage: FirstStorage));
  19.             DocumentResponse[] documentResponses = null;
  20.             try
  21.             {
  22.                 documentResponses = await Task.WhenAll(tasks);
  23.             }
  24.             catch (AggregateException ex)
  25.             {
  26.                 Console.WriteLine(ex.Message);
  27.             }
  28.            
  29.             foreach (var documentResponse in documentResponses)
  30.             {
  31.                 Console.WriteLine(documentResponse.Code);
  32.             }
  33.         }
  34.         public static Exception CustomExceptionFactory(string methodName, RestSharp.IRestResponse response)
  35.         {
  36.             int status = (int)response.StatusCode;
  37.             if (status >= 500) return new Aspose.Pdf.Cloud.Sdk.Client.ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.Content),
  38.                 Newtonsoft.Json.Linq.JObject.Parse(response.Content));
  39.             if (status == 0) return new Aspose.Pdf.Cloud.Sdk.Client.ApiException(status, String.Format("Error calling {0}: {1}", methodName, response.ErrorMessage), response.ErrorMessage);
  40.             return null;
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement