Printing Large image Files in VB.NET

B

ben.agnoli

I have written the below class for printing out large jpg files (1
page wide, multiple pages high) over multiple pages. The class will
get instantiated multiple times at once by a windows service.

For each page that the class prints, it gets visibly slower, when the
third document, third page and onwards starts to print, it takes over
20 seconds a page, am I doing something wrong, or is this the wrong
way to go about the task (could be printing 20 documents at 10 second
intevals), if so, can you suggest a better way?

Kind Regards,

Ben.

===== CODE ====

Private Sub PrintImage(ByVal sender As Object, ByVal e As
PrintPageEventArgs)
Dim iTotalPages As Integer = Math.Round(prntImg.Height /
(prntImg.Width * (2 ^ 0.5)))
Dim srcRect As New RectangleF(0, prntiPage * (prntImg.Width *
(2 ^ 0.5)), prntImg.Width, prntImg.Width * (2 ^ 0.5))

e.Graphics.DrawImage(prntImg, 0, 0, srcRect,
GraphicsUnit.Pixel)

If prntiPage = iTotalPages - 1 Then
e.HasMorePages = False
Else
prntiPage += 1
e.HasMorePages = True
End If
End Sub

Sub New(ByVal sImgagePath)
Try
prntImg = Image.FromFile(sImgagePath)
Dim printer As PrintDocument = New PrintDocument
AddHandler printer.PrintPage, AddressOf PrintImage
printer.Print()
Catch ex As Exception
Log("PRINTER ERROR: " & ex.Message,
EventLogEntryType.Error)
End Try
End Sub

===== END CODE ====
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top