C# 将多个文档发送到打印机
我在.NETWPF中有一个要求。 在本地文件夹中有一些格式为.gif或.jpg的图像。 我准备了一个字符串列表,用于存储文件名 我想通过单击按钮将列表中的所有图像发送到打印机 我搜索过谷歌,但对于打印文档,我们只能给出一个文件PrintFileName 但是我想为每个循环指定每个文件名。有人能解释这是怎么可能的吗C# 将多个文档发送到打印机,c#,wpf,vb.net,printing,C#,Wpf,Vb.net,Printing,我在.NETWPF中有一个要求。 在本地文件夹中有一些格式为.gif或.jpg的图像。 我准备了一个字符串列表,用于存储文件名 我想通过单击按钮将列表中的所有图像发送到打印机 我搜索过谷歌,但对于打印文档,我们只能给出一个文件PrintFileName 但是我想为每个循环指定每个文件名。有人能解释这是怎么可能的吗 谢谢 问题的主题似乎是错的。。。 答复 您好,谢谢您的回复。根据我的要求,只有第一次printpreviewdialog才能打开并预览所有文件。是否有可能一次向printDocumen
谢谢 问题的主题似乎是错的。。。 答复
您好,谢谢您的回复。根据我的要求,只有第一次printpreviewdialog才能打开并预览所有文件。是否有可能一次向printDocument发送更多文件是的。您可以使用IDocumentPaginatorSource打印它们。但所有文件都添加到一个文档中并逐页打印。谢谢,我会检查并回复backHi,Nuri YILMAZ,但是所有文件都添加到一个文档中,并逐页打印。我找不到添加到一个文档中的代码。你能解释一下如何将所有文件添加到一个文档中吗?假设你想将所有图像合并到一个打印文档中,并将该打印文档发送到打印机?
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
}
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