4 Commits

Author SHA1 Message Date
mbabienco 00d35a5ead Try some more algorithms
We got the black background, receipt foreground working, but this is a limited test case. I do not have something working in the general case nor the expertise to know how to do that.
2026-03-01 15:26:36 +09:00
mbabienco 7b854d7216 Sort of finds the receipt not really
Need to read more into params and figure out best config and then run with it
2026-02-27 18:08:53 +09:00
mbabienco af0a5d0501 Add dependency (macOS) on OpenCv 2026-02-27 17:36:28 +09:00
mbabienco c3a4c4ae96 Swap to Magick.NET-Q8 for faster processing 2026-02-27 17:36:15 +09:00
13 changed files with 258 additions and 297 deletions
+19 -28
View File
@@ -1,32 +1,22 @@
magick "2026-01-29 — \$210 — WORK PERMIT.pdf" -background white -alpha background -alpha off -density 288 -resize 25% page-%03d.jpg
https://github.com/dlemstra/Magick.NET/blob/main/docs/ConvertPDF.md
https://stackoverflow.com/questions/65089839/add-an-external-pdf-page-to-pdfsharp-migradoc
https://github.com/mephraim/ghostscriptsharp
https://stackoverflow.com/a/71485279/3938401
-Add ImageMagick attribution to about page
-auto detect receipts in an image and auto-crop?
-https://imagemagick.org/api/feature.php#gsc.tab=0 canny edge image
-https://blog.jiayu.co/2019/05/edge-detection-with-imagemagick/
-https://pyimagesearch.com/2021/10/27/automatically-ocring-receipts-and-scans/ using open CV
-https://www.kaggle.com/code/dmitryyemelyanov/receipt-ocr-part-1-image-segmentation-by-opencv manip done before edge detect
-https://www.luisllamas.es/en/how-to-use-opencv-in-net-with-opencvsharp/ (some basic code but also line detect)
-opencv for macOS? https://www.nuget.org/packages/OpenCvSharp4.runtime.osx.10.15-universal
macOS arm64: https://www.nuget.org/packages/OpenCvSharp4.runtime.osx_arm64/4.8.1-rc
-can use the normal nuget for windows, linnux
-if we can get openCV working then we can probably hack something together...
-https://github.com/shimat/opencvsharp/issues/949 -- requires ffmpeg?!
-https://github.com/shimat/opencvsharp
-https://www.emgu.com/wiki/index.php?title=Main_Page (GPL...)
-https://stackoverflow.com/questions/30296710/detecting-paper-edge-and-crop-it
//https://developers.goalist.co.jp/entry/2019/02/13/150126
need a PDF viewer that works with annotations
https://github.com/BobLd/PdfPig.Rendering.Skia/ works but quality is low for some reason, I don't know why. probably need a bug report or some option that is hidden.
using (var document = UglyToad.PdfPig.PdfDocument.Open(filePath, UglyToad.PdfPig.Rendering.Skia.SkiaRenderingParsingOptions.Instance))
{
document.AddSkiaPageFactory(); // Same as document.AddPageFactory<SKPicture, SkiaPageFactory>() and document.AddPageFactory<PdfPageSize, PageSizeFactory>()
for (int p = 1; p <= document.NumberOfPages; p++)
{
using var skBitmap = document.GetPageAsSKBitmap(p, 1);
using (var fs = new FileStream(Path.Combine(convertedDir, $"{fileName}_{p}PIG.jpeg"), FileMode.Create))
using (var ms = document.GetPageAsPng(p, 1, 4))
{
MemoryStream memoryStream = new MemoryStream();
skBitmap.Encode(memoryStream, SkiaSharp.SKEncodedImageFormat.Jpeg, 100);
memoryStream.Position = 0L;
ms.WriteTo(fs);
}
}
}
https://github.com/GowenGit/docnet -- may need to fork this and publish our own package if some OS doesn't work
---------------
*-add more items
*-save last opened folder to settings somewhere
@@ -50,4 +40,5 @@ https://github.com/GowenGit/docnet -- may need to fork this and publish our own
---Publishing---
*-Published app has unneeded .DSYM file (fixed via .app builder)
*-Published app has Assets folder already copied to it; don't want that in output macOS folder but it's being copied there anyway (fixed via .app builder)
*-macOS x64 build
*-macOS x64 build
+2 -4
View File
@@ -3,7 +3,7 @@
; Non-commercial use only
#define MyAppName "MayShow"
#define MyAppVersion "1.3.0"
#define MyAppVersion "1.2.0"
#define MyAppPublisher "Quickity Quack Productions"
#define MyAppExeName "MayShow.exe"
@@ -45,9 +45,7 @@ Source: "..\src\bin\Release\net10.0\win-x64\publish\{#MyAppExeName}"; DestDir: "
Source: "..\src\bin\Release\net10.0\win-x64\publish\av_libglesv2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\libHarfBuzzSharp.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\libSkiaSharp.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\LICENSE"; DestDir: "{app}"; DestName: "PDFium-license.txt"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\Magick.Native-Q8-x64.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\pdfium.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\Magick.Native-Q16-x64.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\src\bin\Release\net10.0\win-x64\publish\Assets\*"; DestDir: "{app}\Assets"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
+1 -8
View File
@@ -1,6 +1,5 @@
#!/bin/bash
VERSION="1.3.0"
SRC_DIR="src" # user ran script from main folder
if [ ! -d "$SRC_DIR" ]; then
SRC_DIR= "../src" # try
@@ -12,12 +11,6 @@ fi
cd "$SRC_DIR"
echo "Building release for linux-x64..."
dotnet publish -c Release -r linux-x64 -p:StripSymbols=False -p:PublishAot=False
echo "Zipping up linux-x64..."
cd bin/Release/net10.0/linux-x64/publish
zip -r "../../../../MayShow $VERSION linux-arm64.zip" .
cd ../../../../../
echo "Building release for linux-arm64..."
dotnet publish -c Release -r linux-arm64 -p:StripSymbols=False -p:PublishAot=False
cd bin/Release/net10.0/linux-arm64/publish
zip -r "../../../../MayShow $VERSION linux-arm64.zip" .
cd ../../../../../
# TODO: add automatic zipping and version number setting for ease of use
-3
View File
@@ -106,9 +106,6 @@
<DataTemplate DataType="{x:Type viewModels:ConfirmViewModel}">
<views:ConfirmView/>
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:SettingsViewModel}">
<views:SettingsView/>
</DataTemplate>
</Application.DataTemplates>
<Application.Resources>
<ResourceDictionary>
+1 -1
View File
@@ -5,7 +5,7 @@ namespace MayShow.Helpers;
class Constants
{
public static string AppVersion = "1.3.0";
public static string AppVersion = "1.2.0";
public static string[] AllowedFileExtensionPatterns = [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ];
public static string[] AllowedFileExtensionsNoStar = [ "png", "jpg", "jpeg", "gif", "bmp", "webp", "pdf", "heic", ];
+6 -9
View File
@@ -12,17 +12,12 @@
<PublishTrimmed>true</PublishTrimmed>
<PublishAot>true</PublishAot>
<AssemblyName>MayShow</AssemblyName>
<AssemblyVersion>1.3.0</AssemblyVersion> <!-- Also update Constants version -->
<AssemblyVersion>1.2.0</AssemblyVersion> <!-- Also update Constants version -->
<ApplicationIcon>MayShow-icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="MigraDoc.DocumentObjectModel" />
<TrimmerRootAssembly Include="MigraDoc.Rendering" />
<TrimmerRootAssembly Include="MigraDoc.RtfRendering" />
<TrimmerRootAssembly Include="PdfSharp" />
<TrimmerRootAssembly Include="Avalonia.Controls.DataGrid" />
<!-- <TrimmerRootAssembly Include="Docnet.Core" />
<TrimmerRootAssembly Include="SixLabors.ImageSharp" /> -->
</ItemGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
@@ -51,12 +46,14 @@
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="PDFsharp-MigraDoc" Version="6.2.4" />
<PackageReference Include="PDFsharp-MigraDoc" Version="6.2.3" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="14.10.3" />
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.11-preview20251127001" />
<PackageReference Include="DialogHost.Avalonia" Version="0.10.4" />
<PackageReference Include="Xaml.Behaviors.Interactions.DragAndDrop.DataGrid" Version="11.3.9.5" />
<PackageReference Include="Docnet.Core" Version="2.6.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
<PackageReference Include="OpenCvSharp4" Version="4.13.0.20260226" />
</ItemGroup>
<ItemGroup Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' ">
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-universal" Version="4.7.0.20230224" />
</ItemGroup>
</Project>
-9
View File
@@ -12,12 +12,10 @@ namespace MayShow.Models;
class Settings : ChangeNotifier
{
private string _lastUsedPath;
private bool _useDocnetPDFImageRendering;
public Settings()
{
_lastUsedPath = "";
_useDocnetPDFImageRendering = true;
}
[JsonInclude]
@@ -27,13 +25,6 @@ class Settings : ChangeNotifier
set { _lastUsedPath = value; NotifyPropertyChanged(); }
}
[JsonInclude]
public bool UseDocnetPFDImageRendering
{
get => _useDocnetPDFImageRendering;
set { _useDocnetPDFImageRendering = value; NotifyPropertyChanged(); }
}
public static string GetSettingsFileName()
{
return "settings.json";
+220 -111
View File
@@ -20,14 +20,10 @@ using MayShow.Helpers;
using MayShow.Interfaces;
using MayShow.Models;
using MayShows.Helpers;
using Docnet.Core.Models;
using Docnet.Core;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using OpenCvSharp;
using System.Reflection.Metadata.Ecma335;
using Docnet.Core.Readers;
using System.Collections.Generic;
using System.Threading;
namespace MayShow.ViewModels;
@@ -238,7 +234,10 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
{
AddFileBasedOnPath(filePath);
}
ResortPDFItemsByDate();
if (!_isPerformingInitialLoad)
{
ResortPDFItemsByDate();
}
HasUnsavedWork = true;
}
}
@@ -254,17 +253,6 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
DialogHost.Show(new AboutViewModel());
}
public async Task ShowSettings()
{
var updatedSettings = await DialogHost.Show(new SettingsViewModel(_settings));
if (updatedSettings != null)
{
_settings = (Settings)updatedSettings;
await _settings.SaveSettingsAsync();
LogInfo("Saved updated settings!");
}
}
public void RemoveFile(object f) => RemoveFileImpl((ReportFile)f);
public async void RemoveFileImpl(ReportFile file)
@@ -532,6 +520,190 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
return "report_data.json";
}
public void TestReceiptFinding(object f) => TestReceiptFindingImpl((ReportFile)f);
private Mat? b_algor(ReportFile file)
{
using var orig = new Mat(file.FilePath);
using var src = new Mat(file.FilePath, ImreadModes.Grayscale);
if (src.Empty())
{
LogInfo("File was empty?");
return null;
}
using var blur = orig.GaussianBlur(new Size(5, 5), 0.0);
using var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(9,9));
using var dilated = blur.Dilate(kernel, anchor: null, iterations: 4);
using var edges = dilated.Canny(100, 200, 3);
using var heirarchy = new Mat();
Cv2.FindContours(edges, out Mat[] contours, heirarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
using var orgWithContours = new Mat();
orig.CopyTo(orgWithContours);
Cv2.DrawContours(orgWithContours, contours, -1, Scalar.Cyan, 3);
// largest contours
var largestContours = contours.OrderByDescending(x => x.ContourArea()).Take(1).ToArray();
var orgWithLargestContours = new Mat();
orig.CopyTo(orgWithLargestContours);
Cv2.DrawContours(orgWithLargestContours, largestContours, -1, Scalar.Cyan, 5);
using (new OpenCvSharp.Window("blur", blur))
using (new OpenCvSharp.Window("dilated", dilated))
using (new OpenCvSharp.Window("edges", edges))
using (new OpenCvSharp.Window("contours", orgWithContours))
// using (new OpenCvSharp.Window("w biggest contours", orgWithBiggestContours))
{
Cv2.WaitKey();
}
return orgWithLargestContours;
}
private void TestReceiptFindingImpl(ReportFile file)
{
LogInfo("Running receipt edge detection on file at path {0} with OpenCV {1}...", file.FilePath, Cv2.GetVersionString() ?? "");
using var orig = new Mat(file.FilePath);
using var src = new Mat(file.FilePath, ImreadModes.Grayscale);
using var dst = new Mat();
using var wContours = new Mat();
if (src.Empty())
{
LogInfo("File was empty?");
return;
}
var threshold = src.Threshold(90,255, ThresholdTypes.Binary);
var blur = orig.GaussianBlur(new Size(3.0, 3.0), 0.0);
var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(9,9));
var dilated = blur.Dilate(kernel, null, 1);
var edges = dilated.Canny(50, 200, 3);
//# Detect all contours in Canny-edged image
using var heirarchy = new Mat();
Cv2.FindContours(threshold, out Mat[] contours, heirarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
var orgWithContours = new Mat();
orig.CopyTo(orgWithContours);
Cv2.DrawContours(orgWithContours, contours, -1, Scalar.Cyan, 3);
// # find full contours
var poly = new List<Mat>();
foreach (var contour in contours)
{
var hull = contour.ConvexHull();
poly.Add(hull.ApproxPolyDP(0.01 * Cv2.ArcLength(hull, true), false));
}
Console.WriteLine("How many? {0}", poly.Count);
var orgWithAllPly = new Mat();
orig.CopyTo(orgWithAllPly);
Cv2.DrawContours(orgWithAllPly, poly, -1, Scalar.Red, 3);
var largestPoly = poly.OrderByDescending(x => x.ContourArea()).Take(10).ToArray();
var orgWithLargestContoursPly = new Mat();
orig.CopyTo(orgWithLargestContoursPly);
Cv2.DrawContours(orgWithLargestContoursPly, largestPoly, -1, Scalar.Red, 5);
// using (new OpenCvSharp.Window("poly", orgWithAllPly))
// using (new OpenCvSharp.Window("pol2y", orgWithLargestContoursPly))
// {
// Cv2.WaitKey();
// }
//
// # Get 10 largest contours
Console.WriteLine(contours);
var orgWithLargestContours = new Mat();
orig.CopyTo(orgWithLargestContours);
var largestContours = contours.OrderByDescending(x => x.ContourArea()).Take(10).ToArray();
Cv2.DrawContours(orgWithLargestContours, largestContours, -1, Scalar.Cyan, 5);
//
Mat approximate_contour(Mat contour)
{
var perimeter = Cv2.ArcLength(contour, true);
return contour.ApproxPolyDP(0.02 * perimeter, true);
}
Mat? get_receipt_counter(Mat[] contours)
{
var poly = new List<Mat>();
foreach (var contour in contours)
{
// var hull = contour.ConvexHull();
// var arcLength = hull.ArcLength(true);
// var x = contour.ApproxPolyDP(0.01 * arcLength, true);
// poly.Add(x);
var approx = approximate_contour(contour);
if (approx.Total() == 4)
{
return approx;
}
}
return null;
}
var highestY = 0;
var lowestY = 9999;
var highestX = 0;
var lowestX = 9999;
foreach (var contour in largestContours)
{
Console.WriteLine("Rows: {0}", contour.Rows);
if (contour.Rows > 10) // eliminate small things?
{
for (var i = 0; i < contour.Rows; i++)
{
var pt = contour.At<Point>(i);
if (pt.X < lowestX)
{
lowestX = pt.X;
}
if (pt.X > highestX)
{
highestX = pt.X;
}
if (pt.Y < lowestY)
{
lowestY = pt.Y;
}
if (pt.Y > highestY)
{
highestY = pt.Y;
}
}
}
}
Console.WriteLine("Low X: {0}, High X: {1}", lowestX, highestX);
Console.WriteLine("Low Y: {0}, High Y: {1}", lowestY, highestY);
var rect = new Rect(lowestX, lowestY, Math.Abs(highestX - lowestX), Math.Abs(highestY - lowestY));
Console.WriteLine(rect);
using var crop = new Mat(orig, rect);
using (new OpenCvSharp.Window("w largest contours", orgWithLargestContours))
using (new OpenCvSharp.Window("crop", crop))
using (new OpenCvSharp.Window("crop_b", b_algor(file)))
// using (new OpenCvSharp.Window("w biggest contours", orgWithBiggestContours))
{
Cv2.WaitKey();
}
return;
var largest = get_receipt_counter(largestContours);
Console.WriteLine(largest);
var orgWithBiggestContours = new Mat();
orig.CopyTo(orgWithBiggestContours);
Cv2.DrawContours(orgWithBiggestContours, [largest], -1, Scalar.Cyan, 3);
////
using (new OpenCvSharp.Window("src image", src))
// using (new OpenCvSharp.Window("blur image", blur))
// using (new OpenCvSharp.Window("dilated image", dilated))
using (new OpenCvSharp.Window("orig with all contours", orgWithContours))
using (new OpenCvSharp.Window("w largest contours", orgWithLargestContours))
// using (new OpenCvSharp.Window("w biggest contours", orgWithBiggestContours))
{
Cv2.WaitKey();
}
}
public byte[]? GetFont(string faceName)
{
LogInfo(string.Format("Loading font {0}", faceName));
@@ -721,104 +893,41 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
if (didAdjust)
{
await mImage.WriteAsync(convertedOutputPath);
filePath = convertedOutputPath;
LogInfo(string.Format("Saved adjusted image to JPEG; file path is now {0}", filePath));
}
// write to PDF
var paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
var image = paragraph.AddImage(filePath);
image.LockAspectRatio = true;
if (!isPDF && loadedImageHeight > 600)
{
image.Height = 550; // make sure it will fit on one page
}
else
{
image.Width = imageWidth; // can't be too wide now...not sure why...maybe due to margins...
filePath = Path.Combine("Converted", info.Name + ".jpg");
LogInfo(string.Format("Saved adjusted image to JPEG; fileName is now {0}", file.FilePath));
}
}
var paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
var image = paragraph.AddImage(filePath);
image.LockAspectRatio = true;
if (!isPDF && loadedImageHeight > 600)
{
image.Height = 550; // make sure it will fit on one page
}
else
{
// need to render PDF to images
if (_settings.UseDocnetPFDImageRendering)
{
// render using Docnet library (which utilizes pdfium, the chrome renderer)
string RenderPdfPageToImage(IDocReader docReader, int pgNum)
{
Console.WriteLine("Rendering pg " + pgNum);
using var pageReader = docReader.GetPageReader(pgNum);
Console.WriteLine("Getting image for page " + pgNum);
var rawBytes = pageReader.GetImage(RenderFlags.RenderAnnotations);
Console.WriteLine("Getting width & height for page " + pgNum);
var width = pageReader.GetPageWidth();
var height = pageReader.GetPageHeight();
Console.WriteLine("Loading pixel data for page " + pgNum);
using var img = Image.LoadPixelData<Bgra32>(rawBytes, width, height);
// you are likely going to want this as well otherwise you might end up with transparent parts.
img.Mutate(x => x.BackgroundColor(SixLabors.ImageSharp.Color.White));
var pdfPageImageOutputPath = Path.Combine(convertedDir, info.Name + "-Page-"
+ (pgNum + 1).ToString().PadLeft(3, '0') + ".jpg");
img.Save(pdfPageImageOutputPath);
Console.WriteLine("Done rendering pg " + pgNum);
return pdfPageImageOutputPath;
}
// render all pages to images
var docReader = DocLib.Instance.GetDocReader(
filePath,
new PageDimensions(1080, 1920)); // TODO: are these dims right?
// add to document
var pgCount = docReader.GetPageCount();
if (pgCount > 0)
{
var convertedPdfImagePath = RenderPdfPageToImage(docReader, 0);
imageTitlePar.AddText(string.Format(" (PDF with {0} page{1}) ",
pgCount,
pgCount == 1 ? "" : "s"));
var paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
var image = paragraph.AddImage(convertedPdfImagePath);
image.Width = imageWidth;
image.LockAspectRatio = true;
for (var j = 1; j < pgCount; j++)
{
section.AddPageBreak();
paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
convertedPdfImagePath = RenderPdfPageToImage(docReader, j);
image = paragraph.AddImage(convertedPdfImagePath);
image.LockAspectRatio = true;
image.Width = imageWidth;
}
}
}
else
{
// render first page (eventually need to improve code to just do everything in a loop)
var paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
var image = paragraph.AddImage(filePath);
image.LockAspectRatio = true;
image.Width = imageWidth; // can't be too wide now...not sure why...maybe due to margins...
// render other PDF pages, if any
// see: https://stackoverflow.com/a/65091204/3938401
var pdfFileToAdd = PdfReader.Open(filePath, PdfDocumentOpenMode.Import);
var pgCount = pdfFileToAdd.PageCount;
imageTitlePar.AddText(string.Format(" (PDF with {0} page{1}) ",
pgCount,
pgCount == 1 ? "" : "s"));
for (var j = 2; j <= pgCount; j++)
{
section.AddPageBreak();
paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
image = paragraph.AddImage(filePath + "#" + j);
image.LockAspectRatio = true;
image.Width = imageWidth;
}
}
image.Width = imageWidth; // can't be too wide now...not sure why...maybe due to margins...
}
LogInfo(string.Format("Added image: {0} ({1})", file.Title, filePath));
if (isPDF)
{
// add other PDF pages
// see: https://stackoverflow.com/a/65091204/3938401
var pdfFileToAdd = PdfReader.Open(filePath);
imageTitlePar.AddText(string.Format(" (PDF with {0} page{1}) ",
pdfFileToAdd.PageCount,
pdfFileToAdd.PageCount == 1 ? "" : "s"));
for (var j = 2; j <= pdfFileToAdd.PageCount; j++)
{
section.AddPageBreak();
paragraph = section.AddParagraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;
image = paragraph.AddImage(filePath + "#" + j);
image.LockAspectRatio = true;
image.Width = imageWidth;
}
}
hasAddedData = true;
}
var pdfRenderer = new PdfDocumentRenderer
-58
View File
@@ -1,58 +0,0 @@
#nullable enable
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Platform.Storage;
using Avalonia.Themes.Fluent;
using DialogHostAvalonia;
using ImageMagick;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using PdfSharp.Fonts;
using PdfSharp.Pdf.IO;
using PdfSharp.Snippets.Font;
using MayShow.Interfaces;
using MayShow.Models;
using MayShow.Helpers;
namespace MayShow.ViewModels;
class SettingsViewModel: ChangeNotifier
{
private Settings _previousSettings;
private Settings _settings;
public SettingsViewModel(Settings settingsToEdit)
{
_previousSettings = settingsToEdit;
_settings = new Settings
{
LastUsedPath = _previousSettings.LastUsedPath,
UseDocnetPFDImageRendering = _previousSettings.UseDocnetPFDImageRendering
};
}
public bool UseDocnetPDFImageRendering
{
get => _settings.UseDocnetPFDImageRendering;
set
{
_settings.UseDocnetPFDImageRendering = value;
NotifyPropertyChanged();
}
}
public void Cancel()
{
DialogHost.Close("DialogHost", null);
}
public void Save()
{
DialogHost.Close("DialogHost", _settings);
}
}
+8 -10
View File
@@ -12,23 +12,15 @@
x:DataType="vm:MainViewModel">
<Grid ColumnDefinitions="*"
RowDefinitions="Auto, 2*, Auto, Auto, *">
<Button Command="{Binding ShowSettings}"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="4,4,0,4">
<TextBlock><Run Text="&#xf013;" FontFamily="{StaticResource FontAwesomeSolid}"/> Settings</TextBlock>
</Button>
<Button Command="{Binding ShowAbout}"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,4,4,4">
Margin="0,2,4,0">
<TextBlock><Run Text="&#xf059;" FontFamily="{StaticResource FontAwesomeSolid}"/> About</TextBlock>
</Button>
<StackPanel Orientation="Vertical"
Spacing="2"
Margin="0,4,0,0">
Spacing="2">
<Label Content="MayShow: Report Builder"
FontSize="20"
FontWeight="Bold"
@@ -218,6 +210,12 @@
<TextBlock FontSize="12"><Run Text="&#xf07c;" FontFamily="{StaticResource FontAwesomeSolid}"/> Open File</TextBlock>
</Button.Content>
</Button>
<Button Command="{Binding $parent[DataGrid].((vm:MainViewModel)DataContext).TestReceiptFinding}"
CommandParameter="{Binding}">
<Button.Content>
<TextBlock FontSize="12"><Run Text="&#xf07c;" FontFamily="{StaticResource FontAwesomeSolid}"/> TEST RECEIPT FIND</TextBlock>
</Button.Content>
</Button>
</StackPanel>
</Grid>
</DataTemplate>
-40
View File
@@ -1,40 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="800"
d:DesignHeight="450"
x:Class="MayShow.Views.SettingsView"
xmlns:models="clr-namespace:MayShow.Models"
xmlns:vm="clr-namespace:MayShow.ViewModels"
x:DataType="vm:SettingsViewModel"
MaxWidth="350">
<ScrollViewer AllowAutoHide="False">
<StackPanel Orientation="Vertical"
Spacing="4"
Margin="12,4,12,0">
<Label Content="Settings"
HorizontalAlignment="Center"
FontSize="16"
FontWeight="Bold" />
<CheckBox IsChecked="{Binding !UseDocnetPDFImageRendering}">Use legacy PDF handling (does not work with macOS annotations)</CheckBox>
<StackPanel Orientation="Horizontal"
Spacing="12"
Margin="0,4,0,0"
HorizontalAlignment="Right">
<Button Command="{Binding Cancel}">
<TextBlock>
<Run Text="&#xf0e2;"
FontFamily="{StaticResource FontAwesomeSolid}" /> Cancel</TextBlock>
</Button>
<Button Command="{Binding Save}"
Classes="accent">
<TextBlock>
<Run Text="&#xf0c7;"
FontFamily="{StaticResource FontAwesomeSolid}" /> Save</TextBlock>
</Button>
</StackPanel>
</StackPanel>
</ScrollViewer>
</UserControl>
-15
View File
@@ -1,15 +0,0 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace MayShow.Views
{
public partial class SettingsView : UserControl
{
public SettingsView()
{
this.InitializeComponent();
}
}
}
+1 -1
View File
@@ -3,7 +3,7 @@
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.3.0.0" name="MayShow.Desktop"/>
<assemblyIdentity version="1.2.0.0" name="MayShow.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>