This commit is contained in:
@@ -91,6 +91,15 @@ public sealed class ProjectLifecycleTests
|
||||
Assert.Contains("mehrfach", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AktuelleAnsicht_KannAlsPdfGerendertWerden()
|
||||
{
|
||||
var pdf = new DesignerViewModel().RenderCurrentPdf();
|
||||
|
||||
Assert.True(pdf.Length > 100);
|
||||
Assert.Equal("%PDF-", System.Text.Encoding.ASCII.GetString(pdf, 0, 5));
|
||||
}
|
||||
|
||||
private static readonly byte[] OnePixelPng = Convert.FromBase64String(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=");
|
||||
}
|
||||
|
||||
@@ -141,6 +141,9 @@ public partial class DesignerViewModel : ObservableObject
|
||||
public ITemplateDataProvider BuildDataProvider() => new DesignerDataProvider(Placeholders.ToDictionary(
|
||||
x => x.Name.Trim(), x => x.ToValue(), StringComparer.Ordinal));
|
||||
|
||||
public byte[] RenderCurrentPdf() =>
|
||||
new QuestTemplateRenderer().RenderToPdf(BuildLoaded(), BuildDataProvider());
|
||||
|
||||
public void ApplyPdfImport(PdfImportResult import)
|
||||
{
|
||||
TemplateId = import.Manifest.Id; TemplateName = import.Manifest.Name; Description = import.Manifest.Description;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<Separator/>
|
||||
<MenuItem Header="Speichern" InputGesture="Ctrl+S" Click="OnSave"/>
|
||||
<MenuItem Header="Speichern unter …" InputGesture="Ctrl+Shift+S" Click="OnSaveAs"/>
|
||||
<MenuItem Header="Aktuelle Ansicht als PDF exportieren …" Click="OnExportCurrentPdf"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Ausgangsvorlage importieren …" Click="OnImportStarterTemplate"/>
|
||||
<Separator/>
|
||||
@@ -204,8 +205,9 @@
|
||||
</TabControl>
|
||||
|
||||
<Grid Grid.Column="1" RowDefinitions="Auto,*" Margin="0,18">
|
||||
<Grid ColumnDefinitions="*,Auto" Margin="12,0,12,10"><TextBlock Text="Layout-DSL" Classes="section"/>
|
||||
<Button Grid.Column="1" Content="Prüfen & Vorschau" Click="OnPreview"/></Grid>
|
||||
<Grid ColumnDefinitions="*,Auto,8,Auto" Margin="12,0,12,10"><TextBlock Text="Layout-DSL" Classes="section"/>
|
||||
<Button Grid.Column="1" Content="Prüfen & Vorschau" Click="OnPreview"/>
|
||||
<Button Grid.Column="3" Content="Als PDF exportieren …" Click="OnExportCurrentPdf"/></Grid>
|
||||
<TabControl Grid.Row="1" Margin="12">
|
||||
<TabItem Header="Seite 1">
|
||||
<TextBox Text="{Binding LayoutSource}" AcceptsReturn="True" TextWrapping="NoWrap"
|
||||
|
||||
@@ -267,6 +267,40 @@ public partial class MainWindow : Window
|
||||
|
||||
private async void OnSaveAs(object? sender, RoutedEventArgs e) => await SaveAsAsync();
|
||||
|
||||
private async void OnExportCurrentPdf(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
byte[] pdf;
|
||||
try
|
||||
{
|
||||
pdf = _viewModel.RenderCurrentPdf();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_viewModel.SetStatus($"PDF-Export fehlgeschlagen: {ex.Message}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var file = await StorageProvider.SaveFilePickerAsync(new()
|
||||
{
|
||||
Title = "Aktuelle Vorlagenansicht als PDF exportieren",
|
||||
SuggestedFileName = _viewModel.TemplateId + "-vorschau.pdf",
|
||||
DefaultExtension = "pdf",
|
||||
FileTypeChoices = [new("PDF-Dateien") { Patterns = ["*.pdf"] }],
|
||||
});
|
||||
if (file is null) return;
|
||||
|
||||
try
|
||||
{
|
||||
var destination = EnsurePdfExtension(file.Path.LocalPath);
|
||||
await File.WriteAllBytesAsync(destination, pdf);
|
||||
_viewModel.SetStatus($"PDF-Vorschau exportiert: {Path.GetFileName(destination)}", false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_viewModel.SetStatus($"PDF-Export fehlgeschlagen: {ex.Message}", true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsAsync()
|
||||
{
|
||||
try { _viewModel.BuildLoaded(); }
|
||||
@@ -332,6 +366,9 @@ public partial class MainWindow : Window
|
||||
private static string EnsurePackageExtension(string path) =>
|
||||
string.Equals(Path.GetExtension(path), TemplatePackage.Extension, StringComparison.OrdinalIgnoreCase)
|
||||
? path : path + TemplatePackage.Extension;
|
||||
private static string EnsurePdfExtension(string path) =>
|
||||
string.Equals(Path.GetExtension(path), ".pdf", StringComparison.OrdinalIgnoreCase)
|
||||
? path : path + ".pdf";
|
||||
private void RefreshStarterTemplates(string? selectedId = null) =>
|
||||
_viewModel.SetStarterTemplates(_starterTemplates.GetAll(), selectedId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user