public async Task <IActionResult> TestTemplate() { try { // ************************************************************* // Create output using json and mustache template // ************************************************************* RenderRequest request = new RenderRequest() { JsonString = "{\"title\": \"Sample Template\", \"name\": \"McTesty\"}", RenderJsUrl = _configuration.GetSection("Constants").GetSection("RenderJsUrl").Value, Template = _configuration.GetSection("Constants").GetSection("SampleTemplate").Value }; string result = await TemplateHelper.RenderDocument(_nodeServices, request); // ************************************************************* // Convert results to Pdf // ************************************************************* PdfRequest pdfRequest = new PdfRequest() { Html = "<h1>" + result + "<h1>", PdfFileName = "TestTemplate" }; byte[] pdfResponse = PdfDocument.BuildPdf(_configuration, pdfRequest); return(File(pdfResponse, "application/pdf")); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <IActionResult> GetSeniorityListPdf([FromBody] string seniorityListJson, [FromRoute] string name) { try { name = CleanName(name); string fileName = name + ".pdf"; _logger.LogInformation("GetSeniorityListPdf [FileName: {0}]", fileName); // ************************************************************* // Create output using json and mustache template // ************************************************************* if (seniorityListJson == "[]") { seniorityListJson = @"{""Empty"": ""true""}"; } HtmlRequest request = new HtmlRequest() { JsonString = seniorityListJson, RenderJsUrl = _configuration.GetSection("Constants").GetSection("RenderJsUrl").Value, Template = _configuration.GetSection("Constants").GetSection("SeniorityListTemplate").Value }; _logger.LogInformation("GetSeniorityListPdf [FileName: {0}] - Render Html", fileName); string result = await TemplateHelper.RenderDocument(_nodeServices, request); _logger.LogInformation("GetSeniorityListPdf [FileName: {0}] - Html Length: {1}", fileName, result.Length); // ************************************************************* // Convert results to Pdf // ************************************************************* PdfRequest pdfRequest = new PdfRequest() { Html = result, RenderJsUrl = _configuration.GetSection("Constants").GetSection("PdfJsUrl").Value, PdfFileName = fileName }; _logger.LogInformation("GetSeniorityListPdf [FileName: {0}] - Gen Pdf", fileName); byte[] pdfResponseBytes = await PdfDocument.BuildPdf(_nodeServices, pdfRequest, true); // convert to string and log string pdfResponse = System.Text.Encoding.Default.GetString(pdfResponseBytes); _logger.LogInformation("GetSeniorityListPdf [FileName: {0}] - Pdf Length: {1}", fileName, pdfResponse.Length); _logger.LogInformation("GetSeniorityListPdf [FileName: {0}] - Done", fileName); return(File(pdfResponseBytes, "application/pdf", fileName)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public IActionResult TestPdf() { PdfRequest pdfRequest = new PdfRequest() { Html = "<h1>Hello World<h1>", PdfFileName = "HelloWorld" }; byte[] pdfResponse = PdfDocument.BuildPdf(_configuration, pdfRequest); return(File(pdfResponse, "application/pdf")); }
public async Task <IActionResult> TestPdf() { PdfRequest pdfRequest = new PdfRequest() { Html = "<h1>Hello World<h1>", RenderJsUrl = _configuration.GetSection("Constants").GetSection("PdfJsUrl").Value, PdfFileName = "HelloWorld" }; byte[] pdfResponse = await PdfDocument.BuildPdf(_nodeServices, pdfRequest); return(File(pdfResponse, "application/pdf")); }
public async Task <IActionResult> TestPdf() { string options = @"{""height"": ""10.5in"",""width"": ""8in"",""orientation"": ""portrait""}"; PdfRequest request = new PdfRequest() { Html = "<h1>Hello World<h1>", Options = options, PdfJsUrl = _configuration.GetSection("Constants").GetSection("PdfJsUrl").Value }; JsonResponse result = await PdfDocument.BuildPdf(_nodeServices, request); return(File(result.Data, "application/pdf")); }
public async Task <IActionResult> TestTemplate() { try { // ************************************************************* // Create output using json and mustache template // ************************************************************* RenderRequest request = new RenderRequest() { JsonString = "{\"title\": \"Sample Template\", \"name\": \"McTesty\"}", RenderJsUrl = _configuration.GetSection("Constants").GetSection("RenderJsUrl").Value, Template = _configuration.GetSection("Constants").GetSection("SampleTemplate").Value }; string result = await TemplateHelper.RenderDocument(_nodeServices, request); // ************************************************************* // Convert results to Pdf // ************************************************************* string options = @"{""height"": ""10.5in"",""width"": ""8in"",""orientation"": ""portrait""}"; PdfRequest pdfRequest = new PdfRequest() { Html = "<h1>" + result + "<h1>", Options = options, PdfJsUrl = _configuration.GetSection("Constants").GetSection("PdfJsUrl").Value }; JsonResponse jsonResult = await PdfDocument.BuildPdf(_nodeServices, pdfRequest); return(File(jsonResult.Data, "application/pdf")); } catch (Exception e) { Console.WriteLine(e); throw; } }