Below is a sample code.
void PrintDocument(
HDC hPrinterDC,
HDC hMemoryDC,
int iSourceWidth,
int iSourceHeight
)
{
POINT destSize{};
destSize.x = iSourceWidth;
destSize.y = iSourceHeight;
double dMemoryDCX = GetDeviceCaps(hMemoryDC, LOGPIXELSX); double dMemoryDCY = GetDeviceCaps(hMemoryDC, LOGPIXELSY);
double dDeviceX = GetDeviceCaps(hPrinterDC, LOGPIXELSX); double dDeviceY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
double dScaleFactorX = dDeviceX / dMemoryDCX;
double dScaleFactorY = dDeviceY / dMemoryDCY;
destSize.x = static_cast<int>(destSize.x * dScaleFactorX);
destSize.y = static_cast<int>(destSize.y * dScaleFactorY);
DPtoLP(hPrinterDC, &destSize, 1);
StretchBlt(hPrinterDC,
0, 0, destSize.x, destSize.y, hMemoryDC, 0,0, iSourceWidth iSourceHeight, SRCCOPY);
}