【问题标题】:WPF/MVVM. Print multiple pictures in a single processWPF/MVVM。在一个过程中打印多张图片
【发布时间】:2018-09-27 08:20:32
【问题描述】:

我必须打印存储在目录中的所有图片。用户的要求是显示打印预览对话框,以便他们可以选择页面排列(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 {“找不到文件”}

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

【问题讨论】:

  • 您可以从Directory.GetFiles 迭代结果以打印文件夹中的所有文件。

标签: wpf mvvm printdialog


【解决方案1】:

你可以使用

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

在遍历文件路径以打印每个文件之后

【讨论】:

    【解决方案2】:

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

    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 打印 /D:HPColorLaserJetM553 C:\pic1.jpg C:\pic2.jpg

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

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

    【讨论】:

    • 也许我应该运行这样的东西:rundll32 shimgvw.dll ImageView_PrintTo /pt "C:\pic1.jpg" "HP Color LaserJet M553 PCL 6" 但是,如上所述,它只适用于一个文件, 打印过程以批处理模式开始。如何设置参数以使其适用于多张图片?
    【解决方案3】:

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

    rundll32 shimgvw.dll ImageView_PrintTo /pt "files[i]" "HP Color LaserJet M553 PCL 6"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多