diff --git a/WGneu/Documents/Pdf.cs b/WGneu/Documents/Pdf.cs
new file mode 100644
index 0000000..2cf0dd3
--- /dev/null
+++ b/WGneu/Documents/Pdf.cs
@@ -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();
+ }
+ }
+}
diff --git a/WGneu/Print/Template.cs b/WGneu/Documents/Template.cs
similarity index 80%
rename from WGneu/Print/Template.cs
rename to WGneu/Documents/Template.cs
index 5839466..abeca76 100644
--- a/WGneu/Print/Template.cs
+++ b/WGneu/Documents/Template.cs
@@ -5,14 +5,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace WGneu.Print {
+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(ROOT + "test.pdf");
+ Pdf.Display("Test-Dokument", ROOT + "test.pdf");
}
}
}
diff --git a/WGneu/Print/TestTemplate.cs b/WGneu/Documents/TestTemplate.cs
similarity index 85%
rename from WGneu/Print/TestTemplate.cs
rename to WGneu/Documents/TestTemplate.cs
index 142ddc4..2ac41f3 100644
--- a/WGneu/Print/TestTemplate.cs
+++ b/WGneu/Documents/TestTemplate.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace WGneu.Print {
+namespace WGneu.Documents {
internal class TestTemplate {
}
}
diff --git a/WGneu/Print/TestTemplate.cshtml b/WGneu/Documents/TestTemplate.cshtml
similarity index 100%
rename from WGneu/Print/TestTemplate.cshtml
rename to WGneu/Documents/TestTemplate.cshtml
diff --git a/WGneu/Print/Pdf.cs b/WGneu/Print/Pdf.cs
deleted file mode 100644
index a942662..0000000
--- a/WGneu/Print/Pdf.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-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 Task 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)
- await Init();
-
- using var page = await Browser?.NewPageAsync();
- await page.GoToAsync("file://" + path_html);
- await page.WaitForFunctionAsync("() => window.finished");
- await page.PdfAsync(path_pdf);
- }
-
- public static void Display(string path) {
- Process.Start(new ProcessStartInfo() {
- FileName = path,
- UseShellExecute = true,
- });
- }
- }
-}
diff --git a/WGneu/WGneu.csproj b/WGneu/WGneu.csproj
index 1c297db..8a8806f 100644
--- a/WGneu/WGneu.csproj
+++ b/WGneu/WGneu.csproj
@@ -13,6 +13,7 @@
+
diff --git a/WGneu/WGneu.csproj.user b/WGneu/WGneu.csproj.user
index aa8338a..7ab7934 100644
--- a/WGneu/WGneu.csproj.user
+++ b/WGneu/WGneu.csproj.user
@@ -13,6 +13,9 @@
Code
+
+ Code
+
@@ -24,5 +27,8 @@
Designer
+
+ Designer
+
\ No newline at end of file
diff --git a/WGneu/Windows/MainWindow.xaml.cs b/WGneu/Windows/MainWindow.xaml.cs
index cb49f53..7392762 100644
--- a/WGneu/Windows/MainWindow.xaml.cs
+++ b/WGneu/Windows/MainWindow.xaml.cs
@@ -19,9 +19,6 @@ using WGneu.Models;
namespace WGneu.Windows {
- ///
- /// Interaction logic for MainWindow.xaml
- ///
public partial class MainWindow : Window {
private readonly WgContext _context = new WgContext();
private CollectionViewSource countryViewSource;
@@ -32,7 +29,7 @@ namespace WGneu.Windows {
private void Window_Loaded(object sender, RoutedEventArgs e) {
_context.Countries.Load();
- Print.Pdf.Init();
+ Documents.Pdf.Init();
countryViewSource.Source = _context.Countries.Local.ToObservableCollection();
}
@@ -47,7 +44,7 @@ namespace WGneu.Windows {
}
private void Button3_Click(object sender, EventArgs e) {
- Print.Template.Test();
+ Documents.Template.Test();
}
private void Button_Click(object sender, RoutedEventArgs e) {
diff --git a/WGneu/Windows/PdfViewerWindow.xaml b/WGneu/Windows/PdfViewerWindow.xaml
new file mode 100644
index 0000000..899eaf9
--- /dev/null
+++ b/WGneu/Windows/PdfViewerWindow.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
diff --git a/WGneu/Windows/PdfViewerWindow.xaml.cs b/WGneu/Windows/PdfViewerWindow.xaml.cs
new file mode 100644
index 0000000..74172eb
--- /dev/null
+++ b/WGneu/Windows/PdfViewerWindow.xaml.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace WGneu.Windows {
+ public partial class PdfViewerWindow : Window {
+ public PdfViewerWindow(string title, string path) {
+ InitializeComponent();
+ Title = Title + " - " + title;
+ WebView.Source = new("file://" + path);
+ }
+ }
+}