Add Print/

This commit is contained in:
2023-03-05 00:16:47 +01:00
parent d12266abbb
commit 6b8bd3ca00
7 changed files with 84 additions and 0 deletions

34
WGneu/Print/Pdf.cs Normal file
View 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
View 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,
});
}
}
}

View 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 {
}
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="de-AT">
<head>
<title>Test Document</title>
</head>
<body>
<h1>Test Document</h1>
</body>
</html>

View File

@ -8,9 +8,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="6.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.3" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="ModernWpfUI" Version="0.9.6" /> <PackageReference Include="ModernWpfUI" Version="0.9.6" />
<PackageReference Include="PuppeteerSharp" Version="9.0.2" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -18,5 +18,6 @@
<Grid> <Grid>
<ComboBox HorizontalAlignment="Left" Margin="175,149,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Source={StaticResource countryViewSource}}" ItemTemplate="{StaticResource asdf}" SelectionChanged="ComboBox_SelectionChanged" IsEditable="True"/> <ComboBox HorizontalAlignment="Left" Margin="175,149,0,0" VerticalAlignment="Top" Width="120" ItemsSource="{Binding Source={StaticResource countryViewSource}}" ItemTemplate="{StaticResource asdf}" SelectionChanged="ComboBox_SelectionChanged" IsEditable="True"/>
<Button x:Name="Button2" Content="Mitglieder" Margin="472,182,178,0" VerticalAlignment="Top" Click="Button2_Click"/> <Button x:Name="Button2" Content="Mitglieder" Margin="472,182,178,0" VerticalAlignment="Top" Click="Button2_Click"/>
<Button x:Name="Button3" Content="Print" Margin="425,255,225,0" VerticalAlignment="Top" Click="Button3_Click"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -32,6 +32,7 @@ namespace WGneu.Windows {
private void Window_Loaded(object sender, RoutedEventArgs e) { private void Window_Loaded(object sender, RoutedEventArgs e) {
_context.Countries.Load(); _context.Countries.Load();
Print.Pdf.Init();
countryViewSource.Source = _context.Countries.Local.ToObservableCollection(); countryViewSource.Source = _context.Countries.Local.ToObservableCollection();
} }
@ -45,6 +46,10 @@ namespace WGneu.Windows {
w.Show(); w.Show();
} }
private void Button3_Click(object sender, EventArgs e) {
Print.Template.Test();
}
private void Button_Click(object sender, RoutedEventArgs e) { private void Button_Click(object sender, RoutedEventArgs e) {
} }