Tests: Add tests for documents

This commit is contained in:
2024-02-13 12:38:37 +01:00
parent 912206f52d
commit 805f782c83
10 changed files with 136 additions and 13 deletions

View File

@ -11,13 +11,20 @@ using System.Linq;
namespace Elwig.Helpers.Printing {
public static class Pdf {
private static readonly string PdfToPrinter = App.ExePath + "PDFtoPrinter.exe";
private static readonly string WinziPrint = App.ExePath + "WinziPrint.exe";
private static readonly string PdfToPrinter = new string[] { App.ExePath }
.Union(Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? [])
.Select(x => Path.Combine(x, "PDFtoPrinter.exe"))
.Where(x => File.Exists(x))
.FirstOrDefault() ?? throw new FileNotFoundException("PDFtoPrinter executable not found");
private static readonly string WinziPrint = new string[] { App.ExePath }
.Union(Environment.GetEnvironmentVariable("PATH")?.Split(';') ?? [])
.Select(x => Path.Combine(x, "WinziPrint.exe"))
.Where(x => File.Exists(x))
.FirstOrDefault() ?? throw new FileNotFoundException("WiniPrint executable not found");
private static Process? WinziPrintProc;
public static bool IsReady => WinziPrintProc != null;
public static async Task Init(Action evtHandler) {
public static async Task Init(Action? evtHandler = null) {
var p = new Process() { StartInfo = new() {
FileName = WinziPrint,
CreateNoWindow = true,
@ -33,7 +40,7 @@ namespace Elwig.Helpers.Printing {
p.StartInfo.ArgumentList.Add("-");
p.Start();
WinziPrintProc = p;
evtHandler();
evtHandler?.Invoke();
}
public static async Task<IEnumerable<int>> Convert(string htmlPath, string pdfPath, bool doubleSided = false, IProgress<double>? progress = null) {