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);
|
||||
}
|
||||
}
|
||||
}
|
21
WGneu/Print/Template.cs
Normal file
21
WGneu/Print/Template.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Print {
|
||||
class Template {
|
||||
|
||||
private static readonly string ROOT = @"C:\Users\Lorenz\Desktop\";
|
||||
|
||||
public static async void Test() {
|
||||
await Pdf.Convert(ROOT + "din-5008.html", ROOT + "test.pdf");
|
||||
Process.Start(new ProcessStartInfo() {
|
||||
FileName = ROOT + "test.pdf",
|
||||
UseShellExecute = true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
10
WGneu/Print/TestTemplate.cs
Normal file
10
WGneu/Print/TestTemplate.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Print {
|
||||
internal class TestTemplate {
|
||||
}
|
||||
}
|
9
WGneu/Print/TestTemplate.cshtml
Normal file
9
WGneu/Print/TestTemplate.cshtml
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de-AT">
|
||||
<head>
|
||||
<title>Test Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test Document</h1>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user