473,412 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

print a .jpg image from vb .net

I have the following code which I was using to print .pdf's. It worked fine
and actually printed the pdf file.

Now I want to use the same code to print a .jpg file. When I run the code,
it launches the 'Windows Picture and Fax viewer application' and DOES NOT
print the actual image.

Is there a tweak to this code or is there some other code I can use to print
a specified .jpg file directly from within my .net application???

PS.. I hardcoded the image name in here for testing purposes only and I am
simply using teh default printer.

Here is the code..
--------------------------------------------------------
Dim iCopies As Integer

Dim x As Integer

' Ask user for number of copies they want printed

iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate Drawing",
"3"))

Dim psi As New ProcessStartInfo()

For x = 1 To iCopies

With psi

..Verb = "print"

..WindowStyle = ProcessWindowStyle.Hidden

..FileName = "C:\image.jpg"

..UseShellExecute = True

End With

Process.Start(psi)

Next x

Thanks, Brad
Mar 9 '07 #1
5 21155
Brad,

Why not use the PrintDocument control..? You can then pass the name etc.

--
Newbie Coder
(It's just a name)

============================
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I have the following code which I was using to print .pdf's. It worked
fine
and actually printed the pdf file.

Now I want to use the same code to print a .jpg file. When I run the code,
it launches the 'Windows Picture and Fax viewer application' and DOES NOT
print the actual image.

Is there a tweak to this code or is there some other code I can use to
print
a specified .jpg file directly from within my .net application???

PS.. I hardcoded the image name in here for testing purposes only and I am
simply using teh default printer.

Here is the code..
--------------------------------------------------------
Dim iCopies As Integer

Dim x As Integer

' Ask user for number of copies they want printed

iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate Drawing",
"3"))

Dim psi As New ProcessStartInfo()

For x = 1 To iCopies

With psi

.Verb = "print"

.WindowStyle = ProcessWindowStyle.Hidden

.FileName = "C:\image.jpg"

.UseShellExecute = True

End With

Process.Start(psi)

Next x

Thanks, Brad


Mar 9 '07 #2
Hmmm, every time I see sample code on this control, it has never ever showed
being able to simply pass a document name to the control.

I will look closer at it though... Do you have any source code that
specifically shows how to go about printing an existing document using that
control?? If so, I would love to see it!!

THanks, Brad

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
Brad,

Why not use the PrintDocument control..? You can then pass the name etc.

--
Newbie Coder
(It's just a name)

============================
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have the following code which I was using to print .pdf's. It worked
fine
>and actually printed the pdf file.

Now I want to use the same code to print a .jpg file. When I run the
code,
it launches the 'Windows Picture and Fax viewer application' and DOES NOT
print the actual image.

Is there a tweak to this code or is there some other code I can use to
print
>a specified .jpg file directly from within my .net application???

PS.. I hardcoded the image name in here for testing purposes only and I
am
simply using teh default printer.

Here is the code..
--------------------------------------------------------
Dim iCopies As Integer

Dim x As Integer

' Ask user for number of copies they want printed

iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate
Drawing",
"3"))

Dim psi As New ProcessStartInfo()

For x = 1 To iCopies

With psi

.Verb = "print"

.WindowStyle = ProcessWindowStyle.Hidden

.FileName = "C:\image.jpg"

.UseShellExecute = True

End With

Process.Start(psi)

Next x

Thanks, Brad



Mar 9 '07 #3
This code should do it. However, the printed image may be distorted if you
don't first resize it to fit the target page size.

Private Sub PrintImage_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrintImage.Click
If Me.PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
Try
AddHandler Me.PrintDocument1.PrintPage, AddressOf
Me.GraphicPrint
Me.PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub

