private async Task <MemoryStream> InvokeCreation(Models.GenerationRequest data) { MemoryStream ms; var path = data.Template.Url; var client = new System.Net.WebClient(); var src = await client.DownloadDataTaskAsync(path); Scryber.Components.Document doc = null; using (ms = new MemoryStream(src)) { doc = Scryber.Components.Document.ParseDocument(ms, path, ParseSourceType.RemoteFile); } if (data.Params != null) { foreach (var p in data.Params) { doc.Params[p.Key] = p.Value; } } ms = new MemoryStream(); doc.SaveAsPDF(ms, true); return(ms); }
public async Task <FileStreamResult> Inline(Models.GenerationRequest data) { var content = await Task.Run(() => { return(InvokeCreation(data)); }); return(File(content, "application/pdf")); }
public async Task <Models.GenerationResult> Get(Models.GenerationRequest request) { bool success = false; string errors = ""; long binlength = -1; string base64 = ""; var name = request.Output.FileName; if (string.IsNullOrEmpty(name)) { name = "Document.pdf"; } MemoryStream content = null; try { content = await InvokeCreation(request); content.Flush(); binlength = content.Length; content.Position = 0; base64 = Convert.ToBase64String(content.ToArray()); success = true; } catch (Exception ex) { success = false; errors = ex.Message; } finally { if (null != content) { await content.DisposeAsync(); } } GenerationResultData data = null; if (success) { data = new GenerationResultData() { Base64 = base64, Length = base64.Length, DecodedLength = binlength }; } GenerationResult result = new GenerationResult() { Data = data, Success = success, Errors = errors, OriginalSource = request.Template.Url, FileName = name }; return(result); }