Printing Large image Files in VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ben.agnoli@rws.com

    #1

    Printing Large image Files in VB.NET

    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(ByVa l sender As Object, ByVal e As
    PrintPageEventA rgs)
    Dim iTotalPages As Integer = Math.Round(prnt Img.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.Draw Image(prntImg, 0, 0, srcRect,
    GraphicsUnit.Pi xel)

    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.PrintPa ge, AddressOf PrintImage
    printer.Print()
    Catch ex As Exception
    Log("PRINTER ERROR: " & ex.Message,
    EventLogEntryTy pe.Error)
    End Try
    End Sub

    ===== END CODE ====

Working...