Link to home
Start Free TrialLog in
Avatar of willemaw
willemaw

asked on

How to print a tiff from the command line? (shimgvw.dll)

I need to be able to print a tiff from the command line.  Currently I have kodakimg.exe installed and it works fine for printing tiffs from the command line (kodakimg.exe /p "filename.tiff").  However for another implementation I need to be able to print using only default Windows XP applications.  I can display tiffs from the command line using the following call:
rundll32.exe C:\WINDOWS\System32\shimgvw.dll, ImageView_FullScreen  "filename.tiff"

However the ImageView_PrintTo call needs 4 arguments, while the FullScreen call only requires on.
Would anyone know what the other 4 arguments are so I can print from the command line with a call like:
rundll32.exe C:\WINDOWS\System32\shimgvw.dll, ImageView_PrintTo  "filename.tiff" arg2 arg3 arg4

what should I put for the last 3 arguments?

Thanks in advance
-willem

Avatar of CrazyOne
CrazyOne
Flag of United States of America image

Try this

rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "%1" "%2" "%3" "%4"
Avatar of willemaw
willemaw

ASKER

I don't see how that will let me print from the command line, doesn't windows need to have values for to fill in for the %#'s?  If i try:

rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "%1" "%2" "%3" "%4"  filename.tiff

The Windows Picture and Fax Viewer simply pops up.  If i replace either %1 or %4 or any of other other args with the filename.tiff the the command simply returns without doing anything.  I was hoping to find out what i need to enter in as the values for each of the %#'s.
Because for the:
rundll32.exe C:\WINDOWS\System32\shimgvw.dll, ImageView_FullScreen  "filename.tiff"

call, the %1 is replaced with filename.tiff (if you look at the file type properties for tiff viewing it'll have:
rundll32.exe C:\WINDOWS\System32\shimgvw.dll, ImageView_FullScreen "%1"

So following similiar logic I would need to have 4 args for the PrintTo call...
-willem
c:\windows\system32>mspaint.exe/p new-1.tif

will print to your default printer
Another good idea which I've tried, however mspain does not scale tiff files down to their correct size and simply prints out the raw data (like Windows Picture and Fax Viewer does), the same problem is prevelent with PhotoEd.exe.  And another problem with using mspaint.exe and photoed.exe is that they do not support multi-page tiff's (Which almost all the files i'm dealing with are).  Therefore I need to use a well written tiff program (not that Windows Picture and Fax Viewer is well written, i much prefer wangimg.exe or kodakimg.exe but those are not available with the default install of XP).  
So I think my only option is still to figure out what arguments "shimgvw.dll, ImageView_PrintTo" uses.

-willem
ASKER CERTIFIED SOLUTION
Avatar of pbarrette
pbarrette

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, yeah that's exactly what I needed.  I did look at that knowledge base entry but must of skimmed over that part.
Thanks a lot!
-willem
...

C?

pb
For a complete answer to the above question, as even with the good advice above it took and hour to add glue to make it all work.

The command line is:

rundll32.exe %SystemRoot%\System32\shimgvw.dll,ImageView_PrintTo /pt "<putyourfilenamehereinquotes>" "<putyourprinternamehereinquotes" "" ""

The /pt stands for PrintTo

As the MS article vaguely explains, the 4 arguments are 2 required and 2 legacy from Windows 3.1, thus the last two only need to be 'there' but empty

1st argument is the file name in quotes for long file name with spaces
2nd argument is the printer name in quotes
3rd not used
4th not used

The first is the full path to the file in quotes
The 2nd argument is your printer in the form "\\computername\sharename"

I had to replace the %systemroot% with c:\windows when using the Shell command

Here is the VBA code I used to prep the Shell

Private Sub PrintGraphics(uImagePath As String)

    Dim retval
    Dim uexeline As String
    Dim uPrinterName as string

   uPrinterName = "\\Server\Share"
       
    If IsNull(uImagePath) = False Then
        If Trim(uImagePath) <> "" Then
             uexeline = "rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt " & Chr(34) & uImagePath & Chr(34) & _
         " " & Chr(34) &  uPrinterName  & Chr(34) & " " & Chr(34) & Chr(34) & " " & Chr(34) & Chr(34)
        Debug.Print uexeline
            retval = Shell(uexeline, vbHide)
           
        End If
    End If
End Sub

My actual uExelilne was:

rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_PrintTo /pt "\\Oak\shopfloor\Prints\No Print.tif" "\\oak\HP_OFFICE_PRINTER" "" ""

Worked like a charm