Hello All,
I've been looking at using PrintWinAPI.au3 to print images.
Many thanks to the excellent thread started by GRS (link below) which got me started.
http://www.autoitscript.com/forum/topic/73993-printing-from-autoit/page__p__538661__fromsearch__1#entry538661
My issue is when I print, any device ICC assigned to the printer in windows is not used?!
I'm starting to believe I need to apply the ICC to the image before sending to the printer.
The following article suggest to me that it's possible but not simple: http://support.microsoft.com/kb/317825
Has anyone looked into this before? I can't find any existing thread that covers this.
Many thanks
Below is the print function I'm using for testing; you need to change the printer name.
I've been looking at using PrintWinAPI.au3 to print images.
Many thanks to the excellent thread started by GRS (link below) which got me started.
http://www.autoitscript.com/forum/topic/73993-printing-from-autoit/page__p__538661__fromsearch__1#entry538661
My issue is when I print, any device ICC assigned to the printer in windows is not used?!
I'm starting to believe I need to apply the ICC to the image before sending to the printer.
The following article suggest to me that it's possible but not simple: http://support.microsoft.com/kb/317825
Has anyone looked into this before? I can't find any existing thread that covers this.
Many thanks
Below is the print function I'm using for testing; you need to change the printer name.
[ autoit ]
#Include <PrintWinAPI.au3> Local $sPrinterName = "Printer Name as found in 'Devices and Printers'"; edit accordingly Local $sfilePath = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.bmp;*.gif;*.tif)", 3) _PrintImage($sfilePath, $sPrinterName,1) Func _PrintImage($sfile, $sPrinterName, $iResize = 2, $autoRotate = True) Local $hPrintDC, $hImage Local $jobInc = 0 If Not FileExists($sfile) Then Return $hPrintDC = _WinAPI_CreateDC("winspool", $sPrinterName) $dividerH = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_LOGPIXELSY)/100; not sure if I have these the right way round $dividerW = _WinAPI_GetDeviceCaps($hPrintDC, $__WINAPICONSTANT_LOGPIXELSX)/100 $PageWidth = _WinAPI_GetDeviceCaps($hPrintDC, $HORZRES); Get width, in millimeters, of the physical page $PageHeight = _WinAPI_GetDeviceCaps($hPrintDC, $VERTRES); Get height, in millimeters, of the physical page $PageRatio = $PageHeight/$PageWidth ; setup docinfo $s_DocName = "Test_" & $jobInc $DocName = DllStructCreate("char DocName[" & StringLen($s_DocName & chr(0)) & "]") DllStructSetData($DocName, "DocName", $s_DocName & chr(0)); Size of DOCINFO structure $DOCINFO = DllStructCreate($tagDOCINFO); Structure for Print Document info DllStructSetData($DOCINFO, "Size", 20); Size of DOCINFO structure DllStructSetData($DOCINFO, "DocName", DllStructGetPtr($DocName)); Set name of print job (Optional) ;Start the Document $result = _WinAPI_StartDoc($hPrintDC, $DOCINFO) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sfile) If $hImage = 0 Or $hImage = -1 Then Return ; Skip if Image file not loaded $result += _WinAPI_StartPage($hPrintDc) $iImageW = _GDIPlus_ImageGetWidth($hImage) $iImageH = _GDIPlus_ImageGetHeight($hImage) $iImageRatio = $iImageH/$iImageW If $autoRotate Then $rotate = False If $PageRatio > 1 and $iImageRatio < 1 Then $rotate = True ElseIf $PageRatio < 1 and $iImageRatio > 1 Then $rotate = True EndIf If $rotate Then DllCall($ghGDIPDll, "int", "GdipImageRotateFlip", "hwnd", $hImage, "long", 1); rotate 270 degrees $iImageW = _GDIPlus_ImageGetWidth($hImage) $iImageH = _GDIPlus_ImageGetHeight($hImage) $iImageRatio = $iImageH/$iImageW EndIf EndIf If $iResize = 0 Then ; 2 = fill (Default) $ImageResizeRatio = 1 ElseIf $iResize = 1 Then ; 1 = fit If $PageRatio > $iImageRatio Then; Image more square than paper - resize to fit height (Potrait!!!) $ImageResizeRatio = $iImageW/$PageWidth Else $ImageResizeRatio = $iImageH/$PageHeight EndIf Else ; fill (Default If $PageRatio > $iImageRatio Then; Image more square than paper - resize to fit height (Potrait!!!) $ImageResizeRatio = $iImageH/$PageHeight Else $ImageResizeRatio = $iImageW/$PageWidth EndIf EndIf $w = Int($iImageW/$ImageResizeRatio) $h = Int($iImageH/$ImageResizeRatio) $ImageOffsetH = Int(($PageHeight - $h)/2) $ImageOffsetW = Int(($PageWidth - $w)/2) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hPrintDC) _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage, $ImageOffsetW/$dividerW, $ImageOffsetH/$dividerH, $w/$dividerW, $h/$dividerH) $result += _WinAPI_EndPage($hPrintDC) $result = _WinAPI_EndDoc($hPrintDC) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_BitmapDispose($hImage) _GDIPlus_Shutdown () _WinAPI_DeleteDC($hPrintDC) Endfunc