2014-02-10 4 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 должен открыть и просмотреть все файлы. Есть возможность отправить больше файлов для печатиDocument за один раз – 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 
Смежные вопросы