469,266 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

PrintDocument speed is slow

I have code that is able to print using the PrintDocument class,
PrintPage event and the Graphics.DrawString method. It is on the slow
side though. Does anyone have an ideas on how to speed up the printing
process? I did read one suggestion that said I should use the Win32
API's for printing, but that is too much work for the info I want to
print.

Oct 30 '06 #1
1 8778
ch*****@aegonusa.com wrote:
I have code that is able to print using the PrintDocument class,
PrintPage event and the Graphics.DrawString method. It is on the slow
side though. Does anyone have an ideas on how to speed up the printing
process? I did read one suggestion that said I should use the Win32
API's for printing, but that is too much work for the info I want to
print.
One of the tricks I have learned, which has the greatest impact on
speed, is to cache all the PageSettings values that I require. Every
time your code references PageSettings it appears the printer is
interrogated for the value. (The performance impact is particularly
noticeable with Network Printers).

If your code has sprinklings of "X = e.PageSettings.HardMarginX" or uses
"e.PageSettings...." or similar, then you will obtain an enormous
performance increase by already assigning the value to a variable, and
doing this just once!

In my applications, I do something like the following (watch for wrapping) -

Dim iCurrentPage as UInt16 = 0

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles
PrintDocument1.PrintPage

Static iPrinterPageTop, iPrinterLeftMargin, iPrinterPageWidth,
iPrinterPageBottom, iPrinterPageWorkingWidth, iPrinterPageWorkingHeight
As UInt16

iCurrentPage += 1

If iCurrentPage = 1 Then
Dim pPageSettings As System.Drawing.Printing.PageSettings =
e.PageSettings 'This speeds-up the code as we don't continually call
"e.PageSettings".
iPrinterPageTop = pPageSettings.HardMarginY
iPrinterLeftMargin = pPageSettings.Bounds.Left
......
......
End If

From here, I just use the iPrinterPageTop, iPrinterLeftMargin etc
within all printing statements.

End Sub
My own tests have shown performance increases of several hundred
percent, just by avoiding multiple calls to the PageSettings Property.

I trust I have explained my technique clearly enough and it helps you
with your speed problem. As mentioned, this works for me.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Oct 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

34 posts views Thread by Jacek Generowicz | last post: by
52 posts views Thread by Neuruss | last post: by
25 posts views Thread by Stijn Oude Brunink | last post: by
reply views Thread by active | last post: by
reply views Thread by brogits | last post: by
6 posts views Thread by lawrence k | last post: by
27 posts views Thread by SQL Learner | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.