This commit is contained in:
@@ -74,9 +74,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
[HttpGet("render")]
|
[HttpGet("poc")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IActionResult> GetPdfReport([FromRoute] string url)
|
public async Task<IActionResult> ProofOfConcept([FromRoute] string url)
|
||||||
{
|
{
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -101,10 +101,20 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
@page :first {
|
@page :first {
|
||||||
margin: 2cm;
|
margin: 2cm;
|
||||||
}";
|
}
|
||||||
|
|
||||||
|
.ay-red {
|
||||||
|
color:red;
|
||||||
|
}
|
||||||
|
.ay-blue {
|
||||||
|
color:blue;
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
//sample template
|
//sample template
|
||||||
var reportTemplate = "'<div>{{#with person}}{{firstname}} {{aycaps lastname}}{{/with}}</div>'";
|
//var reportTemplate = "'<div>{{#with person}}<span class=\"ay-red\">{{firstname}}</span> {{aycaps lastname}}{{/with}}</div>'";
|
||||||
|
var reportTemplate = "'<!DOCTYPE html><html><head><title>test title</title></head><body><h1>Test page top</h1><p class=\"ay-blue\">A blue paragraph</p><div>{{#with person}}<span class=\"ay-red\">{{firstname}}</span> {{aycaps lastname}}{{/with}}</div></body></html>'";
|
||||||
|
|
||||||
//data object
|
//data object
|
||||||
var reportData = "{ person: { firstname: 'Tyler', lastname: 'Mott' } }";
|
var reportData = "{ person: { firstname: 'Tyler', lastname: 'Mott' } }";
|
||||||
|
|
||||||
@@ -116,6 +126,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
//test add helpers
|
//test add helpers
|
||||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb-helpers.js") });
|
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb-helpers.js") });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//execute to add to handlebars
|
//execute to add to handlebars
|
||||||
await page.EvaluateExpressionAsync("ayRegisterHelpers();");
|
await page.EvaluateExpressionAsync("ayRegisterHelpers();");
|
||||||
|
|
||||||
@@ -124,9 +137,14 @@ namespace AyaNova.Api.Controllers
|
|||||||
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
var resultHTML = await page.EvaluateExpressionAsync<string>(compileScript);
|
||||||
|
|
||||||
//render report as HTML
|
//render report as HTML
|
||||||
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
|
||||||
await page.SetContentAsync(resultHTML);
|
await page.SetContentAsync(resultHTML);
|
||||||
|
|
||||||
|
//add style (after page or it won't work)
|
||||||
|
await page.AddStyleTagAsync(new AddTagOptions { Content = reportCSS });
|
||||||
|
|
||||||
|
//useful for debugging purposes only
|
||||||
|
//var pagecontent = await page.GetContentAsync();
|
||||||
|
|
||||||
//render to pdf and return
|
//render to pdf and return
|
||||||
var pdfBuffer = await page.PdfDataAsync();
|
var pdfBuffer = await page.PdfDataAsync();
|
||||||
return new FileContentResult(pdfBuffer, "application/pdf");
|
return new FileContentResult(pdfBuffer, "application/pdf");
|
||||||
|
|||||||
Reference in New Issue
Block a user