0

I have one Requirement in .net wpf. There are some images in format of .gif or .jpg in a local folder. I have prepared one List of string , to store file names i want to send all images in a list to a printer in button click.

I have searched Google but for Print document we can give only one file PrintFileName.

But i want to give each file name in for each loop . any one can explain how is it possible?

Thanks..

Tithi Patel
  • 777
  • 4
  • 21
PullaReddy
  • 13
  • 3
  • 1
    I suppose you want to combine all images in one printdocument and send that printdocument to the printer? – User999999 Feb 10 '14 at 08:11

2 Answers2

1

question subject is look like wrong... answer;

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
}
Nuri YILMAZ
  • 4,291
  • 5
  • 37
  • 43
  • in my requirement only first time printpreviewdialog should open and preview all the files.is there posibility to send more files to printDocument at a time – PullaReddy Feb 10 '14 at 08:11
  • yes. you can print them using IDocumentPaginatorSource. but all files add in one document and print page by page. http://code.msdn.microsoft.com/windowsdesktop/WPF-Printing-Overview-f28c541a – Nuri YILMAZ Feb 10 '14 at 08:18
  • Thanks, i will check and reply back – PullaReddy Feb 10 '14 at 08:20
  • Hi, Nuri YILMAZ **but all files add in one document and print page by page** i am unable to find the code to add in to one document . can you please explain how to add all files to one document please – PullaReddy Feb 10 '14 at 12:37
  • you could use this link for paginator implementation http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/wpf/src/Core/CSharp/System/Windows/Documents/DocumentPaginator@cs/1305600/DocumentPaginator@cs and after that you can implement getPage method with this link answer http://stackoverflow.com/questions/7825056/blank-pages-when-implementing-documentpaginator – Nuri YILMAZ Feb 10 '14 at 15:08
  • Hi i got solution in the below link.http://stackoverflow.com/questions/11853096/adding-image-to-fixedpage-in-wpf – PullaReddy Feb 11 '14 at 06:56
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
LaurentG
  • 11,128
  • 9
  • 51
  • 66
PullaReddy
  • 13
  • 3