56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using Elwig.Windows;
|
|
using System;
|
|
using System.Drawing.Printing;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace Elwig.Helpers.Printing {
|
|
public static class Pdf {
|
|
|
|
public static Task Init(Action? evtHandler = null) {
|
|
PdfiumNative.FPDF_InitLibrary();
|
|
evtHandler?.Invoke();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public static Task Cleanup() {
|
|
PdfiumNative.FPDF_DestroyLibrary();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public static void Show(TempFile file, string title) {
|
|
App.MainDispatcher.BeginInvoke(() => {
|
|
var w = new DocumentViewerWindow(title, file);
|
|
w.Show();
|
|
});
|
|
}
|
|
|
|
public static void Show(string path, string title) {
|
|
App.MainDispatcher.BeginInvoke(() => {
|
|
var w = new DocumentViewerWindow(title, path);
|
|
w.Show();
|
|
});
|
|
}
|
|
|
|
public static async Task Print(string path, int copies = 1, bool doublePaged = false) {
|
|
await Print(path, new() {
|
|
Copies = (short)copies,
|
|
Collate = true,
|
|
Duplex = doublePaged ? Duplex.Vertical : Duplex.Simplex,
|
|
});
|
|
}
|
|
|
|
public static Task Print(string path, PrinterSettings settings) {
|
|
try {
|
|
using var printDoc = new PdfPrintDocument(path) {
|
|
PrinterSettings = settings,
|
|
};
|
|
printDoc.Print();
|
|
} catch (Exception e) {
|
|
MessageBox.Show("Beim Drucken ist ein Fehler aufgetreten:\n\n" + e.Message, "Fehler beim Drucken", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|