Fix some trimming issues

This commit is contained in:
2026-03-02 17:13:33 +09:00
parent cd5a89e35a
commit 70e5215ca9
2 changed files with 11 additions and 2 deletions
+5
View File
@@ -16,8 +16,13 @@
<ApplicationIcon>MayShow-icon.ico</ApplicationIcon> <ApplicationIcon>MayShow-icon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<TrimmerRootAssembly Include="MigraDoc.DocumentObjectModel" />
<TrimmerRootAssembly Include="MigraDoc.Rendering" />
<TrimmerRootAssembly Include="MigraDoc.RtfRendering" />
<TrimmerRootAssembly Include="PdfSharp" /> <TrimmerRootAssembly Include="PdfSharp" />
<TrimmerRootAssembly Include="Avalonia.Controls.DataGrid" /> <TrimmerRootAssembly Include="Avalonia.Controls.DataGrid" />
<!-- <TrimmerRootAssembly Include="Docnet.Core" />
<TrimmerRootAssembly Include="SixLabors.ImageSharp" /> -->
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />
+6 -2
View File
@@ -746,21 +746,25 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
// render using Docnet library (which utilizes pdfium, the chrome renderer) // render using Docnet library (which utilizes pdfium, the chrome renderer)
string RenderPdfPageToImage(IDocReader docReader, int pgNum) string RenderPdfPageToImage(IDocReader docReader, int pgNum)
{ {
Console.WriteLine("rendering pg " + pgNum); Console.WriteLine("Rendering pg " + pgNum);
using var pageReader = docReader.GetPageReader(pgNum); using var pageReader = docReader.GetPageReader(pgNum);
Console.WriteLine("Getting image for page " + pgNum);
var rawBytes = pageReader.GetImage(RenderFlags.RenderAnnotations); var rawBytes = pageReader.GetImage(RenderFlags.RenderAnnotations);
Console.WriteLine("Getting width & height for page " + pgNum);
var width = pageReader.GetPageWidth(); var width = pageReader.GetPageWidth();
var height = pageReader.GetPageHeight(); var height = pageReader.GetPageHeight();
Console.WriteLine("Loading pixel data for page " + pgNum);
using var img = Image.LoadPixelData<Bgra32>(rawBytes, width, height); 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. // 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)); img.Mutate(x => x.BackgroundColor(SixLabors.ImageSharp.Color.White));
var pdfPageImageOutputPath = Path.Combine(convertedDir, info.Name + "-Page-" var pdfPageImageOutputPath = Path.Combine(convertedDir, info.Name + "-Page-"
+ (pgNum + 1).ToString().PadLeft(3, '0') + ".jpg"); + (pgNum + 1).ToString().PadLeft(3, '0') + ".jpg");
img.Save(pdfPageImageOutputPath); img.Save(pdfPageImageOutputPath);
Console.WriteLine("Done rendering pg " + pgNum);
return pdfPageImageOutputPath; return pdfPageImageOutputPath;
} }
// render all pages to images // render all pages to images
using var docReader = DocLib.Instance.GetDocReader( var docReader = DocLib.Instance.GetDocReader(
filePath, filePath,
new PageDimensions(1080, 1920)); // TODO: are these dims right? new PageDimensions(1080, 1920)); // TODO: are these dims right?
// add to document // add to document