Renamed Print/ to Documents/
This commit is contained in:
55
WGneu/Documents/Pdf.cs
Normal file
55
WGneu/Documents/Pdf.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PuppeteerSharp;
|
||||
using PuppeteerSharp.Media;
|
||||
using WGneu.Windows;
|
||||
|
||||
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;
|
||||
|
||||
public static void Init() {
|
||||
var b = Browser;
|
||||
}
|
||||
|
||||
private static IBrowser Browser {
|
||||
get {
|
||||
_Browser ??= Puppeteer.LaunchAsync(new LaunchOptions {
|
||||
Headless = true,
|
||||
ExecutablePath = CHROMIUM,
|
||||
}).GetAwaiter().GetResult();
|
||||
return _Browser;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task Convert(string path_html, string path_pdf) {
|
||||
using var page = await Browser.NewPageAsync();
|
||||
await page.GoToAsync("file://" + path_html);
|
||||
await page.WaitForFunctionAsync("() => window.finished");
|
||||
await page.PdfAsync(path_pdf, new() {
|
||||
PreferCSSPageSize = true,
|
||||
//Format = PaperFormat.A4,
|
||||
DisplayHeaderFooter = false,
|
||||
MarginOptions = new() {
|
||||
Top = "0mm",
|
||||
Right = "0mm",
|
||||
Bottom = "0mm",
|
||||
Left = "0mm",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public static void Display(string title, string path) {
|
||||
var w = new PdfViewerWindow(title, path);
|
||||
w.Show();
|
||||
}
|
||||
}
|
||||
}
|
18
WGneu/Documents/Template.cs
Normal file
18
WGneu/Documents/Template.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Documents {
|
||||
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");
|
||||
Pdf.Display("Test-Dokument", ROOT + "test.pdf");
|
||||
}
|
||||
}
|
||||
}
|
10
WGneu/Documents/TestTemplate.cs
Normal file
10
WGneu/Documents/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.Documents {
|
||||
internal class TestTemplate {
|
||||
}
|
||||
}
|
9
WGneu/Documents/TestTemplate.cshtml
Normal file
9
WGneu/Documents/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