This commit is contained in:
@@ -52,21 +52,10 @@ namespace Elwig.Helpers.Printing {
|
|||||||
throw new InvalidOperationException($"Unable to load PDF page {pageIndex}.");
|
throw new InvalidOperationException($"Unable to load PDF page {pageIndex}.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// PDF coordinates are points (1/72 inch).
|
int renderWidth = (int)Math.Round(pageWidthPt / 72.0 * printer.DpiX);
|
||||||
//
|
int renderHeight = (int)Math.Round(pageHeightPt / 72.0 * printer.DpiY);
|
||||||
// HORZRES/VERTRES are the printable area in
|
int offsetX = (printer.PrintableWidth - renderWidth) / 2;
|
||||||
// device pixels for the current printer DC.
|
int offsetY = (printer.PrintableHeight - renderHeight) / 2;
|
||||||
int widthPx = printer.PixelWidth;
|
|
||||||
int heightPx = printer.PixelHeight;
|
|
||||||
|
|
||||||
// Preserve aspect ratio.
|
|
||||||
double scaleX = widthPx / pageWidthPt;
|
|
||||||
double scaleY = heightPx / pageHeightPt;
|
|
||||||
double scale = Math.Min(scaleX, scaleY);
|
|
||||||
int renderWidth = Math.Max(1, (int)Math.Round(pageWidthPt * scale));
|
|
||||||
int renderHeight = Math.Max(1, (int)Math.Round(pageHeightPt * scale));
|
|
||||||
int offsetX = (widthPx - renderWidth) / 2;
|
|
||||||
int offsetY = (heightPx - renderHeight) / 2;
|
|
||||||
|
|
||||||
printer.StartPage();
|
printer.StartPage();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ namespace Elwig.Helpers.Printing {
|
|||||||
private const int VERTRES = 10;
|
private const int VERTRES = 10;
|
||||||
private const int LOGPIXELSX = 88;
|
private const int LOGPIXELSX = 88;
|
||||||
private const int LOGPIXELSY = 90;
|
private const int LOGPIXELSY = 90;
|
||||||
|
private const int PHYSICALWIDTH = 110;
|
||||||
|
private const int PHYSICALHEIGHT = 111;
|
||||||
|
private const int PHYSICALOFFSETX = 112;
|
||||||
|
private const int PHYSICALOFFSETY = 113;
|
||||||
|
|
||||||
private const int DM_DUPLEX = 0x1000;
|
private const int DM_DUPLEX = 0x1000;
|
||||||
private const short DMDUP_SIMPLEX = 1;
|
private const short DMDUP_SIMPLEX = 1;
|
||||||
@@ -129,10 +133,14 @@ namespace Elwig.Helpers.Printing {
|
|||||||
|
|
||||||
public IntPtr Hdc => _hdc;
|
public IntPtr Hdc => _hdc;
|
||||||
|
|
||||||
public int PixelWidth => GetDeviceCaps(_hdc, HORZRES);
|
public int PrintableWidth => GetDeviceCaps(_hdc, HORZRES);
|
||||||
public int PixelHeight => GetDeviceCaps(_hdc, VERTRES);
|
public int PrintableHeight => GetDeviceCaps(_hdc, VERTRES);
|
||||||
public int DpiX => GetDeviceCaps(_hdc, LOGPIXELSX);
|
public int DpiX => GetDeviceCaps(_hdc, LOGPIXELSX);
|
||||||
public int DpiY => GetDeviceCaps(_hdc, LOGPIXELSY);
|
public int DpiY => GetDeviceCaps(_hdc, LOGPIXELSY);
|
||||||
|
public int PhysicalWidth => GetDeviceCaps(_hdc, PHYSICALWIDTH);
|
||||||
|
public int PhysicalHeight => GetDeviceCaps(_hdc, PHYSICALHEIGHT);
|
||||||
|
public int PhysicalOffsetX => GetDeviceCaps(_hdc, PHYSICALOFFSETX);
|
||||||
|
public int PhysicalOffsetY => GetDeviceCaps(_hdc, PHYSICALOFFSETY);
|
||||||
|
|
||||||
public Printer(string printerName) {
|
public Printer(string printerName) {
|
||||||
_printerName = printerName;
|
_printerName = printerName;
|
||||||
|
|||||||
Reference in New Issue
Block a user