Add Print/

This commit is contained in:
2023-03-05 00:16:47 +01:00
parent d12266abbb
commit 6b8bd3ca00
7 changed files with 84 additions and 0 deletions

34
WGneu/Print/Pdf.cs Normal file
View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using PuppeteerSharp;
namespace WGneu.Print {
public static class Pdf {
private static readonly string CHROMIUM = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
private static IBrowser? Browser = null;
public static async void Init() {
Browser = await Puppeteer.LaunchAsync(new LaunchOptions {
Headless = true,
ExecutablePath = CHROMIUM,
});
}
public static async Task Convert(string path_html, string path_pdf) {
if (Browser == null)
Init();
using var page = await Browser?.NewPageAsync();
await page.GoToAsync("file://" + path_html);
await page.WaitForFunctionAsync("() => window.finished");
await page.PdfAsync(path_pdf);
}
}
}