Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3be81f136f | |||
| 2f14270379 | |||
| 70e5215ca9 | |||
| cd5a89e35a | |||
| 47fb765239 | |||
| 68cf8a4145 | |||
| e80d252b25 | |||
| fc89854bfc | |||
| d51017bb73 | |||
| 5f99d0e4eb | |||
| 3720a6a25a | |||
| 6d4e7a7bfe | |||
| be1fc5ec18 | |||
| baaf6f8e2b | |||
| bb6cdf0abf | |||
| 3c754dc196 | |||
| af8cfa31e5 | |||
| f32568c918 | |||
| b42da7603b | |||
| 851772398c | |||
| dfc1c557e0 | |||
| f927667732 | |||
| d77f9bab8c | |||
| d508222901 |
@@ -1,3 +1,32 @@
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 421 KiB After Width: | Height: | Size: 236 KiB |
@@ -3,7 +3,7 @@
|
||||
; Non-commercial use only
|
||||
|
||||
#define MyAppName "MayShow"
|
||||
#define MyAppVersion "1.2.0"
|
||||
#define MyAppVersion "1.3.0"
|
||||
#define MyAppPublisher "Quickity Quack Productions"
|
||||
#define MyAppExeName "MayShow.exe"
|
||||
|
||||
@@ -45,7 +45,9 @@ 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\Magick.Native-Q16-x64.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\Assets\*"; DestDir: "{app}\Assets"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION="1.3.0"
|
||||
SRC_DIR="src" # user ran script from main folder
|
||||
if [ ! -d "$SRC_DIR" ]; then
|
||||
SRC_DIR= "../src" # try
|
||||
@@ -11,6 +12,12 @@ 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
|
||||
# TODO: add automatic zipping and version number setting for ease of use
|
||||
cd bin/Release/net10.0/linux-arm64/publish
|
||||
zip -r "../../../../MayShow $VERSION linux-arm64.zip" .
|
||||
cd ../../../../../
|
||||
@@ -103,6 +103,12 @@
|
||||
<DataTemplate DataType="{x:Type viewModels:ShutdownCheckViewModel}">
|
||||
<views:ShutdownCheckView/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:ConfirmViewModel}">
|
||||
<views:ConfirmView/>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type viewModels:SettingsViewModel}">
|
||||
<views:SettingsView/>
|
||||
</DataTemplate>
|
||||
</Application.DataTemplates>
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
|
||||
@@ -5,7 +5,10 @@ namespace MayShow.Helpers;
|
||||
|
||||
class Constants
|
||||
{
|
||||
public static string AppVersion = "1.2.0";
|
||||
public static string AppVersion = "1.3.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", ];
|
||||
|
||||
public static string[] GetQuotes()
|
||||
{
|
||||
|
||||
+10
-3
@@ -12,12 +12,17 @@
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
<PublishAot>true</PublishAot>
|
||||
<AssemblyName>MayShow</AssemblyName>
|
||||
<AssemblyVersion>1.2.0</AssemblyVersion> <!-- Also update Constants version -->
|
||||
<AssemblyVersion>1.3.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\**" />
|
||||
@@ -46,10 +51,12 @@
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PDFsharp-MigraDoc" Version="6.2.3" />
|
||||
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="14.10.2" />
|
||||
<PackageReference Include="PDFsharp-MigraDoc" Version="6.2.4" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -12,10 +12,12 @@ namespace MayShow.Models;
|
||||
class Settings : ChangeNotifier
|
||||
{
|
||||
private string _lastUsedPath;
|
||||
private bool _useDocnetPDFImageRendering;
|
||||
|
||||
public Settings()
|
||||
{
|
||||
_lastUsedPath = "";
|
||||
_useDocnetPDFImageRendering = true;
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
@@ -25,6 +27,13 @@ class Settings : ChangeNotifier
|
||||
set { _lastUsedPath = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
[JsonInclude]
|
||||
public bool UseDocnetPFDImageRendering
|
||||
{
|
||||
get => _useDocnetPDFImageRendering;
|
||||
set { _useDocnetPDFImageRendering = value; NotifyPropertyChanged(); }
|
||||
}
|
||||
|
||||
public static string GetSettingsFileName()
|
||||
{
|
||||
return "settings.json";
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#nullable enable
|
||||
|
||||
using DialogHostAvalonia;
|
||||
using MayShow.Helpers;
|
||||
|
||||
namespace MayShow.ViewModels;
|
||||
|
||||
class ConfirmViewModel
|
||||
{
|
||||
private string _title;
|
||||
private string _message;
|
||||
private string _confirmTitle;
|
||||
private string _declineTitle;
|
||||
|
||||
public ConfirmViewModel(string title, string message, string confirmTitle = "Yes", string declineTitle = "No")
|
||||
{
|
||||
_title = title;
|
||||
_message = message;
|
||||
_confirmTitle = confirmTitle;
|
||||
_declineTitle = declineTitle;
|
||||
}
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
}
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => _message;
|
||||
}
|
||||
|
||||
public string ConfirmTitle
|
||||
{
|
||||
get => _confirmTitle;
|
||||
}
|
||||
|
||||
public string DeclineTitle
|
||||
{
|
||||
get => _declineTitle;
|
||||
}
|
||||
|
||||
public void Confirm()
|
||||
{
|
||||
DialogHost.Close("DialogHost", true);
|
||||
}
|
||||
|
||||
public void Decline()
|
||||
{
|
||||
DialogHost.Close("DialogHost", false);
|
||||
}
|
||||
}
|
||||
+169
-70
@@ -21,6 +21,14 @@ 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 System.Reflection.Metadata.Ecma335;
|
||||
using Docnet.Core.Readers;
|
||||
|
||||
namespace MayShow.ViewModels;
|
||||
|
||||
class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
@@ -230,10 +238,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
{
|
||||
AddFileBasedOnPath(filePath);
|
||||
}
|
||||
if (!_isPerformingInitialLoad)
|
||||
{
|
||||
ResortPDFItemsByDate();
|
||||
}
|
||||
ResortPDFItemsByDate();
|
||||
HasUnsavedWork = true;
|
||||
}
|
||||
}
|
||||
@@ -249,6 +254,17 @@ 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)
|
||||
@@ -280,18 +296,6 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
}
|
||||
}
|
||||
|
||||
private string[] GetAllowedFileExtensionPatterns()
|
||||
{
|
||||
// update GetAllowedFileExtensionPatternsWithoutStar if this is edited
|
||||
return [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ];
|
||||
}
|
||||
|
||||
private string[] GetAllowedFileExtensionPatternsWithoutStar()
|
||||
{
|
||||
// update GetAllowedFileExtensionPatterns if this is edited
|
||||
return [ "png", "jpg", "jpeg", "gif", "bmp", "webp", "pdf", "heic", ];
|
||||
}
|
||||
|
||||
public async void AddItem()
|
||||
{
|
||||
var topLevel = TopLevelGrabber?.GetTopLevel();
|
||||
@@ -304,7 +308,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
FileTypeFilter = [
|
||||
new FilePickerFileType("All Types")
|
||||
{
|
||||
Patterns = GetAllowedFileExtensionPatterns(),
|
||||
Patterns = Constants.AllowedFileExtensionPatterns,
|
||||
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
|
||||
MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
|
||||
},
|
||||
@@ -334,7 +338,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath) && !filePath.EndsWith(".DS_Store"))
|
||||
{
|
||||
// make sure extensions are OK
|
||||
var fileExtensions = GetAllowedFileExtensionPatternsWithoutStar();
|
||||
var fileExtensions = Constants.AllowedFileExtensionsNoStar;
|
||||
var didMatch = false;
|
||||
foreach (var fileExtension in fileExtensions)
|
||||
{
|
||||
@@ -346,7 +350,10 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
}
|
||||
if (!didMatch)
|
||||
{
|
||||
LogInfo("File {0} did not match allowed file extension types, so it was not added.", filePath);
|
||||
if (!filePath.EndsWith(GetReportSavedDataFileName()))
|
||||
{
|
||||
LogInfo("File {0} did not match allowed file extension types, so it was not added.", filePath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -363,6 +370,17 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
}
|
||||
}
|
||||
|
||||
public async void RemoveAllItems()
|
||||
{
|
||||
var result = await DialogHost.Show(new ConfirmViewModel("Warning!", "Are you sure you want to remove all items from this report?", "Remove All Items", "Cancel"));
|
||||
if (result != null && (bool)result)
|
||||
{
|
||||
ReportFiles.Clear();
|
||||
HasUnsavedWork = true;
|
||||
NotifyPropertyChanged(nameof(IsCreatePDFButtonEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
public void LocateFile(object f) => LocateFileImpl((ReportFile) f);
|
||||
public async void LocateFileImpl(ReportFile reportFile)
|
||||
{
|
||||
@@ -376,7 +394,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
FileTypeFilter = [
|
||||
new FilePickerFileType("All Types")
|
||||
{
|
||||
Patterns = GetAllowedFileExtensionPatterns(),
|
||||
Patterns = Constants.AllowedFileExtensionPatterns,
|
||||
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
|
||||
MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
|
||||
},
|
||||
@@ -604,6 +622,12 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
reportTitlePar.Format.Font.Name = "Noto Sans JP"; // has english letters in it, too
|
||||
reportTitlePar.AddText(ReportTitle);
|
||||
//
|
||||
var convertedDir = Path.Combine(folderPath, "converted");
|
||||
if (!Directory.Exists(convertedDir))
|
||||
{
|
||||
Directory.CreateDirectory(convertedDir);
|
||||
}
|
||||
//
|
||||
GlobalFontSettings.FontResolver = this;
|
||||
GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver();
|
||||
var hasAddedData = false;
|
||||
@@ -659,67 +683,142 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
var info = new FileInfo(file.FilePath);
|
||||
uint loadedImageWidth = 0;
|
||||
uint loadedImageHeight = 0;
|
||||
if (isHEIC || isWebp || isPNG)
|
||||
if (!isPDF)
|
||||
{
|
||||
// Save image as jpg
|
||||
var convertedDir = Path.Combine(folderPath, "converted");
|
||||
if (!Directory.Exists(convertedDir))
|
||||
{
|
||||
Directory.CreateDirectory(convertedDir);
|
||||
}
|
||||
var outputPath = Path.Combine(convertedDir, info.Name + ".jpg");
|
||||
using var mImage = new MagickImage(info.FullName);
|
||||
loadedImageWidth = mImage.Width;
|
||||
loadedImageHeight = mImage.Height;
|
||||
mImage.Quality = 80;
|
||||
if (mImage.Width >= 400 || mImage.Height >= 400)
|
||||
var convertedOutputPath = Path.Combine(convertedDir, info.Name + ".jpg");
|
||||
var didAdjust = false;
|
||||
LogInfo("Image orientation of {0} is {1}", fileName, mImage.Orientation);
|
||||
if (mImage.Orientation != OrientationType.TopLeft)
|
||||
{
|
||||
loadedImageWidth = (uint)Math.Floor(mImage.Width * 0.5);
|
||||
loadedImageHeight = (uint)Math.Floor(mImage.Height * 0.5);
|
||||
mImage.Scale(loadedImageWidth, loadedImageHeight);
|
||||
LogInfo("Auto-adjusted image orientation of {0}", fileName);
|
||||
mImage.AutoOrient();
|
||||
didAdjust = true;
|
||||
}
|
||||
// perform needed image manipulations
|
||||
if (isHEIC || isWebp || isPNG || (!isPDF && info.Length > 1.5 * 1024 * 1024 /* 1.5 MB */))
|
||||
{
|
||||
// Save image as jpg
|
||||
mImage.Quality = 80;
|
||||
if (mImage.Width >= 400 || mImage.Height >= 400)
|
||||
{
|
||||
loadedImageWidth = (uint)Math.Floor(mImage.Width * 0.5);
|
||||
loadedImageHeight = (uint)Math.Floor(mImage.Height * 0.5);
|
||||
mImage.Scale(loadedImageWidth, loadedImageHeight);
|
||||
LogInfo("Image {2} scaled to {0}x{1}", loadedImageWidth, loadedImageHeight, fileName);
|
||||
}
|
||||
didAdjust = true;
|
||||
LogInfo("Converted image {0} to JPEG", fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// load height/width
|
||||
loadedImageWidth = mImage.Width;
|
||||
loadedImageHeight = mImage.Height;
|
||||
}
|
||||
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...
|
||||
}
|
||||
await mImage.WriteAsync(outputPath);
|
||||
filePath = Path.Combine("Converted", info.Name + ".jpg");
|
||||
LogInfo(string.Format("Converted image to JPEG; fileName is now {0}", file.FilePath));
|
||||
}
|
||||
else if (!isPDF)
|
||||
{
|
||||
// load height/width
|
||||
using var mImage = new MagickImage(info.FullName);
|
||||
loadedImageWidth = mImage.Width;
|
||||
loadedImageHeight = mImage.Height;
|
||||
}
|
||||
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...
|
||||
}
|
||||
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++)
|
||||
// need to render PDF to images
|
||||
if (_settings.UseDocnetPFDImageRendering)
|
||||
{
|
||||
section.AddPageBreak();
|
||||
paragraph = section.AddParagraph();
|
||||
// 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;
|
||||
image = paragraph.AddImage(filePath + "#" + j);
|
||||
var image = paragraph.AddImage(filePath);
|
||||
image.LockAspectRatio = true;
|
||||
image.Width = imageWidth;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
LogInfo(string.Format("Added image: {0} ({1})", file.Title, filePath));
|
||||
hasAddedData = true;
|
||||
}
|
||||
var pdfRenderer = new PdfDocumentRenderer
|
||||
@@ -727,12 +826,12 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
|
||||
Document = pdfDoc,
|
||||
WorkingDirectory = folderPath
|
||||
};
|
||||
LogInfo("Rendering document...");
|
||||
LogInfo("Rendering document to PDF file...");
|
||||
pdfRenderer.RenderDocument();
|
||||
string outputPDFFileName = Path.Join(folderPath, outputFileName);
|
||||
LogInfo("Saving document to disk...");
|
||||
LogInfo("Saving PDF document to disk...");
|
||||
pdfRenderer.PdfDocument.Save(outputPDFFileName);
|
||||
LogInfo("Saved PDF output to: " + outputPDFFileName);
|
||||
LogInfo("Finished saving PDF output to: " + outputPDFFileName);
|
||||
await CreateAndSaveReportObjectAfterReportCreation();
|
||||
OpenFolderForFileInFileViewer(outputPDFFileName);
|
||||
IsCreatingPDF = false;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<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.ConfirmView"
|
||||
xmlns:models="clr-namespace:MayShow.Models"
|
||||
xmlns:vm="clr-namespace:MayShow.ViewModels"
|
||||
x:DataType="vm:ConfirmViewModel">
|
||||
<StackPanel Orientation="Vertical"
|
||||
Spacing="4">
|
||||
<TextBlock TextAlignment="Center"
|
||||
FontWeight="Bold"
|
||||
FontSize="18"
|
||||
Text="{Binding Title}"/>
|
||||
<TextBlock TextAlignment="Center"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap"
|
||||
FontSize="14"
|
||||
MaxWidth="350"
|
||||
Text="{Binding Message}"/>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Spacing="12"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="4">
|
||||
<Button Command="{Binding Decline}"
|
||||
Content="{Binding DeclineTitle}"
|
||||
HorizontalAlignment="Right"/>
|
||||
<Button Command="{Binding Confirm}"
|
||||
Classes="accent"
|
||||
Content="{Binding ConfirmTitle}"
|
||||
HorizontalAlignment="Right"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace MayShow.Views;
|
||||
|
||||
public partial class ConfirmView : UserControl
|
||||
{
|
||||
public ConfirmView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
+22
-10
@@ -12,15 +12,23 @@
|
||||
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="" FontFamily="{StaticResource FontAwesomeSolid}"/> Settings</TextBlock>
|
||||
</Button>
|
||||
<Button Command="{Binding ShowAbout}"
|
||||
Grid.Row="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,2,4,0">
|
||||
Margin="0,4,4,4">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> About</TextBlock>
|
||||
</Button>
|
||||
<StackPanel Orientation="Vertical"
|
||||
Spacing="2">
|
||||
Spacing="2"
|
||||
Margin="0,4,0,0">
|
||||
<Label Content="MayShow: Report Builder"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
@@ -226,24 +234,28 @@
|
||||
IsEnabled="{Binding CanAddItem}">
|
||||
<TextBlock><Run Text="+" FontFamily="{StaticResource FontAwesomeSolid}"/> Add Item(s)</TextBlock>
|
||||
</Button>
|
||||
<Button Command="{Binding SaveInterimReportInfo}"
|
||||
IsEnabled="{Binding HasWorkingFolderAndNotMakingPDF}">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Save Report Info</TextBlock>
|
||||
<Button Command="{Binding RemoveAllItems}"
|
||||
IsEnabled="{Binding IsCreatePDFButtonEnabled}"
|
||||
Classes="Danger">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Remove All Items</TextBlock>
|
||||
</Button>
|
||||
<Button Command="{Binding ResortPDFItemsByDate}"
|
||||
IsEnabled="{Binding IsCreatePDFButtonEnabled}">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Re-sort PDF Items</TextBlock>
|
||||
</Button>
|
||||
<Button Command="{Binding BuildPDF}"
|
||||
Classes="accent"
|
||||
IsEnabled="{Binding IsCreatePDFButtonEnabled}">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Create Report PDF</TextBlock>
|
||||
<Button Command="{Binding SaveInterimReportInfo}"
|
||||
IsEnabled="{Binding HasWorkingFolderAndNotMakingPDF}">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Save Report Info</TextBlock>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
IsVisible="{Binding IsCreatingPDF}"
|
||||
Spacing="6"
|
||||
HorizontalAlignment="Center">
|
||||
<Button Command="{Binding BuildPDF}"
|
||||
Classes="accent"
|
||||
IsEnabled="{Binding IsCreatePDFButtonEnabled}">
|
||||
<TextBlock><Run Text="" FontFamily="{StaticResource FontAwesomeSolid}"/> Create Report PDF</TextBlock>
|
||||
</Button>
|
||||
<Label Content="Creating PDF..."
|
||||
IsVisible="{Binding IsCreatingPDF}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<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=""
|
||||
FontFamily="{StaticResource FontAwesomeSolid}" /> Cancel</TextBlock>
|
||||
</Button>
|
||||
<Button Command="{Binding Save}"
|
||||
Classes="accent">
|
||||
<TextBlock>
|
||||
<Run Text=""
|
||||
FontFamily="{StaticResource FontAwesomeSolid}" /> Save</TextBlock>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,15 @@
|
||||
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
@@ -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.2.0.0" name="MayShow.Desktop"/>
|
||||
<assemblyIdentity version="1.3.0.0" name="MayShow.Desktop"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
|
||||
Reference in New Issue
Block a user