Posted By

nausherwan on 05/29/14


Tagged

images slides Aspose asposeslides


Versions (?)

Save a PowerPoint Slide as Image with Specified Size using Aspose.Slides for Cloud API


 / Published in: C#
 

URL: http://www.aspose.com/docs/display/slidescloud/Save+a+PowerPoint+Slide+as+Image+with+Specified+Size

This sample code allows developers to save a particular slide as image with specified size using Aspose.Slides for Cloud API in their applications. Developers can use our REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.

  1. //sepcify App SID
  2. AsposeApp.AppSID = "77******-1***-4***-a***-80**********";
  3. //sepcify App Key
  4. AsposeApp.AppKey = "********************************";
  5.  
  6. string filename = "demo.ppt";
  7.  
  8. string format = "JPEG";
  9.  
  10. int width = 800;
  11.  
  12. int height = 600;
  13.  
  14. //build URI
  15. string strURI = "http://api.aspose.com/v1.1/slides/"+filename+"/slides/1?format="+format+"&width="+ width +"&height="+ height;
  16.  
  17. string signedURI = Sign(strURI);
  18.  
  19. Stream responseStream = ProcessCommand(signedURI, "GET");
  20.  
  21. using (Stream fileStream = System.IO.File.OpenWrite("C:\\Slide1.jpg"))
  22. {
  23. CopyStream(responseStream, fileStream);
  24. }
  25. responseStream.Close();
  26.  
  27.  
  28. /// <summary>
  29. /// Copies the contents of input to output. Doesn't close either stream.
  30. /// </summary>
  31. public static void CopyStream(Stream input, Stream output)
  32. {
  33. try
  34. {
  35. byte[] buffer = new byte[8 * 1024];
  36. int len;
  37. while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
  38. {
  39. output.Write(buffer, 0, len);
  40. }
  41. }
  42. catch (Exception ex)
  43. {
  44. throw new Exception(ex.Message);
  45. }
  46. }
  47.  
  48. /// <summary>
  49. /// Method to Sign your app key
  50. /// This should be called with each URI resource
  51. /// before sending any HTTP command to the remote server
  52. /// </summary>
  53. public static string Sign(string url, string AppSID, string AppKey)
  54. {
  55. try
  56. {
  57. // Add appSID parameter.
  58. UriBuilder builder = new UriBuilder(url);
  59. if (builder.Query != null && builder.Query.Length > 1)
  60. builder.Query = builder.Query.Substring(1) + "&appSID=" + AppSID;
  61. else
  62. builder.Query = "appSID=" + AppSID;
  63. // Remove final slash here as it can be added automatically.
  64. builder.Path = builder.Path.TrimEnd('/');
  65. // Compute the hash.
  66.  
  67. byte[] privateKey = System.Text.Encoding.UTF8.GetBytes(AppKey);
  68.  
  69. System.Security.Cryptography.HMACSHA1 algorithm = new System.Security.Cryptography.HMACSHA1(privateKey);
  70. //System.Text.ASCIIEncoding
  71. byte[] sequence = System.Text.ASCIIEncoding.ASCII.GetBytes(builder.Uri.AbsoluteUri);
  72. byte[] hash = algorithm.ComputeHash(sequence);
  73. string signature = Convert.ToBase64String(hash);
  74. // Remove invalid symbols.
  75. signature = signature.TrimEnd('=');
  76. signature = System.Web.HttpUtility.UrlEncode(signature);
  77. // Convert codes to upper case as they can be updated automatically.
  78. signature = System.Text.RegularExpressions.Regex.Replace(signature, "%[0-9a-f]{2}", e => e.Value.ToUpper());
  79. //signature = System.Text.RegularExpressions.Regex.Replace(signature, "%[0-9a-f]{2}", delegate(string e){ e.Value.ToUpper()});
  80. // Add the signature to query string.
  81. return string.Format("{0}&signature={1}", builder.Uri.AbsoluteUri, signature);
  82. }
  83. catch (Exception ex)
  84. {
  85. throw new Exception(ex.Message);
  86. }
  87. }
  88.  
  89. public static Stream ProcessCommand(string strURI, string strHttpCommand)
  90. {
  91. try
  92. {
  93. Uri address = new Uri(strURI);
  94. System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(address);
  95. request.Method = strHttpCommand;
  96. request.ContentType = "application/json";
  97.  
  98. request.ContentLength = 0;
  99. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
  100. return response.GetResponseStream();
  101. }
  102. catch (System.Net.WebException webex)
  103. {
  104. throw new Exception(webex.Message);
  105. }
  106. catch (Exception Ex)
  107. {
  108. throw new Exception(Ex.Message);
  109. }
  110. }

Report this snippet  

You need to login to post a comment.