Using Html/Pdf Initializer
This commit is contained in:
@ -16,35 +16,19 @@ namespace WGneu.Documents {
|
||||
public static class Pdf {
|
||||
|
||||
private static readonly string CHROMIUM = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
|
||||
private static IBrowser? _Browser = null;
|
||||
private static RazorLightEngine? _Engine = null;
|
||||
private static IBrowser? Browser = null;
|
||||
public static bool IsReady => Browser != null;
|
||||
|
||||
public static void Init() {
|
||||
var b = Browser;
|
||||
var e = Engine;
|
||||
}
|
||||
|
||||
private static IBrowser Browser {
|
||||
get {
|
||||
_Browser ??= Puppeteer.LaunchAsync(new LaunchOptions {
|
||||
Headless = true,
|
||||
ExecutablePath = CHROMIUM,
|
||||
}).GetAwaiter().GetResult();
|
||||
return _Browser;
|
||||
}
|
||||
}
|
||||
|
||||
private static RazorLightEngine Engine {
|
||||
get {
|
||||
_Engine ??= new RazorLightEngineBuilder()
|
||||
.UseFileSystemProject(@"C:\Users\Lorenz\source\repos\WGneu\WGneu\Documents")
|
||||
.UseMemoryCachingProvider()
|
||||
.Build();
|
||||
return _Engine;
|
||||
}
|
||||
public static async Task Init(Action evtHandler) {
|
||||
Browser = await Puppeteer.LaunchAsync(new LaunchOptions {
|
||||
Headless = true,
|
||||
ExecutablePath = CHROMIUM,
|
||||
});
|
||||
evtHandler();
|
||||
}
|
||||
|
||||
public static async Task Convert(string path_html, string path_pdf) {
|
||||
if (Browser == null) throw new InvalidOperationException("The puppeteer engine has not been initialized yet");
|
||||
using var page = await Browser.NewPageAsync();
|
||||
await page.GoToAsync("file://" + path_html);
|
||||
await page.WaitForFunctionAsync("() => window.finished");
|
||||
@ -68,13 +52,13 @@ namespace WGneu.Documents {
|
||||
doc.Save(path);
|
||||
}
|
||||
|
||||
public static void Display(string title, string path) {
|
||||
public static void Show(string path, string title) {
|
||||
var w = new DocumentViewerWindow(title, path);
|
||||
w.Show();
|
||||
}
|
||||
|
||||
public static async Task<string> CompileRenderAsync(string key, object model) {
|
||||
return await Engine.CompileRenderAsync(key, model);
|
||||
public static void Print(string path) {
|
||||
// TODO print pdf
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user