Belini

Print photo using Autoit

20 posts in this topic

Share this post


Link to post
Share on other sites



Shellexecute("YouPhotoDisplayAndPrinting.exe","","","print")

Share this post


Link to post
Share on other sites

A polished version of AutoBert's reply:

Use ShellExecute with the $SHEX_PRINT verb, Example:

#include <AutoItConstants.au3>

Global Const $IMAGE = "C:\Users\TheDcoder\Pictures\TheDcoder.png" ; Location of the image file to print

ShellExecute($IMAGE, "", "", $SHEX_PRINT)

 

TD :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

@AutoBert Thus opened the print window and select the photo but not automatically printed the picture and I have more than one printer must then choose the printer instead of indicating the executable it!

Share this post


Link to post
Share on other sites

If that is the case then ShellExecute won't work for you, you need a more advanced code.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Try Irfanview. It has a nice command line interface that will let you do what you want.

Link

1 person likes this

Share this post


Link to post
Share on other sites

@TheDcoder The image was printed but opened the photoshop window before printing, I can print without associating the image to another program?

Spoiler

printing.jpg

@dmob I'll download Irfanview and I will experiment with it by command line!

Share this post


Link to post
Share on other sites

@Belini You would have to work with the print API in windows, I don't know much about it :unsure:

It would best if you follow @dmob's suggestion :).


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

also...

 

 

 

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#10 ·  Posted

@TheDcoder If I do not find another way I will try this option!

Thank @Chimp I'll read these topics you indicated!

Share this post


Link to post
Share on other sites

#11 ·  Posted

Good luck @Belini :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#12 ·  Posted

RunWait('Rundll32.exe "' & @SystemDir & '\mshtml.dll",PrintHTML "' & $tempFile & '"', @SystemDir) ;replace $tempFile with the file which should be printed

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

@UEZ This way does not automatically prints it opens the printer configuration box before printing!

Share this post


Link to post
Share on other sites
3 minutes ago, Belini said:

@UEZ This way does not automatically prints it opens the printer configuration box before printing!

Sorry, I misunderstood your issue. I thought you will be able to select the printer.

Currently I don't know how to send the file directly to the default printer.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

What about this here?

 

 

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

you could do this way:

Create a pdf file containing all the pictures you want to print and use SumatraPDF.exe to print the pdf file silently on a printer of your choice or on the default printer.

