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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Print {
|
||||
namespace WGneu.Documents {
|
||||
internal class TestTemplate {
|
||||
}
|
||||
}
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.14" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1587.40" />
|
||||
<PackageReference Include="ModernWpfUI" Version="0.9.6" />
|
||||
<PackageReference Include="PuppeteerSharp" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
@ -13,6 +13,9 @@
|
||||
<Compile Update="Windows\DeliveryReceptionWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Windows\PdfViewerWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Windows\MainWindow.xaml">
|
||||
@ -24,5 +27,8 @@
|
||||
<Page Update="Windows\DeliveryReceptionWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Windows\PdfViewerWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -19,9 +19,6 @@ using WGneu.Models;
|
||||
|
||||
|
||||
namespace WGneu.Windows {
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
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) {
|
||||
|
14
WGneu/Windows/PdfViewerWindow.xaml
Normal file
14
WGneu/Windows/PdfViewerWindow.xaml
Normal file
@ -0,0 +1,14 @@
|
||||
<Window x:Class="WGneu.Windows.PdfViewerWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
|
||||
xmlns:local="clr-namespace:WGneu.Windows"
|
||||
mc:Ignorable="d"
|
||||
Title="PDF Ansicht"
|
||||
MinHeight="600" MinWidth="420" Height="600" Width="420">
|
||||
<Grid>
|
||||
<wv2:WebView2 Name="WebView"/>
|
||||
</Grid>
|
||||
</Window>
|
23
WGneu/Windows/PdfViewerWindow.xaml.cs
Normal file
23
WGneu/Windows/PdfViewerWindow.xaml.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user