diff --git a/Elwig/Helpers/Printing/PdfPrintDocument.cs b/Elwig/Helpers/Printing/PdfPrintDocument.cs index b2bd528..59c2f64 100644 --- a/Elwig/Helpers/Printing/PdfPrintDocument.cs +++ b/Elwig/Helpers/Printing/PdfPrintDocument.cs @@ -9,15 +9,13 @@ namespace Elwig.Helpers.Printing { private readonly IntPtr _handle; private readonly int _pageCount; - private readonly double _dpi; private int _currentPage; - public PdfPrintDocument(string path, string? password = null, double dpi = 300.0) : + public PdfPrintDocument(string path, string? password = null) : base() { _handle = PdfiumNative.FPDF_LoadDocument(path, password); _pageCount = PdfiumNative.FPDF_GetPageCount(_handle); - _dpi = dpi; } protected override void Dispose(bool disposing) { @@ -35,8 +33,8 @@ namespace Elwig.Helpers.Printing { IntPtr page = PdfiumNative.FPDF_LoadPage(_handle, _currentPage); double width = PdfiumNative.FPDF_GetPageWidth(page); double height = PdfiumNative.FPDF_GetPageHeight(page); - int pixelWidth = (int)(width / 72.0 * _dpi); - int pixelHeight = (int)(height / 72.0 * _dpi); + int pixelWidth = (int)(width / 72.0 * (evt.Graphics?.DpiX ?? 300.0)); + int pixelHeight = (int)(height / 72.0 * (evt.Graphics?.DpiY ?? 300.0)); IntPtr bitmap = PdfiumNative.FPDFBitmap_Create(pixelWidth, pixelHeight, 1); PdfiumNative.FPDF_RenderPageBitmap(bitmap, page, 0, 0, pixelWidth, pixelHeight, 0, 0); @@ -44,7 +42,10 @@ namespace Elwig.Helpers.Printing { IntPtr buffer = PdfiumNative.FPDFBitmap_GetBuffer(bitmap); int stride = PdfiumNative.FPDFBitmap_GetStride(bitmap); using (var bmp = new Bitmap(pixelWidth, pixelHeight, stride, PixelFormat.Format32bppArgb, buffer)) { - evt.Graphics?.DrawImage(bmp, evt.PageBounds); + evt.Graphics?.TranslateTransform( + -evt.PageSettings.HardMarginX, + -evt.PageSettings.HardMarginY); + evt.Graphics?.DrawImage(bmp, new RectangleF(0, 0, (float)(width / 72.0 * 100.0), (float)(height / 72.0 * 100.0))); } _currentPage++;