Beispiel #1
0
        public IActionResult DownloadToHtml(JupyterPreviewModel model)
        {
            var jupyterText = model.PreviewJson;

            if (!string.IsNullOrEmpty(jupyterText))
            {
                //convert to document
                var document = Jupyter.Parse(jupyterText);

                //convert to html
                string fileName  = "jupyterDocument.html";
                byte[] fileBytes = null;
                using (var memoryStream = new MemoryStream())
                {
                    using (var writer = new StreamWriter(memoryStream))
                    {
                        var htmlRenderer = new HtmlRenderer(writer)
                        {
                            RendererHeaderAndFooter = true
                        };
                        htmlRenderer.Render(document);
                    }
                    fileBytes = memoryStream.ToArray();
                }

                //diwnload
                return(File(fileBytes, "application/force-download", fileName));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public IActionResult PreviewHtml(JupyterPreviewModel model)
        {
            if (string.IsNullOrEmpty(model.SelectedItem))
            {
                return(RedirectToAction("Index"));
            }

            var jupyterText = model.PreviewJson;

            if (!string.IsNullOrEmpty(jupyterText))
            {
                //convert to document
                var document = Jupyter.Parse(jupyterText);

                string htmlText = null;
                using (var memoryStream = new MemoryStream())
                {
                    using (var writer = new StreamWriter(memoryStream))
                    {
                        var htmlRenderer = new HtmlRenderer(writer)
                        {
                            RendererHeaderAndFooter = true,
                            CssText = GetCssFromSelection(model.SelectedItem)
                        };
                        htmlRenderer.Render(document);
                    }
                    htmlText = Encoding.UTF8.GetString(memoryStream.ToArray());
                }

                //preview
                return(Content(htmlText, "text/html", Encoding.UTF8));
            }

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public IActionResult DownloadToPdf(JupyterPreviewModel model)
        {
            var jupyterText = model.PreviewJson;

            if (!string.IsNullOrEmpty(jupyterText))
            {
                //convert to document
                var document = Jupyter.Parse(jupyterText);

                //convert to html
                string fileName  = "jupyterDocument.pdf";
                byte[] fileBytes = null;
                using (var memoryStream = new MemoryStream())
                {
                    var htmlRenderer = new PdfRenderer(memoryStream);
                    htmlRenderer.Render(document);
                    fileBytes = memoryStream.ToArray();
                }

                return(File(fileBytes, "application/force-download", fileName));
            }

            return(RedirectToAction("Index"));
        }