首页 文章

将多个文档发送到打印机

提问于
浏览
0

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

我搜索过Google但是对于Print文档,我们只能提供一个文件PrintFileName .

但我想为每个循环提供每个文件名 . 任何人都可以解释它是如何可能的?

谢谢..

2 回答

  • 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
    }
    
  • 0
    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
    

相关问题