diff --git a/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml b/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml
index 0cd521a..dbf9a2d 100644
--- a/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml
+++ b/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml
@@ -24,6 +24,8 @@
+
diff --git a/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs b/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs
index ba0764b..071c08a 100644
--- a/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs
+++ b/Elwig/Dialogs/DeliveryConfirmationsDialog.xaml.cs
@@ -93,8 +93,10 @@ namespace Elwig.Dialogs {
""")
.ToListAsync();
- using var doc = await Document.Merge(list.Select(m => new DeliveryConfirmation(Context, Year, m, deliveries.Where(d => d.Delivery.MgNr == m.MgNr)))); ;
- await doc.Generate();
+ using var doc = Document.Merge(list.Select(m => new DeliveryConfirmation(Context, Year, m, deliveries.Where(d => d.Delivery.MgNr == m.MgNr)))); ;
+ await doc.Generate(new Progress(v => {
+ ProgressBar.Value = v;
+ }));
Mouse.OverrideCursor = null;
if (mode < 2) {
diff --git a/Elwig/Documents/Document.cshtml.cs b/Elwig/Documents/Document.cshtml.cs
index 3cbff9f..ab2a5ca 100644
--- a/Elwig/Documents/Document.cshtml.cs
+++ b/Elwig/Documents/Document.cshtml.cs
@@ -47,7 +47,7 @@ namespace Elwig.Documents {
GC.SuppressFinalize(this);
}
- public static async Task Merge(IEnumerable docs) {
+ public static Document Merge(IEnumerable docs) {
return new MergedDocument(docs);
}
@@ -75,17 +75,21 @@ namespace Elwig.Documents {
return await Html.CompileRenderAsync(name, this); ;
}
- public async Task Generate() {
+ public async Task Generate(IProgress? progress = null) {
+ progress?.Report(0.0);
if (this is MergedDocument m) {
var pdf = new TempFile("pdf");
var tmpHtmls = new List();
+ var n = 0;
foreach (var doc in m.Documents) {
var tmpHtml = new TempFile("html");
- await doc.Render();
await File.WriteAllTextAsync(tmpHtml.FilePath, await doc.Render(), Utils.UTF8);
tmpHtmls.Add(tmpHtml);
+ n++;
+ progress?.Report(50.0 * n / m.Documents.Count());
}
- await Pdf.Convert(tmpHtmls.Select(f => f.FilePath), pdf.FilePath);
+ progress?.Report(50.0);
+ await Pdf.Convert(tmpHtmls.Select(f => f.FilePath), pdf.FilePath, new Progress(v => progress?.Report(50.0 + v / 2)));
foreach (var tmp in tmpHtmls) {
tmp.Dispose();
}
@@ -94,10 +98,12 @@ namespace Elwig.Documents {
var pdf = new TempFile("pdf");
using (var tmpHtml = new TempFile("html")) {
await File.WriteAllTextAsync(tmpHtml.FilePath, await Render(), Utils.UTF8);
+ progress?.Report(50.0);
await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath);
}
_pdfFile = pdf;
}
+ progress?.Report(100.0);
}
public void SaveTo(string pdfPath) {
diff --git a/Elwig/Documents/Pdf.cs b/Elwig/Documents/Pdf.cs
index fc7f07c..3eb704a 100644
--- a/Elwig/Documents/Pdf.cs
+++ b/Elwig/Documents/Pdf.cs
@@ -21,7 +21,7 @@ namespace Elwig.Documents {
public static async Task Init(Action evtHandler) {
var p = new Process() { StartInfo = new() {
FileName = WinziPrint,
- Arguments = "-",
+ Arguments = $"-p -e utf-8 -d '{App.TempPath}' -",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardInput = true,
@@ -32,20 +32,27 @@ namespace Elwig.Documents {
evtHandler();
}
- public static async Task> Convert(string htmlPath, string pdfPath) {
- return await Convert(new string[] { htmlPath }, pdfPath);
+ public static async Task> Convert(string htmlPath, string pdfPath, IProgress? progress = null) {
+ return await Convert(new string[] { htmlPath }, pdfPath, progress);
}
- public static async Task> Convert(IEnumerable htmlPath, string pdfPath) {
+ public static async Task> Convert(IEnumerable htmlPath, string pdfPath, IProgress? progress = null) {
if (WinziPrintProc == null) throw new InvalidOperationException("The WinziPrint process has not been initialized yet");
+ progress?.Report(0.0);
await WinziPrintProc.StandardInput.WriteLineAsync($"{string.Join(';', htmlPath)};{pdfPath}");
- var line = await WinziPrintProc.StandardOutput.ReadLineAsync() ?? throw new IOException("Invalid response from WinziPrint");
- if (line.StartsWith("error:")) {
- MessageBox.Show(line[6..].Trim(), "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
- return Array.Empty();
+ while (true) {
+ var line = await WinziPrintProc.StandardOutput.ReadLineAsync() ?? throw new IOException("Invalid response from WinziPrint");
+ if (line.StartsWith("error:")) {
+ MessageBox.Show(line[6..].Trim(), "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
+ return Array.Empty();
+ } else if (line.StartsWith("progress:")) {
+ var parts = line[9..].Trim().Split('/').Select(int.Parse).ToArray();
+ progress?.Report(parts[0] / (double)parts[1]);
+ } else if (line.StartsWith("success:")) {
+ var m = Regex.Match(line, @"\(([0-9, ]+)\)");
+ return m.Groups[1].Value.Split(", ").Select(n => int.Parse(n));
+ }
}
- var m = Regex.Match(line, @"\(([0-9, ]+)\)");
- return m.Groups[1].Value.Split(", ").Select(n => int.Parse(n));
}
public static void Show(TempFile file, string title) {
diff --git a/Elwig/Windows/MemberAdminWindow.xaml.cs b/Elwig/Windows/MemberAdminWindow.xaml.cs
index 353ba54..9bfbae3 100644
--- a/Elwig/Windows/MemberAdminWindow.xaml.cs
+++ b/Elwig/Windows/MemberAdminWindow.xaml.cs
@@ -317,7 +317,7 @@ namespace Elwig.Windows {
.ThenBy(m => m.MgNr);
break;
}
- using var doc = await Document.Merge((await members.ToListAsync()).Select(m => new Letterhead(m)));
+ using var doc = Document.Merge((await members.ToListAsync()).Select(m => new Letterhead(m)));
await doc.Generate();
Mouse.OverrideCursor = null;
if (App.Config.Debug) {