Beispiel #1
0
        public async Task <ActionResult> PdfWithRazor(String title = "Star Wars")
        {
            //Execute the Move Search to load data . . .
            //NOTE: This can come from any source, and can be from converted JSON or Xml, etc.
            //NOTE: As an interesting use case here, we load the results dynamically from a Movie Search
            //      Database REST call for JSON results, and convert to Xml dynamically to use efficiently
            //      with our templates.
            var movieSearchService = new MovieSearchService();
            var searchResponse     = await movieSearchService.SearchAsync(title);

            //Initialize the appropriate Renderer based on the Parameter.
            // and execute the Pdf Renderer to generate the Pdf Document byte data
            IPdfTemplatingRenderer <MovieSearchResponse> pdfTemplatingRenderer = new RazorMoviePdfRenderer(ControllerContext);
            var pdfBytes = pdfTemplatingRenderer.RenderPdf(searchResponse);

            //Create the File Content Result from the Pdf byte data
            var fileContent = new FileContentResult(pdfBytes, "application/pdf");

            return(fileContent);
        }
        public async Task <ActionResult> PdfWithRazorAndApacheFOP(String title = "Star Wars")
        {
            try
            {
                var searchResponse = await ExecuteMovieSearchHelperAsync(title);

                //*******************************************
                // RAZOR + Apace FOP (async I/O request)
                //*******************************************
                var pdfRenderer = new RazorMoviePdfRenderer(ControllerContext);
                var pdfBytes    = await pdfRenderer.RenderPdfAsync(searchResponse).ConfigureAwait(false);

                //Create the File Content Result from the Pdf byte data
                return(new FileContentResult(pdfBytes, WebContentType.Pdf));
            }
            catch (Exception exc)
            {
                //Bubble up the Error as Json for additional Details
                return(CreateJsonExceptionResult(exc));
            }
        }
        public async Task <ActionResult> PdfWithRazor(String title = "Star Wars")
        {
            try
            {
                var searchResponse = await ExecuteMovieSearchHelperAsync(title);

                //*******************************************
                // RAZOR + Fonet (synchronous; embedded code)
                //*******************************************
                var pdfRenderer = new RazorMoviePdfRenderer(ControllerContext);
                var pdfBytes    = pdfRenderer.RenderPdf(searchResponse);

                //Create the File Content Result from the Pdf byte data
                return(new FileContentResult(pdfBytes, WebContentType.Pdf));
            }
            catch (Exception exc)
            {
                //Since the Apache FOP Service provides helpful errors on syntax issues, we want to let
                //  those details bubble up to the caller for troubleshooting...
                return(CreateJsonExceptionResult(exc));
            }
        }