Documents/Pdf: Add progress tracker
This commit is contained in:
@ -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<IEnumerable<int>> Convert(string htmlPath, string pdfPath) {
|
||||
return await Convert(new string[] { htmlPath }, pdfPath);
|
||||
public static async Task<IEnumerable<int>> Convert(string htmlPath, string pdfPath, IProgress<double>? progress = null) {
|
||||
return await Convert(new string[] { htmlPath }, pdfPath, progress);
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<int>> Convert(IEnumerable<string> htmlPath, string pdfPath) {
|
||||
public static async Task<IEnumerable<int>> Convert(IEnumerable<string> htmlPath, string pdfPath, IProgress<double>? 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<int>();
|
||||
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<int>();
|
||||
} 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) {
|
||||
|
Reference in New Issue
Block a user