This commit is contained in:
@@ -104,26 +104,32 @@ namespace AyaNova.Api.Controllers
|
||||
}";
|
||||
|
||||
//sample template
|
||||
var templateHtml = "<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>";
|
||||
var templateHtml = "'<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>'";
|
||||
|
||||
//data object
|
||||
var jsonData = "{person: {firstname: \"Yehuda\",lastname: \"Katz\",}}";
|
||||
|
||||
var dat="{ person: { firstname: 'Yehuda', lastname: 'Katz' } }";
|
||||
|
||||
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
|
||||
using (var page = await browser.NewPageAsync())
|
||||
{
|
||||
//Add handlebars JS for compiling and presenting
|
||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath});
|
||||
await page.AddScriptTagAsync(new AddTagOptions() { Path = hbspath });
|
||||
|
||||
await page.AddStyleTagAsync(new AddTagOptions { Content = templateCSS });
|
||||
await page.SetContentAsync(templateHtml);
|
||||
//script
|
||||
//var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat})";
|
||||
var theScript = $"let fun=Handlebars.compile({templateHtml});fun({dat});";
|
||||
|
||||
//compile into function
|
||||
|
||||
//get result by running hb function against data
|
||||
//COMPILE into function
|
||||
|
||||
var f3 = await page.EvaluateExpressionAsync<string>(theScript);
|
||||
|
||||
//get result by running hb function against data
|
||||
// string html = await page.EvaluateExpressionAsync<string>(sfunc);
|
||||
|
||||
//open page with result
|
||||
// await page.AddStyleTagAsync(new AddTagOptions { Content = templateCSS });
|
||||
// await page.SetContentAsync(templateHtml);
|
||||
|
||||
//pdf-ize and return
|
||||
var pdfBuffer = await page.PdfDataAsync();
|
||||
|
||||
Reference in New Issue
Block a user