/// <summary> /// Download the original document or a version in PDF. /// </summary> /// <param name="uuid">The uuid of the document to download</param> /// <param name="options"></param> /// <returns></returns> public async Task<Stream> DownloadAsync(string uuid, CrocodocDownloadOptions options = null) { if (uuid == null) throw new ArgumentNullException("uuid"); if (string.IsNullOrEmpty(uuid)) throw new ArgumentException("Parameter cannot be an empty string.", "uuid"); if (options == null) { options = CrocodocDownloadOptions.Default; } var parameters = CreateParameters(uuid, options); HttpResponseMessage responseMessage = await GetAsync(Path, Methods.Document, parameters); if (!responseMessage.IsSuccessStatusCode) { var exception = await ReadAsException(responseMessage); throw exception; } Stream stream = await responseMessage.Content.ReadAsStreamAsync(); return stream; }
/// <summary> /// /// </summary> /// <param name="uuid"></param> /// <param name="options"></param> /// <returns></returns> private IDictionary<string,string> CreateParameters(string uuid, CrocodocDownloadOptions options) { var data = new Dictionary<string, string>(); data.Add(Parameters.Token, Token); data.Add(Parameters.Uuid, uuid); data.Add("annotated", options.Annotated ? "true" : "false"); data.Add("pdf", options.Pdf ? "true" : "false"); if (!string.IsNullOrEmpty(options.Filename)) { data.Add("filename", options.Filename); } if (!string.IsNullOrEmpty(options.Filter)) { data.Add("filter", options.Filter); } return data; }