Files
google-labs-jules[bot] a1463dfeb9 Output:
Fix: Correct print scaling for Win2D PDF printing

Issue:
When you're printing pages using Win2D, especially when dealing with PDF documents that are rendered to CanvasBitmaps, you might run into some problems if your Windows display scaling isn't set to 100%. You might find that the edges of your printed PDF page are cut off, or the content might look like it's spilling out of the paper boundaries.

Cause:
The problem was happening because a part of the code, `PdfDocument.GetPage().RenderToStreamAsync()`, was being used without specifying certain rendering options (`PdfPageRenderOptions`). This meant the PDF page was being turned into an image stream using a default resolution (probably assuming 96 DPI for the PDF's original size) and wasn't taking into account the printer's actual DPI or your system's display scaling factor (`RawPixelsPerViewPixel`). Because of this, the `CanvasBitmap` created from this stream had pixel dimensions that didn't accurately match the intended physical size on paper when display scaling was active. This led to an incorrect layout by `CanvasPrintDocument`.

Solution:
I've made changes to the `LoadPDFPageBitmapsAsync` method in `Wino.Core.UWP/Services/PrintService.cs` to address this. Here's what I did:
1. I now get the printer's DPI from the `CanvasPrintDocument` (`sender.Dpi`).
2. I also get your current system display scaling factor (`DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel`).
3. For each page in your PDF, I calculate the target pixel dimensions needed to print the page at its correct physical size, using the printer's DPI.
4. Then, I figure out the necessary `DestinationWidth` and `DestinationHeight` (in DIPs) for `PdfPageRenderOptions` by dividing those target pixel dimensions by the `rawPixelsPerViewPixel`.
5. Finally, I call `PdfPage.RenderToStreamAsync()` using these calculated options.

This makes sure that the `CanvasBitmap` objects are created with pixel dimensions that are right for the printer's resolution and are correctly scaled according to your system's display settings. I ran some checks by simulating how this would work with display scaling at 100%, 125%, and 150%, and it confirmed that the calculations are now correct.
2025-05-20 18:48:21 +00:00
..
2025-02-16 11:54:23 +01:00
2025-02-22 00:22:00 +01:00
2025-05-20 18:48:21 +00:00