WPF / MVVM。在一个过程中打印多张图片

问题描述 投票:0回答:3

我必须打印存储在目录中的所有图片。用户的要求是要显示打印预览对话框,以便他们可以选择页面排列(see picture)。我尝试使用Process工具,但它只适用于一个文件。这是代码

                        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

这有效。当我尝试将info.FileName设置为“C:\ Pictures \ pic1.jpg C:\ Pictures \ pic2.jpg”或“[pic1]; [pic2]”或“。”;但我总是得到错误信息

System.ComponentModel.Win32Exception {“找不到文件”}

如何配置它以选择目录中的所有文件?谢谢

wpf mvvm printdialog multifile
3个回答
0
投票

你可以用

using System.IO;
:
:
string[] filePaths = Directory.GetFiles(@"c:\Pictures\", "*.jpg");

并且只需遍历文件路径即可打印每个文件


0
投票

我通过循环目录文件来打印。但这会导致打印过程在authomatic模式下运行,并且每个文件都要打印一个。这不是我需要的:我希望模拟多选和打印。我试图在Windows命令shell中运行“print”命令

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

生成的命令字符串是

/ C print / D:HPColorLaserJetM553 C:\ pic1.jpg C:\ pic2.jpg

这不起作用,即使过程结束没有明显的错误。如果我尝试从Windows shell运行命令字符串,我收到错误

“无法初始化设备D:HPColorLaserJetM553”


0
投票

将所有文件路径存储在string[]char[][](字符串数组)中,然后循环此指令:

rundll32 shimgvw.dll ImageView_PrintTo /pt "files[i]" "HP Color LaserJet M553 PCL 6"
© www.soinside.com 2019 - 2024. All rights reserved.