• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

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.
0
adimit
Asked:
adimit
  • 2
2 Solutions
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now