Private Sub GraphicPrint(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
Dim imagePrint As Image = Image.FromFile(Path to the File)
'Here you really need to put in some code to resize image to fit
paper and use either landscape of portriat.
e.Graphics.DrawImage(imagePrint, 50, 50, imagePrint.Width,
imagePrint.Height)
e.HasMorePages = False
End Sub
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:Oo*************@TK2MSFTNGP04.phx.gbl...
Hmmm, every time I see sample code on this control, it has never ever
showed being able to simply pass a document name to the control.

I will look closer at it though... Do you have any source code that
specifically shows how to go about printing an existing document using
that control?? If so, I would love to see it!!

THanks, Brad

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>Brad,

Why not use the PrintDocument control..? You can then pass the name etc.

--
Newbie Coder
(It's just a name)

============================
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>I have the following code which I was using to print .pdf's. It worked
fine
>>and actually printed the pdf file.

Now I want to use the same code to print a .jpg file. When I run the
code,
it launches the 'Windows Picture and Fax viewer application' and DOES
NOT
print the actual image.

Is there a tweak to this code or is there some other code I can use to
print
>>a specified .jpg file directly from within my .net application???

PS.. I hardcoded the image name in here for testing purposes only and I
am
simply using teh default printer.

Here is the code..
--------------------------------------------------------
Dim iCopies As Integer

Dim x As Integer

' Ask user for number of copies they want printed

iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate
Drawing",
"3"))

Dim psi As New ProcessStartInfo()

For x = 1 To iCopies

With psi

.Verb = "print"

.WindowStyle = ProcessWindowStyle.Hidden

.FileName = "C:\image.jpg"

.UseShellExecute = True

End With

Process.Start(psi)

Next x

Thanks, Brad




Mar 10 '07 #4
That does work...

However, I am so new to this, any chance you could either give me or point
me to some sample code to actually set a printer to landscape/portrait (or
better yet - use the pagesetupdialog control to do all this) and to resize
an image to fit???

Thanks, Brad

"William LaMartin" <la******@tampabay.rr.comwrote in message
news:uD**************@TK2MSFTNGP02.phx.gbl...
This code should do it. However, the printed image may be distorted if
you don't first resize it to fit the target page size.

Private Sub PrintImage_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrintImage.Click
If Me.PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
Try
AddHandler Me.PrintDocument1.PrintPage, AddressOf
Me.GraphicPrint
Me.PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub

Private Sub GraphicPrint(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
Dim imagePrint As Image = Image.FromFile(Path to the File)
'Here you really need to put in some code to resize image to fit
paper and use either landscape of portriat.
e.Graphics.DrawImage(imagePrint, 50, 50, imagePrint.Width,
imagePrint.Height)
e.HasMorePages = False
End Sub
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:Oo*************@TK2MSFTNGP04.phx.gbl...
>Hmmm, every time I see sample code on this control, it has never ever
showed being able to simply pass a document name to the control.

I will look closer at it though... Do you have any source code that
specifically shows how to go about printing an existing document using
that control?? If so, I would love to see it!!

THanks, Brad

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>>Brad,

Why not use the PrintDocument control..? You can then pass the name etc.

--
Newbie Coder
(It's just a name)

============================
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl.. .
I have the following code which I was using to print .pdf's. It worked
fine
and actually printed the pdf file.

Now I want to use the same code to print a .jpg file. When I run the
code,
it launches the 'Windows Picture and Fax viewer application' and DOES
NOT
print the actual image.

Is there a tweak to this code or is there some other code I can use to
print
a specified .jpg file directly from within my .net application???

PS.. I hardcoded the image name in here for testing purposes only and I
am
simply using teh default printer.

Here is the code..
--------------------------------------------------------
Dim iCopies As Integer

Dim x As Integer

' Ask user for number of copies they want printed

iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate
Drawing",
"3"))

Dim psi As New ProcessStartInfo()

For x = 1 To iCopies

With psi

.Verb = "print"

.WindowStyle = ProcessWindowStyle.Hidden

.FileName = "C:\image.jpg"

.UseShellExecute = True

End With

Process.Start(psi)

Next x

Thanks, Brad




Mar 12 '07 #5
Nevermind... I got it figured out... Thanks for your help!!!

Brad

"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:Oh**************@TK2MSFTNGP06.phx.gbl...
That does work...

However, I am so new to this, any chance you could either give me or point
me to some sample code to actually set a printer to landscape/portrait (or
better yet - use the pagesetupdialog control to do all this) and to resize
an image to fit???

Thanks, Brad

