Use ReportFiles arr instead of files found in path

This commit is contained in:
2026-02-16 19:03:14 +09:00
parent 56fd2e27ec
commit 59d14c9665
+27 -15
View File
@@ -245,7 +245,6 @@ class MainViewModel : BaseViewModel, IFontResolver
{ {
try try
{ {
// TODO: use already found files and information
await Task.Run(() => CreatePDF(_workingFolder)); await Task.Run(() => CreatePDF(_workingFolder));
} catch (Exception e) } catch (Exception e)
{ {
@@ -394,15 +393,14 @@ class MainViewModel : BaseViewModel, IFontResolver
footerPar.AddText("Report generated on " + DateTime.Now.ToString("f")); footerPar.AddText("Report generated on " + DateTime.Now.ToString("f"));
section.Footers.Primary.Add(footerPar); section.Footers.Primary.Add(footerPar);
// //
var files = Directory.GetFiles(folderPath);
files.Sort();
GlobalFontSettings.FontResolver = this; GlobalFontSettings.FontResolver = this;
GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver(); GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver();
var hasAddedData = false; var hasAddedData = false;
for (var i = 0; i < files.Length; i++) for (var i = 0; i < ReportFiles.Count; i++)
{ {
var file = files[i]; var file = ReportFiles[i];
var fileName = Path.GetFileName(file); var fileName = file.FileName;
var filePath = file.FilePath;
if (fileName == ".DS_Store" || fileName == outputFileName) if (fileName == ".DS_Store" || fileName == outputFileName)
{ {
continue; continue;
@@ -416,39 +414,53 @@ class MainViewModel : BaseViewModel, IFontResolver
imageTitlePar.Format.Font.Size = 12; imageTitlePar.Format.Font.Size = 12;
imageTitlePar.Format.Font.Bold = true; imageTitlePar.Format.Font.Bold = true;
imageTitlePar.Format.Font.Name = "Noto Sans JP"; // has english letters in it, too imageTitlePar.Format.Font.Name = "Noto Sans JP"; // has english letters in it, too
imageTitlePar.AddText(fileName); imageTitlePar.AddText(file.Title);
if (!string.IsNullOrWhiteSpace(file.Notes))
{
var imageNotesPar = section.AddParagraph();
imageNotesPar.Format.Alignment = ParagraphAlignment.Center;
imageNotesPar.Format.Font.Size = 10;
imageNotesPar.Format.Font.Bold = false;
imageNotesPar.Format.Font.Name = "Noto Sans JP";
imageNotesPar.AddText(file.Notes);
}
section.AddParagraph(); // add empty line for spacing section.AddParagraph(); // add empty line for spacing
// now add the image // now add the image
var isPDF = fileName.EndsWith(".pdf"); var isPDF = fileName.EndsWith(".pdf");
var isHEIC = fileName.EndsWith(".HEIC") || fileName.EndsWith(".heic"); // convert heic, webp, or png to JPEG for size and ease of use
if (isHEIC) // (and probably compat reasons too, though I haven't tested that...)
var lowerName = fileName.ToLower();
var isHEIC = lowerName.EndsWith(".heic");
var isWebp = lowerName.EndsWith(".webp");
var isPNG = lowerName.EndsWith(".png");
if (isHEIC || isWebp || isPNG)
{ {
var convertedDir = Path.Combine(folderPath, "converted"); var convertedDir = Path.Combine(folderPath, "converted");
if (!Directory.Exists(convertedDir)) if (!Directory.Exists(convertedDir))
{ {
Directory.CreateDirectory(convertedDir); Directory.CreateDirectory(convertedDir);
} }
var info = new FileInfo(file); var info = new FileInfo(file.FilePath);
using var mImage = new MagickImage(info.FullName); using var mImage = new MagickImage(info.FullName);
// Save frame as jpg // Save frame as jpg
var outputPath = Path.Combine(convertedDir, info.Name + ".jpg"); var outputPath = Path.Combine(convertedDir, info.Name + ".jpg");
mImage.Quality = 80; mImage.Quality = 80;
mImage.Scale((uint)Math.Floor(mImage.Width * 0.5), (uint)Math.Floor(mImage.Height * 0.5)); mImage.Scale((uint)Math.Floor(mImage.Width * 0.5), (uint)Math.Floor(mImage.Height * 0.5));
await mImage.WriteAsync(outputPath); await mImage.WriteAsync(outputPath);
fileName = Path.Combine("Converted", info.Name + ".jpg"); filePath = Path.Combine("Converted", info.Name + ".jpg");
LogInfo(string.Format("Converted HEIC image to JPEG; fileName is now {0}", fileName)); LogInfo(string.Format("Converted image to JPEG; fileName is now {0}", file.FilePath));
} }
var paragraph = section.AddParagraph(); var paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Format.Alignment = ParagraphAlignment.Center;
var image = paragraph.AddImage(fileName); var image = paragraph.AddImage(filePath);
image.LockAspectRatio = true; image.LockAspectRatio = true;
image.Width = imageWidth; // can't be too wide now...not sure why...maybe due to margins... image.Width = imageWidth; // can't be too wide now...not sure why...maybe due to margins...
LogInfo(string.Format("Added image: {0}", fileName)); LogInfo(string.Format("Added image: {0} ({1})", file.Title, filePath));
if (isPDF) if (isPDF)
{ {
// add other PDF pages // add other PDF pages
// see: https://stackoverflow.com/a/65091204/3938401 // see: https://stackoverflow.com/a/65091204/3938401
var pdfFileToAdd = PdfReader.Open(file); var pdfFileToAdd = PdfReader.Open(filePath);
imageTitlePar.AddText(string.Format(" (PDF with {0} page{1}) ", imageTitlePar.AddText(string.Format(" (PDF with {0} page{1}) ",
pdfFileToAdd.PageCount, pdfFileToAdd.PageCount,
pdfFileToAdd.PageCount == 1 ? "" : "s")); pdfFileToAdd.PageCount == 1 ? "" : "s"));