473,396 Members | 2,011 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,396 software developers and data experts.

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 10182
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
52
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
2
by: Robert Hooker | last post by:
Hi, I'm curious to know if I'm doing something wrong here, or if this is just mind-numbingly slow for a reason. In a simple WindowsFormsApplication: public Form1() { // Required for...
0
by: active | last post by:
Dim mPD As PrintDocument Dim mPrinternameSaved As PrintDocument Public WriteOnly Property PrintDocument() As PrintDocument Set(ByVal value As PrintDocument) mPD = value mPrinternameSaved = mPD...
0
by: brogits | last post by:
Hello, I would like to print text using PrintDocument in Draft mode. Is this possible? I tried the PrinterResolution but it is readonly? How does one set the PrinterSetting or...
6
by: lawrence k | last post by:
The following function is way too slow. If anyone has any suggestions about how to speed it up, I'd be grateful for them. We have to call this function 36 times on one page, and I think each time...
1
by: kig25 | last post by:
Hello, When using the VB.NET PrintDocument class, I seem to be encountering an issue where the sub pd_PrintPage handles PrintDocument.PrintPage (upon continuing if HasMorePages = true) will...
27
by: SQL Learner | last post by:
Hi all, I have an Access db with two large tables - 3,100,000 (tblA) and 7,000 (tblB) records. I created a select query using Inner Join by partial matching two fields (X from tblA and Y from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.