diff --git a/QuestPDF.Previewer/PreviewerUtils.cs b/QuestPDF.Previewer/PreviewerUtils.cs new file mode 100644 index 0000000..7704e2e --- /dev/null +++ b/QuestPDF.Previewer/PreviewerUtils.cs @@ -0,0 +1,43 @@ +using System.Diagnostics; +using Avalonia.Controls; +using QuestPDF.Fluent; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Previewer +{ + internal static class PreviewerUtils + { + public static async Task SavePdfWithDialog(IDocument? document, Window dialogOwner) + { + if (document == null) + return false; + + var dialog = new SaveFileDialog() + { + DefaultExtension = ".pdf", + InitialFileName = document.GetMetadata().Title ?? "Document", + Filters = new List() + { + new FileDialogFilter() + { + Extensions = new List() { "pdf" }, + } + } + }; + + var filePath = await dialog.ShowAsync(dialogOwner); + if (string.IsNullOrWhiteSpace(filePath)) + return false; + + var dirPath = Path.GetDirectoryName(filePath); + + if (!Directory.Exists(dirPath)) + return false; + + //TODO Catch layout exceptions. + document.GeneratePdf(filePath); + Process.Start("explorer.exe", filePath); + return true; + } + } +} diff --git a/QuestPDF.Previewer/PreviewerWindow.axaml b/QuestPDF.Previewer/PreviewerWindow.axaml index 1576066..80bf69c 100644 --- a/QuestPDF.Previewer/PreviewerWindow.axaml +++ b/QuestPDF.Previewer/PreviewerWindow.axaml @@ -23,8 +23,20 @@ - - - + + + + + + + + +