This commit is contained in:
@@ -15,7 +15,7 @@ Here are all the error codes that can be returned by the AyaNova server:
|
||||
| ----- | ------------------------------ |
|
||||
| E1000 | Could not connect to the database specified in the [connection string](ops-config-db.md). |
|
||||
| E1010 | Could not find wwwRoot folder. AyaNova must be started from the folder immediately above wwwRoot. Generally the start folder should be the same folder as AyaNova.dll file. |
|
||||
| E1012 | Missing resource folder. AyaNova was started from the wrong location or the resource folder was not installed properly. This is required to intialize a new AyaNova database |
|
||||
| E1012 | Missing resource folder. AyaNova was started from the wrong location or was not installed properly. |
|
||||
| E1013 | Missing translation resource file was deleted, renamed or not installed correctly. Resource translation files are required to load into a new AyaNova database to display text in several translations for the user interface |
|
||||
| E1015 | Missing translation. One or more of the stock translations were not found in the database or a custom translation specified in the config setting [AYANOVA_DEFAULT_TRANSLATION](ops-config-default-translation.md) is missing from the database. Log will have details. |
|
||||
| E1020 | Licensing related error. The message will contain the explanation |
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -8,6 +9,7 @@ using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Util;
|
||||
|
||||
using PuppeteerSharp;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
@@ -79,16 +81,16 @@ namespace AyaNova.Api.Controllers
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
// byte[] buffer = readfromdatabase();
|
||||
// return new FileContentResult(buffer, "text/html");
|
||||
var ReportJSFolderPath = Path.Combine(ServerBootConfig.AYANOVA_CONTENT_ROOT_PATH, "resource", "reportjs");
|
||||
if (!Directory.Exists(ReportJSFolderPath))
|
||||
throw new System.Exception($"E1012: \"reportjs\" folder not found where expected: \"{ReportJSFolderPath}\", installation damaged?");
|
||||
|
||||
|
||||
var hbspath = Path.Combine(ReportJSFolderPath, "ayhandlebars.js");
|
||||
if (!System.IO.File.Exists(hbspath))
|
||||
throw new System.Exception($"E1012: \"ayhandlebars.js\" file not found where expected: \"{hbspath}\", installation damaged?");
|
||||
|
||||
//first test, just render a web page to pdf and return it
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
|
||||
//http://www.puppeteersharp.com/api/index.html
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||
|
||||
//sample CSS
|
||||
@@ -101,15 +103,29 @@ namespace AyaNova.Api.Controllers
|
||||
margin: 2cm;
|
||||
}";
|
||||
|
||||
//sample HTML
|
||||
var templateHtml = "<div><h1>Hello world!</h1></div>";
|
||||
//sample template
|
||||
var templateHtml = "<div>{{#with person}}{{firstname}} {{lastname}}{{/with}}</div>";
|
||||
|
||||
//data object
|
||||
var jsonData = "{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.AddStyleTagAsync(new AddTagOptions { Content = templateCSS });
|
||||
await page.SetContentAsync(templateHtml);
|
||||
|
||||
//compile into function
|
||||
|
||||
//get result by running hb function against data
|
||||
|
||||
//open page with result
|
||||
|
||||
//pdf-ize and return
|
||||
var pdfBuffer = await page.PdfDataAsync();
|
||||
return new FileContentResult(pdfBuffer, "application/pdf");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user