Add Print/
This commit is contained in:
34
WGneu/Print/Pdf.cs
Normal file
34
WGneu/Print/Pdf.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user