Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I have one Requirement in .net wpf.
There are some images in format of .gif or .jpg in a local folder.
i want to send all images in a folder to a printer in button click.
i searched google There for Printdocument 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 possible

Thanks..
Posted
Comments
Ahmed Bensaid 10-Feb-14 3:58am    
http://www.codeproject.com/Articles/27404/An-absolute-beginner-s-guide-to-printing-in-NET
http://www.codeproject.com/Articles/12450/Structured-Print-Document-utility

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900