【问题标题】:Send Multiple Documents To Printer将多个文档发送到打印机
【发布时间】:2014-02-10 07:50:43
【问题描述】:

我在 .net wpf 中有一个要求。 本地文件夹中有一些 .gif.jpg 格式的图像。 我准备了一个字符串列表,用于存储文件名 我想通过单击按钮将列表中的所有图像发送到打印机。

我在 Google 上搜索过,但对于打印文档,我们只能提供一个文件 PrintFileName。

但我想为每个循环提供每个文件名。任何人都可以解释这怎么可能?

谢谢..

【问题讨论】:

  • 我想您想将所有图像合并到一个打印文档中并将该打印文档发送到打印机?

标签: c# wpf vb.net printing


【解决方案1】:

题主好像错了... 回答;

var filenames = Directory.EnumerateFiles(@"c:\targetImagePath", "*.*", SearchOption.AllDirectories)
                        .Where(s => s.EndsWith(".gif") || s.EndsWith(".jpg") || s.EndsWith(".bmp"));
foreach (var filename in filenames)
{
    //use filename
}

【讨论】:

  • 您好,感谢您的回复。
  • 在我的要求中,只有第一次 printpreviewdialog 应该打开并预览所有文件。是否可以一次将更多文件发送到 printDocument
  • 是的。您可以使用 IDocumentPaginatorSource 打印它们。但是所有文件都添加到一个文档中并逐页打印。 code.msdn.microsoft.com/windowsdesktop/…
  • 谢谢,我会检查并回复
  • 嗨,Nuri YILMAZ 但是所有文件都添加到一个文档中并逐页打印我无法找到要添加到一个文档中的代码。你能解释一下如何将所有文件添加到一个文档中吗
【解决方案2】:
Private Sub btnPrint_Click(sender As Object, e As RoutedEventArgs) Handles btnPrint.Click
    Dim printDialog = New System.Windows.Controls.PrintDialog()
    If printDialog.ShowDialog = False Then
        Return
    End If
    Dim fixedDocument = New FixedDocument()
    fixedDocument.DocumentPaginator.PageSize = New System.Windows.Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight)
    For Each p In _lablefilenames
        Dim page As New FixedPage()
        Dim info As System.IO.FileInfo = New FileInfo(p)
        'If info.Extension.ToLower = ".gif" Then
        '    page.Width = fixedDocument.DocumentPaginator.PageSize.Height
        '    page.Height = fixedDocument.DocumentPaginator.PageSize.Width
        'Else
        page.Width = fixedDocument.DocumentPaginator.PageSize.Width
        page.Height = fixedDocument.DocumentPaginator.PageSize.Height
        'End If
        Dim img As New System.Windows.Controls.Image()
        ' PrintIt my project's name, Img folder
        'Dim uriImageSource = New Uri(p, UriKind.RelativeOrAbsolute)
        'img.Source = New BitmapImage(uriImageSource)
        Dim Bimage As New BitmapImage()
        Bimage.BeginInit()
        Bimage.CacheOption = BitmapCacheOption.OnLoad
        Bimage.UriSource = New Uri(p)
        If info.Extension.ToLower = ".gif" Then Bimage.Rotation += Rotation.Rotate90
        Bimage.EndInit()
        'img.Width = 100
        'img.Height = 100
        img.Source = Bimage
        page.Children.Add(img)
        Dim pageContent As New PageContent()
        DirectCast(pageContent, IAddChild).AddChild(page)
        fixedDocument.Pages.Add(pageContent)
    Next
    ' Print me an image please!
    printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Print")
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多