12

My program needs to print a curve; my solution is changing the curve into a picture, and this picture file (xxx.png) can be printed by using the default windows picture printing tool (right click the mouse on top of the file, and select print).

but I don't want user do this job manually, I need a command line tool to do this:

printPicture xxx.png

How can I do this in command line?

M--
  • 25,431
  • 8
  • 61
  • 93
linjunhalida
  • 4,538
  • 6
  • 44
  • 64

6 Answers6

14

This link had a simpler solution:

mspaint /pt [image filename]
aross
  • 3,325
  • 3
  • 34
  • 42
ulatekh
  • 1,311
  • 1
  • 14
  • 19
  • 1
    thank you, save my life. this is very cool, i coding it on my python django app: cmd = f'mspaint /pt {filename}' p = subprocess.Popen(cmd, shell=True) p.wait() – rogers.wang Apr 20 '20 at 15:06
  • Unfortunately, it does not seem that mspaint allows you to set default printing settings yourself. – knowledge_seeker Jun 28 '21 at 19:27
14

I finally found out!

use windows image and fax viewer.

rundll32    shimgvw.dll    ImageView_PrintTo /pt   xxx.png   "printer name"
Joey
  • 344,408
  • 85
  • 689
  • 683
linjunhalida
  • 4,538
  • 6
  • 44
  • 64
  • 1
    Careful, you can't give any options with this solution, and you can't change default options (picture will be fitted to A4). – Jerry Nov 21 '17 at 13:21
  • how to print in 8mm paper ? – Criss Sep 01 '19 at 23:45
  • 1
    No clue why, but this doesn't work for me on a Windows 10 desktop. Neither does the `print` command (with a txt file). I had to resort to mspaint... which is acceptable I guess – aross Feb 19 '20 at 13:25
11

IrfanView is able to do this. Here's a list of command line options for this application.

The following should work:

i_view32 xxx.png /print

If you want to print to a printer other than the default printer, specify the printer name:

i_view32 xxx.png /print="PrinterName"
Gamopo
  • 1,600
  • 1
  • 14
  • 22
Charlie Salts
  • 13,109
  • 7
  • 49
  • 78
  • 3
    You asked for a command line tool... that's what I've posted. How you use this in your application is up to you - you're the developer! – Charlie Salts Feb 20 '10 at 05:44
  • This rocks ! irfanView keep your last printing options. When you call it to print a picture through command line, it uses last printing options. It's perfect. – Jerry Nov 21 '17 at 13:32
  • 1
    Great!!! It works perfect. First we need to install inrfan_view from here http://www.irfanview.com/ and then run this command in windows **`& 'C:\Program Files\IrfanView\i_view64.exe' .\test_image.png /print`** – Sunny Chaudhari Feb 02 '19 at 05:46
1
rundll32 C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo "c:\mydir\my.bmp" "Fictional HP Printer"
loop
  • 825
  • 6
  • 15
0
rundll32 C:\WINDOWS\system32\shimgvw.dll,ImageView_PrintTo "c:\mydir\my.bmp" "Fictional HP Printer"

This prints an image file (.png in my case) to a specified printer WITHOUT a dialog box popping up. Also... works without elevated command prompt privileges.

Martin Serrano
  • 3,727
  • 1
  • 35
  • 48
Rodney
  • 9
  • 1
-1

You can call ShellExecute from your program with print operation:

ShellExecute(NULL,"print","c:\\test.png",NULL,NULL,SW_HIDE);
Carlos Gutiérrez
  • 13,972
  • 5
  • 37
  • 47