diff --git a/Elwig/Documents/Document.cs b/Elwig/Documents/Document.cs index b6b65b3..3a8b897 100644 --- a/Elwig/Documents/Document.cs +++ b/Elwig/Documents/Document.cs @@ -16,6 +16,8 @@ namespace Elwig.Documents { protected TempFile? _pdfFile = null; protected string? _pdfPath; protected string? PdfPath => _pdfPath ?? _pdfFile?.FilePath; + public int? TotalPages { get; private set; } + public int? Pages => TotalPages / (DoubleSided ? 2 : 1); public bool ShowFoldMarks = App.Config.Debug; public bool DoubleSided = false; @@ -114,7 +116,8 @@ namespace Elwig.Documents { progress?.Report(GenerationProportion * 100 * i / n); } progress?.Report(GenerationProportion * 100); - await Pdf.Convert(tmpFiles, pdf.FileName, DoubleSided, new Progress(v => progress?.Report(GenerationProportion * 100 + v * (1 - GenerationProportion)))); + var pages = await Pdf.Convert(tmpFiles, pdf.FileName, DoubleSided, new Progress(v => progress?.Report(GenerationProportion * 100 + v * (1 - GenerationProportion)))); + TotalPages = pages.Pages; foreach (var tmp in tmpHtmls) { tmp.Dispose(); } @@ -124,7 +127,8 @@ namespace Elwig.Documents { 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, DoubleSided); + var pages = await Pdf.Convert(tmpHtml.FilePath, pdf.FilePath, DoubleSided); + TotalPages = pages.Pages; } _pdfFile = pdf; } diff --git a/Elwig/Helpers/Printing/Pdf.cs b/Elwig/Helpers/Printing/Pdf.cs index 3379c75..1bf3992 100644 --- a/Elwig/Helpers/Printing/Pdf.cs +++ b/Elwig/Helpers/Printing/Pdf.cs @@ -49,11 +49,11 @@ namespace Elwig.Helpers.Printing { return Task.CompletedTask; } - public static async Task> Convert(string htmlPath, string pdfPath, bool doubleSided = false, IProgress? progress = null) { + public static async Task<(int Pages, IEnumerable PerDoc)> Convert(string htmlPath, string pdfPath, bool doubleSided = false, IProgress? progress = null) { return await Convert([htmlPath], pdfPath, doubleSided, progress); } - public static async Task> Convert(IEnumerable htmlPath, string pdfPath, bool doubleSided = false, IProgress? progress = null) { + public static async Task<(int Pages, IEnumerable PerDoc)> Convert(IEnumerable htmlPath, string pdfPath, bool doubleSided = false, IProgress? progress = null) { if (WinziPrintProc == null) throw new InvalidOperationException("The WinziPrint process has not been initialized yet"); progress?.Report(0.0); using var client = new TcpClient("127.0.0.1", 30983); @@ -71,8 +71,8 @@ namespace Elwig.Helpers.Printing { var parts = line[9..].Trim().Split('/').Select(int.Parse).ToArray(); progress?.Report(100.0 * parts[0] / parts[1]); } else if (line.StartsWith("success:")) { - var m = Regex.Match(line, @"\(([0-9, ]+)\)"); - return m.Groups[1].Value.Split(", ").Select(int.Parse).ToList(); + var m = Regex.Match(line, @"([0-9]+) pages \(([0-9, ]+)\)"); + return (int.Parse(m.Groups[1].Value), m.Groups[2].Value.Split(", ").Select(int.Parse).ToList()); } } } diff --git a/Elwig/Windows/MailWindow.xaml b/Elwig/Windows/MailWindow.xaml index ef8450d..6c4df28 100644 --- a/Elwig/Windows/MailWindow.xaml +++ b/Elwig/Windows/MailWindow.xaml @@ -249,9 +249,11 @@ Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="3" FontSize="14" Click="PreviewButton_Click"/>