in short do like this:

  1. download SumatraPDF.exe (portable version) from herehttp://www.sumatrapdfreader.org/download-free-pdf-viewer.html and save the exe to your script dir. This is a very nice tool that allows also to print pdf files silently. (moer command line arguments here: https://github.com/sumatrapdfreader/sumatrapdf/wiki/Command-line-arguments)
  2. Download this very nice UDF from here: and save it to your script dir (this is used to create the pdf that contains the images to be printed)
  3. use this draft script posted here as an example to see how to print silently one ore more pictures of your choice.
    #include "MPDF_UDF.au3"
    
    _SelectImages() ; select images and create a temporary pdf file containing all the selected images
    
    ; now print selected images silently using sumatraPDF.exe
    Run(@ScriptDir & '\SumatraPDF.exe -silent -print-to-default ' & @ScriptDir & "\Image2PDF.pdf", "", @SW_HIDE)
    ; use -print-to "printername" to select another printer
    
    ; delete temporary file
    ; FileDelete (@ScriptDir & "\Image2PDF.pdf" )
    
    Func _SelectImages()
        Local $var = FileOpenDialog("Select images", @ScriptDir & "\", "Images (*.jpg;*.bmp;*gif;*png;*tif;*ico)", 4)
        If @error Then
            MsgBox(4096, "", "No File(s) chosen")
            Exit
        Else
            If not StringInStr($var, '|') Then ; only one file selected
                $var = StringReplace($var, '\', '|', -1)
            EndIf
        EndIf
        Local $aImgs = StringSplit($var, "|", 3)
        Local $aIMG_Params
    
        ;set the properties for the pdf
        _SetTitle("Image2PDF")
        _SetSubject("Convert image(s) to pdf")
        _SetKeywords("pdf, AutoIt")
        _OpenAfter(True);open after generation
    
        _SetUnit($PDF_UNIT_PT) ; 1
        _SetPaperSize("a4")
        _SetZoomMode($PDF_ZOOM_CUSTOM, 100)
        _SetOrientation($PDF_ORIENTATION_PORTRAIT)
        _SetLayoutMode($PDF_LAYOUT_CONTINOUS)
    
        ;initialize the pdf
        FileDelete(@ScriptDir & "\Image2PDF.pdf")
        _InitPDF(@ScriptDir & "\Image2PDF.pdf")
    
    
        ;=== load resources (images) used in pdf ===
        For $i = 1 To UBound($aImgs) - 1
            $aIMG_Params = _LoadResImage_MOD("img" & $i, $aImgs[0] & "\" & $aImgs[$i])
    
            _BeginPage() ; load each image on it's own page
    
            ;scale factors
            $iScaleFactorX = _GetPageWidth() / $aIMG_Params[1]
            $iScaleFactorY = _GetPageHeight() / $aIMG_Params[2]
    
            if $iScaleFactorX >= 1 And $iScaleFactorY >= 1 Then ; The image is smaller than the sheet, no need to rescale
                _InsertImage("img" & $i, ( _GetPageWidth() - $aIMG_Params[1]) / 2, (_GetPageHeight() - $aIMG_Params[2]) / 2) ; center image in the page
            Else ; the image is bigger than the sheet, it needs to be reduced to fit (maintaining proportions)
                If $iScaleFactorX < $iScaleFactorY Then
                    $iScale = $iScaleFactorX
                Else
                    $iScale = $iScaleFactorY
                EndIf
                _InsertImage("img" & $i, ( _GetPageWidth() - $aIMG_Params[1] * $iScale) / 2, (_GetPageHeight() - $aIMG_Params[2] * $iScale) / 2, $aIMG_Params[1] * $iScale, $aIMG_Params[2] * $iScale) ; Rescale and center image in the page
            EndIf
            _EndPage()
        Next
    
        ; finally, write the buffer to disk
        _ClosePDFFile()
    EndFunc   ;==>_SelectImages
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _LoadResImage
    ; Description ...: Load a image in the pdf (if you use it multiple times it decreases the size of the pdf)
    ; Syntax ........: _LoadResImage( $sImgAlias , $sImage  )
    ; Parameters ....: $sImgAlias           -  an alias to identify the image in the pdf (e.g. "Cheese").
    ;                  $sImage              -  image path.
    ; Return values .: Success      - True
    ;                  Failure      - False
    ; Author(s) .....: Mihai Iancu (taietel at yahoo dot com)
    ; Modified ......: By Cimp (returns an 3 element array where: [0]$_Image , [1] $_iImageW , [2] $_iImageH instead of just $_Image
    ; Remarks .......: Image types accepted: BMP, GIF, TIF, TIFF, PNG, JPG, JPEG (those are tested)
    ; Related .......:
    ; Link ..........: http://www.autoitscript.com/forum/topic/118827-create-pdf-from-your-application/
    ; Example .......: No
    ; ===============================================================================================================================
    Func _LoadResImage_MOD($sImgAlias, $sImage)
        Local $iW, $iH, $ImgBuf, $hImage, $hImageExt, $newImg, $hClone, $hGraphics, $iObj, $aReturn[3]
        If $sImgAlias = "" Then __Error("You don't have an alias for the image", @ScriptLineNumber)
        If $sImage = "" Then
            __Error("You don't have any images to insert or the path is invalid", @ScriptLineNumber)
        Else
            $hImageExt = StringUpper(StringRight($sImage, 3))
            $newImg = _TempFile(@ScriptDir, "~", ".jpg")
            Switch $hImageExt
                Case "BMP", "GIF", "TIF", "TIFF", "PNG", "JPG", "JPEG", "ICO"
                    _GDIPlus_Startup()
                    $hImage = _GDIPlus_ImageLoadFromFile($sImage)
                    $iW = _GDIPlus_ImageGetWidth($hImage)
                    $iH = _GDIPlus_ImageGetHeight($hImage)
                    $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iW, $iH, $GDIP_PXF24RGB)
                    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hClone)
                    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
                    _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)
                    _GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
                    _GDIPlus_ImageSaveToFile($hClone, $newImg)
                    $ImgBuf = __ToBinary($newImg)
                    $_iImageW = $iW
                    $_iImageH = $iH
                    $iObj = __InitObj()
                    __ToBuffer("<</Type /XObject /Subtype /Image /Name /" & $sImgAlias & " /Width " & $_iImageW & " /Height " & $_iImageH & " /Filter /DCTDecode /ColorSpace /DeviceRGB /BitsPerComponent 8" & Chr(10) & "/Length " & StringLen($ImgBuf) & ">>stream")
                    __ToBuffer($ImgBuf)
                    __ToBuffer("endstream")
                    __EndObj()
                    $_Image &= "/" & $sImgAlias & " " & $iObj & " 0 R " & Chr(10)
                    __InitObj()
                    __ToBuffer(StringLen($ImgBuf))
                    __EndObj()
                    _GDIPlus_ImageDispose($hImage)
                    _GDIPlus_GraphicsDispose($hGraphics)
                    _GDIPlus_BitmapDispose($hClone)
                    _GDIPlus_Shutdown()
                    FileDelete($newImg)
                Case Else
                    __Error("The image is invalid", @ScriptLineNumber)
                    Exit
            EndSwitch
        EndIf
        ; Return $_Image
        $aReturn[0] = $_Image
        $aReturn[1] = $_iImageW
        $aReturn[2] = $_iImageH
        Return $aReturn
    EndFunc   ;==>_LoadResImage_MOD
    
    Func _Iif($vExpression, $vTrue, $vFalse)
        Return $vExpression ? $vTrue : $vFalse
    EndFunc   ;==>_Iif

     

 

This script uses a little modified version of the function _LoadResImage() from the MPDF_UDF.au3.

if you use an old version of AutoIt and get an error about the _Iif() function then just rename or delete the _Iif() function located at the end of this script.

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

You can also try using IrfanView with command line options.  You can use the /print or the /print="Name" options.  From the IrfanView help file.  

Quote

/print -        print input image to default printer and close IrfanView 

/print="Name" -        print input image to specific printer and close IrfanView 

- Wildcards supported only for /convert, /multitif, /multipdf, /panorama, /print, /info, /jpg_rotate and /extract.
- Most settings are loaded from the INI file. Using prepared INIs and /ini=folder option, you can extend the possibilities.

Example for /print:

i_view32.exe c:\test.jpg /print

Open 'c:\test.jpg', print the image to default printer and close IrfanView.

i_view32.exe c:\test.jpg /print="Printer Name"

Open 'c:\test.jpg', print the image to specific printer and close IrfanView.

i_view32.exe c:\*.jpg /print

Print all JPGs from "C:\" and close IrfanView.

Note: The actual settings from the INI file are used.

You can be run without installation, download the ZIP.  Irfanview is available in 32 and 64 bit.  

 

Adam

1 person likes this

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Thank @dmob and @AdamUL by IrfanView's tip because he solved my problem!


@Chimp I chose to use IrfanView because he did not need to create a PDF of the images but thank you very much for the tips you gave me!

Edited by Belini
1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now