/// <summary> /// Gets all Drawing Objects from document /// </summary> /// <param name="FileName"></param> /// <param name="outputPath"></param> /// <returns></returns> public void GetDrawingObjects(string FileName, string outputPath) { //build URI to get Drawing Objects string strURI = Product.BaseProductUri + "/words/" + FileName + "/drawingObjects"; string signedURI = Utils.Sign(strURI); Stream responseStream = Utils.ProcessCommand(signedURI, "GET"); StreamReader reader = new StreamReader(responseStream); string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. DrawingObjectsResponse Response = JsonConvert.DeserializeObject <DrawingObjectsResponse>(parsedJSON.ToString()); int i = 1; foreach (Aspose.Cloud.Words.List list in Response.DrawingObjects.List) { GetDrawingObject(list.link.Href, outputPath); i++; } }
/// <summary> /// Get the List of drawing object from document /// </summary> /// <param name="FileName"></param> public Dictionary <int, string> GetDrawingObjectList(string FileName) { try { //build URI to get Drawing Objects string strURI = Product.BaseProductUri + "/words/" + FileName + "/drawingObjects"; string signedURI = Utils.Sign(strURI); Stream responseStream = Utils.ProcessCommand(signedURI, "GET"); StreamReader reader = new StreamReader(responseStream); string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. DrawingObjectsResponse Response = JsonConvert.DeserializeObject <DrawingObjectsResponse>(parsedJSON.ToString()); int index = 0; Dictionary <int, string> dObject = new Dictionary <int, string>(); foreach (Aspose.Cloud.Words.List list in Response.DrawingObjects.List) { responseStream = Utils.ProcessCommand(Utils.Sign(list.link.Href), "GET"); reader = new StreamReader(responseStream); strJSON = reader.ReadToEnd(); parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. Response = JsonConvert.DeserializeObject <DrawingObjectsResponse>(parsedJSON.ToString()); if (Response.DrawingObject.ImageDataLink != null && Response.DrawingObject.OleDataLink == null) { dObject.Add(index, Response.DrawingObject.ImageDataLink.Href); index++; } else if (Response.DrawingObject.OleDataLink != null) { dObject.Add(index, Response.DrawingObject.OleDataLink.Href); index++; } else { dObject.Add(index, Response.DrawingObject.RenderLinks[0].Href); index++; } } responseStream.Close(); return(dObject); } catch (Exception ex) { return(null); } }
/// <summary> /// Get the drawing object from document /// </summary> /// <param name="strURI"></param> /// <param name="outputPath">C:\Output.jpg</param> public void GetDrawingObject(string strURI, string outputPath) { try { //build URI to get Drawing Objects string signedURI = Utils.Sign(strURI); Stream responseStream = Utils.ProcessCommand(signedURI, "GET"); StreamReader reader = new StreamReader(responseStream); string strJSON = reader.ReadToEnd(); //Parse the json string to JObject JObject parsedJSON = JObject.Parse(strJSON); //Deserializes the JSON to a object. DrawingObjectsResponse Response = JsonConvert.DeserializeObject <DrawingObjectsResponse>(parsedJSON.ToString()); string index = Response.DrawingObject.link.Href.Substring(Response.DrawingObject.link.Href.LastIndexOf("/") + 1).ToString(); if (Response.DrawingObject.ImageDataLink != null && Response.DrawingObject.OleDataLink == null) { //build URI to get Image strURI = strURI + "/imageData";//?format=" + DrawingObjectsRenderFormat.jpeg; outputPath = outputPath + "\\DrawingObject_" + index + "." + DrawingObjectsRenderFormat.jpeg; } else if (Response.DrawingObject.OleDataLink != null) { //build URI to get OLE strURI = strURI + "/oleData"; //format=" + DrawingObjectsRenderFormat.jpeg; outputPath = outputPath + "\\DrawingObject__" + index + ".xlsx"; // This needs to be discuss } else { //build URI to get Image strURI = strURI + "?format=" + DrawingObjectsRenderFormat.jpeg; outputPath = outputPath + "\\DrawingObject__" + index + "." + DrawingObjectsRenderFormat.jpeg; } signedURI = Utils.Sign(strURI); responseStream = Utils.ProcessCommand(signedURI, "GET"); using (Stream fileStream = System.IO.File.OpenWrite(outputPath)) { Utils.CopyStream(responseStream, fileStream); } responseStream.Close(); } catch (Exception ex) { } }