Print .jpeg in vb.net

I want to print a .jpeg file (e.g c:\test.jpg) to the default printer from a push button in vb.net. I don't want to see dialog boxes.
adimitAsked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
Hi,
You can do something like this:

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Using printer As New Printing.PrintDocument
            AddHandler printer.PrintPage, AddressOf PrintImage
            printer.Print()
        End Using
    End Sub
 
    Private Sub PrintImage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
        Dim img As Image = Image.FromFile("c:\ImageToPrint.jpg")
        e.Graphics.DrawImage(img, 0, 0)
    End Sub

Open in new window

0
 
adimitAuthor Commented:
The above code works. How do I format the printout in terms of margins and orientations
0
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
In the PrintImage sub you can change the position, like this:

e.Graphics.DrawImage(img, 50, 50)
And the orientation you can do this way:

Using printer As New Printing.PrintDocument
      printer.DefaultPageSettings.Landscape = True
       ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.