コード例 #1
0
        public async Task <ActionResult> PdfWithXslt(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 XsltMoviePdfRenderer();
            var pdfBytes = pdfTemplatingRenderer.RenderPdf(searchResponse);

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

            return(fileContent);
        }
コード例 #2
0
        public async Task <ActionResult> PdfWithXslt(String title = "Star Wars")
        {
            try
            {
                var searchResponse = await ExecuteMovieSearchHelperAsync(title);

                //*******************************************
                // XSLT + Fonet (synchronous; embedded code)
                //*******************************************
                var pdfRenderer = new XsltMoviePdfRenderer();
                var pdfBytes    = pdfRenderer.RenderPdf(searchResponse);

                //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));
            }
        }
コード例 #3
0
        public async Task <ActionResult> PdfWithXsltAndApacheFOP(String title = "Star Wars")
        {
            try
            {
                var searchResponse = await ExecuteMovieSearchHelperAsync(title);

                //*******************************************
                // XSLT + Apache FOP (async I/O request)
                //*******************************************
                var pdfRenderer = new XsltMoviePdfRenderer();
                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));
            }
        }