2014-02-10 109 views
0

我在.net wpf中有一个要求。 部分图像格式为.gif.jpg在本地文件夹中。 我已经准备了一个字符串列表,用于存储文件名称 我希望将按列表中的所有图像发送到打印机。发送多个文档到打印机

我已经搜索了Google,但对于Print文档,我们只能给出一个文件PrintFileName。

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

谢谢..

+1

我想你想的所有图像PrintDocument的结合和发送的PrintDocument到打印机吗? – User999999

回答

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

嗨,谢谢你的回复。 – PullaReddy

+0

在我的要求中只有第一次printpreviewdialog应该打开并预览所有files.is有可能性发送更多的文件printDocument在一次 – PullaReddy

+0

是的。你可以使用IDocumentPaginatorSource来打印它们。但所有文件都会添加到一个文档中并逐页打印。 http://code.msdn.microsoft.com/windowsdesktop/WPF-Printing-Overview-f28c541a –

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