"William LaMartin" <la******@tampabay.rr.comwrote in message
news:uD**************@TK2MSFTNGP02.phx.gbl...
>This code should do it. However, the printed image may be distorted if
you don't first resize it to fit the target page size.

Private Sub PrintImage_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PrintImage.Click
If Me.PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
Try
AddHandler Me.PrintDocument1.PrintPage, AddressOf
Me.GraphicPrint
Me.PrintDocument1.Print()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub

Private Sub GraphicPrint(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
Dim imagePrint As Image = Image.FromFile(Path to the File)
'Here you really need to put in some code to resize image to fit
paper and use either landscape of portriat.
e.Graphics.DrawImage(imagePrint, 50, 50, imagePrint.Width,
imagePrint.Height)
e.HasMorePages = False
End Sub
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:Oo*************@TK2MSFTNGP04.phx.gbl...
>>Hmmm, every time I see sample code on this control, it has never ever
showed being able to simply pass a document name to the control.

I will look closer at it though... Do you have any source code that
specifically shows how to go about printing an existing document using
that control?? If so, I would love to see it!!

THanks, Brad

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
Brad,

Why not use the PrintDocument control..? You can then pass the name
etc.

--
Newbie Coder
(It's just a name)

============================
"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl. ..
I have the following code which I was using to print .pdf's. It worked
fine
and actually printed the pdf file.
>
Now I want to use the same code to print a .jpg file. When I run the
code,
it launches the 'Windows Picture and Fax viewer application' and DOES
NOT
print the actual image.
>
Is there a tweak to this code or is there some other code I can use to
print
a specified .jpg file directly from within my .net application???
>
PS.. I hardcoded the image name in here for testing purposes only and
I am
simply using teh default printer.
>
Here is the code..
--------------------------------------------------------
Dim iCopies As Integer
>
Dim x As Integer
>
' Ask user for number of copies they want printed
>
iCopies = CInt(InputBox("Number of Copies: ", "Print Steel Plate
Drawing",
"3"))
>
Dim psi As New ProcessStartInfo()
>
For x = 1 To iCopies
>
With psi
>
.Verb = "print"
>
.WindowStyle = ProcessWindowStyle.Hidden
>
.FileName = "C:\image.jpg"
>
.UseShellExecute = True
>
End With
>
Process.Start(psi)
>
Next x
>
>
>
>
>
Thanks, Brad
>
>




Mar 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: me | last post by:
Hey all, well i am also a newbie :) i saw this on many sites: <img src="somephp.php?blabla" width="100"> how can i make that to? i want to reffer to a php file that returns or prints a jpg...
7
by: Henri Schomäcker | last post by:
Hi folks, I got a windows com executable which returns a jpg image in a BSTR. Let's say, the var that holds the data is $imgData. With perl, in a cgi script, I may simpy write:...
2
by: Henri Schomaecker | last post by:
Hi folks, I'm still having the problem that I don't know how I can print the data of a jpeg image. I got the imagedata as return-value from a COM object. The imagedata are hold in a Variant...
1
by: Jason | last post by:
For some reason, most but not all reports printing from an access application our client is using will not print any images on the reports or forms. One report will print the image and data...
24
by: Rhino | last post by:
I am dabbling with print CSS for the first time and I need some guidance. The web pages on my site look fine - to my untrained eye - when displayed on the monitor in any of the standard browsers....
0
by: Sergei Shelukhin | last post by:
I need to generate an image to print on a small card (15cm x 5cm), the image will be cut from the standart a4 sheet; it was done by MS Access proggie before and I'm rewriting it into ASP.NET. I...
1
by: dpowc | last post by:
How do I print a background image? I read another article that says as long as print background becomes a default for IE settings, we need to "cheat" a little to print a site as close to what we see...
0
by: Axeman | last post by:
I have an ASP.NET webapp that needs to view and print several different image formats (JPG, TIFF, BMP, etc.). In addition, it also needs to view/print PDF files. I have successfully implemented the...
1
by: eqiz | last post by:
I'm looking for a way to print stuff from my program. I have searched and searched for a way to print and the only thing I have found is PrintFORM which only takes a picture of the form and prints it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.