WIP: Add iOS version #10
@@ -85,15 +85,6 @@ class ReportPDFCreator : ChangeNotifier
|
|||||||
// https://forum.pdfsharp.net/viewtopic.php?f=2&t=1025
|
// https://forum.pdfsharp.net/viewtopic.php?f=2&t=1025
|
||||||
public async Task<string?> CreatePDF(List<ReportFile> reportFiles, string reportTitle, string outputFolderPath, PDFFontResolver fontResolver, Settings appSettings)
|
public async Task<string?> CreatePDF(List<ReportFile> reportFiles, string reportTitle, string outputFolderPath, PDFFontResolver fontResolver, Settings appSettings)
|
||||||
{
|
{
|
||||||
// safety checks
|
|
||||||
var outputDir = appSettings.PDFOutputSaveLocation == Enums.PDFSaveLocation.BaseFolder
|
|
||||||
? outputFolderPath
|
|
||||||
: appSettings.OutputPdfDir; // TODO: adjust for new logic
|
|
||||||
if (!Directory.Exists(outputDir))
|
|
||||||
{
|
|
||||||
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// setup globals and consts...
|
// setup globals and consts...
|
||||||
GlobalFontSettings.FontResolver = fontResolver;
|
GlobalFontSettings.FontResolver = fontResolver;
|
||||||
GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver();
|
GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver();
|
||||||
@@ -403,7 +394,7 @@ class ReportPDFCreator : ChangeNotifier
|
|||||||
pdfRenderer.DocumentRenderer.PrepareDocument(); // needed if you make edits after first PrepareDocument() is called
|
pdfRenderer.DocumentRenderer.PrepareDocument(); // needed if you make edits after first PrepareDocument() is called
|
||||||
pdfRenderer.RenderDocument();
|
pdfRenderer.RenderDocument();
|
||||||
// actually save to disk now
|
// actually save to disk now
|
||||||
string outputPDFFilePath = Path.Join(outputDir, outputFileName);
|
string outputPDFFilePath = Path.Join(outputFolderPath, outputFileName);
|
||||||
_logger?.LogInfo("Saving PDF document to disk...");
|
_logger?.LogInfo("Saving PDF document to disk...");
|
||||||
pdfRenderer.PdfDocument.Save(outputPDFFilePath);
|
pdfRenderer.PdfDocument.Save(outputPDFFilePath);
|
||||||
_logger?.LogInfo("Finished saving PDF output to: " + outputPDFFilePath);
|
_logger?.LogInfo("Finished saving PDF output to: " + outputPDFFilePath);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using MayShow.Interfaces;
|
|||||||
using MayShow.Models;
|
using MayShow.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
namespace MayShow.ViewModels;
|
namespace MayShow.ViewModels;
|
||||||
|
|
||||||
@@ -453,7 +454,7 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Run(() => CreatePDF(outputFolderPath: _pdfReport.BaseFolder));
|
await Task.Run(() => CreatePDF());
|
||||||
} catch (Exception e)
|
} catch (Exception e)
|
||||||
{
|
{
|
||||||
LogInfo("PDF process failed! Reason: " + e.Message);
|
LogInfo("PDF process failed! Reason: " + e.Message);
|
||||||
@@ -510,15 +511,58 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreatePDF(string outputFolderPath)
|
private async Task CreatePDF()
|
||||||
{
|
{
|
||||||
IsCreatingPDF = true;
|
IsCreatingPDF = true;
|
||||||
var reportCreator = new ReportPDFCreator(this);
|
var reportCreator = new ReportPDFCreator(this);
|
||||||
var outputPdfFile = await reportCreator.CreatePDF(ReportFiles.ToList(), ReportTitle, outputFolderPath, new PDFFontResolver(_processDir, this), _settings);
|
var outputDir = "";
|
||||||
if (!string.IsNullOrWhiteSpace(outputPdfFile))
|
switch (_settings.PDFOutputSaveLocation)
|
||||||
{
|
{
|
||||||
await CreateAndSaveReportObjectAfterReportCreation();
|
case Enums.PDFSaveLocation.BaseFolder:
|
||||||
OpenFolderForFileInFileViewer(outputPdfFile);
|
outputDir = _pdfReport.BaseFolder;
|
||||||
|
break;
|
||||||
|
case Enums.PDFSaveLocation.AlwaysAsk:
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||||
|
{
|
||||||
|
var topLevel = TopLevelGrabber?.GetTopLevel();
|
||||||
|
if (topLevel != null)
|
||||||
|
{
|
||||||
|
var result = await topLevel.StorageProvider.SaveFilePickerWithResultAsync(new FilePickerSaveOptions
|
||||||
|
{
|
||||||
|
Title = "Choose PDF save location...",
|
||||||
|
FileTypeChoices = [FilePickerFileTypes.Pdf],
|
||||||
|
SuggestedFileType = FilePickerFileTypes.Pdf,
|
||||||
|
DefaultExtension = "pdf",
|
||||||
|
ShowOverwritePrompt = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.File is not null)
|
||||||
|
{
|
||||||
|
var path = result.File.Path.AbsolutePath;
|
||||||
|
Console.WriteLine(path); // <--- this is what I want
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
IsCreatingPDF = false;
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case Enums.PDFSaveLocation.OtherChosenDir:
|
||||||
|
outputDir = _settings.OutputPdfDir;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// safety checks
|
||||||
|
if (!Directory.Exists(outputDir))
|
||||||
|
{
|
||||||
|
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var outputPdfFile = await reportCreator.CreatePDF(ReportFiles.ToList(), ReportTitle, outputDir, new PDFFontResolver(_processDir, this), _settings);
|
||||||
|
if (!string.IsNullOrWhiteSpace(outputPdfFile))
|
||||||
|
{
|
||||||
|
await CreateAndSaveReportObjectAfterReportCreation();
|
||||||
|
OpenFolderForFileInFileViewer(outputPdfFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IsCreatingPDF = false;
|
IsCreatingPDF = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user