Reputation: 25
I have to print all pictures stored in a directory. Users' request is that the print preview dialog should be displayed so that they can choose the page arrangement (see picture). I tried to use the Process tool, but it works only for one file. Here is the code:
Dim info As New ProcessStartInfo()
info.Verb = "print"
info.FileName = "C:\Pictures\pic1.jpg"
info.LoadUserProfile = True
Dim p As New Process()
Try
p.StartInfo = info
p.Start()
p.WaitForExit()
System.Threading.Thread.Sleep(3000)
If False = p.CloseMainWindow() Then
p.Kill()
End If
Catch i As System.InvalidOperationException
System.Threading.Thread.Sleep(100)
End Try
This works. When I try to set info.FileName to "C:\Pictures\pic1.jpg C:\Pictures\pic2.jpg", or "[pic1];[pic2]", or "."; but I always get the error message
System.ComponentModel.Win32Exception {"could not find file"}
How can I configure it to select all files in the directory?
Upvotes: 0
Views: 178
Reputation: 11
Store all files path in a string[]
or char[][]
(Array of string)
then loop this instruction:
rundll32 shimgvw.dll ImageView_PrintTo /pt "files[i]" "HP Color LaserJet M553 PCL 6"
Upvotes: 0
Reputation: 25
I got to print by looping on directory files. But this causes print process to run in authomatic mode, and one for every file to be printed. This is not what I need: i wish to simulate the multiselection and printing. I tried to run the "print" command in the Windows command shell
Dim pr As New System.Windows.Controls.PrintDialog
Dim myprinter = pr.PrintQueue.QueuePort.Name
Dim files = "C:\pic1.jpg C:\pic2.jpg"
Dim command = String.Format("/C print /D:{0} {1}", myprinter, files)
info.FileName = "cmd.exe"
info.Arguments = command
the command string generated is
/C print /D:HPColorLaserJetM553 C:\pic1.jpg C:\pic2.jpg
which doesnt work, even if the process ends without apparent errors. If i try to run the command string from windows shell, I get the error
"could not initialize the device D:HPColorLaserJetM553"
Upvotes: 0
Reputation: 17017
you could use
using System.IO;
:
:
string[] filePaths = Directory.GetFiles(@"c:\Pictures\", "*.jpg");
and after just iterate through filepaths to print each file
Upvotes: 1