473,583 Members | 4,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Slow printing in C#/.NET...

I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while my
C# code prints 10 labels in 5 to 6 seconds. And this differences increases
with the increase number of labels.

The code is as follwods:
Here rdr = OleDbDataReader
Font is Times New Roman, 12pt
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.HasMorePages = false;

if(this.rdr.Rea d())
{
e.Graphics.Draw String(rdr[0].ToString(), font, Brushes.Black, 10, 20);
e.Graphics.Draw String(rdr[1].ToString(), font, Brushes.Black, 10, 40);
e.Graphics.Draw String(rdr[2].ToString(), font, Brushes.Black, 10, 60);

if( --this.labels_to_ print > 0)
e.HasMorePages = true;
}
}

How can I increase printing speed? Please help.

Arif.
Nov 17 '05 #1
4 9217
Arif,

I don't see much room for improvement here. It looks like you are
disposing of resources correctly (or rather, not allocating anything that
you don't need during the printing process).

The Graphics object takes advantage of GDI+, which is very slow. This
is probably the issue. I would suspect that the third-party component is
not using GDI+. Why not just use that?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Arif" <Ar**@discussio ns.microsoft.co m> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while
my
C# code prints 10 labels in 5 to 6 seconds. And this differences increases
with the increase number of labels.

The code is as follwods:
Here rdr = OleDbDataReader
Font is Times New Roman, 12pt
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.HasMorePages = false;

if(this.rdr.Rea d())
{
e.Graphics.Draw String(rdr[0].ToString(), font, Brushes.Black, 10, 20);
e.Graphics.Draw String(rdr[1].ToString(), font, Brushes.Black, 10, 40);
e.Graphics.Draw String(rdr[2].ToString(), font, Brushes.Black, 10, 60);

if( --this.labels_to_ print > 0)
e.HasMorePages = true;
}
}

How can I increase printing speed? Please help.

Arif.

Nov 17 '05 #2
Another issue is that you're actually reading directly out of the database
while printing, and using OleDb (Access?) mind you -- not a good performer.

Could you read the data into an array first, then call the Print() and just
iterate through the array inside the PrintPage event? You could then
isolate the performance problems between reading from the db and how long
the GDI+ calls and spooling is actually taking. I would put good money that
your db access is slowing you down MUCH more than GDI+.

I have an app that prints Legal (8.5x14) paychecks and I can spool about 10
checks/pages per second on a 2.4Ghz/512MB laptop. They have at least 100
DrawString()s, probably a dozen fonts (including a custom MICR font -
similar to a barcode), at least 30-40 DrawLine()s, and 4 DrawImage()s for
signature files and logos on the checks. Everything is read into memory
before I call the Print() method though.

Craig
"Arif" <Ar**@discussio ns.microsoft.co m> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while
my
C# code prints 10 labels in 5 to 6 seconds. And this differences increases
with the increase number of labels.

The code is as follwods:
Here rdr = OleDbDataReader
Font is Times New Roman, 12pt
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.HasMorePages = false;

if(this.rdr.Rea d())
{
e.Graphics.Draw String(rdr[0].ToString(), font, Brushes.Black, 10, 20);
e.Graphics.Draw String(rdr[1].ToString(), font, Brushes.Black, 10, 40);
e.Graphics.Draw String(rdr[2].ToString(), font, Brushes.Black, 10, 60);

if( --this.labels_to_ print > 0)
e.HasMorePages = true;
}
}

How can I increase printing speed? Please help.

Arif.

Nov 17 '05 #3
I would recommend that you get your hands on a profiler (comes with
VS2005, for VS2003 you can use CompuWare's DevPartner Community
Edition:

http://www.compuware.com/products/de...rtner&sf=1&p=0

Profile your application, figure out where it's spending all its time,
and then figure out how to optimize that.

Nov 17 '05 #4
Now i am using the simplest code that reads the data from an array rather
than from OleDbDatareader object, as follows:

private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 0], font,
Brushes.Black, 10, 20);
e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 1], font,
Brushes.Black, 10, 40);
e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 2], font,
Brushes.Black, 10, 60);

if( --this.labels_to_ print > 0)
e.HasMorePages = true;
else
e.HasMorePages = false;

}

But I am seeing the same down printing speed as was in the case using
OleDBDataReader instead of an array.

I also notice that when I turn off the printer,click to print then 64
pages/labels are spooled very fast. But if the printer is ON then this
spooling is comparatively slow.

I think that the printer is printing labels perhaps as a separate print job
for each page because there is a step/0.5 second delay between two labels
printing. But the third party software prints contineously and very fast.
when I used the following code to print 64 labels separately, I see the same
printing style/speed as was when printing 64 labels in on printing job.

some_methos()
{
for(int i=0; i < this.labels_to_ print; i++) //printing 64 labels as separate
print job.
this.printDocum ent1.Print();
}

private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.HasMorePages = false;

e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 0], font,
Brushes.Black, 10, 20);
e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 1], font,
Brushes.Black, 10, 40);
e.Graphics.Draw String(this.dat a_ary[this.labels_to_ print-1, 2], font,
Brushes.Black, 10, 60);
}

I think that may be there some settings for printer that I should take care
in C# code.

Any new idea, please share.

Arif.
"Craig Scheets" wrote:
Another issue is that you're actually reading directly out of the database
while printing, and using OleDb (Access?) mind you -- not a good performer.

Could you read the data into an array first, then call the Print() and just
iterate through the array inside the PrintPage event? You could then
isolate the performance problems between reading from the db and how long
the GDI+ calls and spooling is actually taking. I would put good money that
your db access is slowing you down MUCH more than GDI+.

I have an app that prints Legal (8.5x14) paychecks and I can spool about 10
checks/pages per second on a 2.4Ghz/512MB laptop. They have at least 100
DrawString()s, probably a dozen fonts (including a custom MICR font -
similar to a barcode), at least 30-40 DrawLine()s, and 4 DrawImage()s for
signature files and logos on the checks. Everything is read into memory
before I call the Print() method though.

Craig
"Arif" <Ar**@discussio ns.microsoft.co m> wrote in message
news:F2******** *************** ***********@mic rosoft.com...
I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while
my
C# code prints 10 labels in 5 to 6 seconds. And this differences increases
with the increase number of labels.

The code is as follwods:
Here rdr = OleDbDataReader
Font is Times New Roman, 12pt
private void printDocument1_ PrintPage(objec t sender,
System.Drawing. Printing.PrintP ageEventArgs e)
{
e.HasMorePages = false;

if(this.rdr.Rea d())
{
e.Graphics.Draw String(rdr[0].ToString(), font, Brushes.Black, 10, 20);
e.Graphics.Draw String(rdr[1].ToString(), font, Brushes.Black, 10, 40);
e.Graphics.Draw String(rdr[2].ToString(), font, Brushes.Black, 10, 60);

if( --this.labels_to_ print > 0)
e.HasMorePages = true;
}
}

How can I increase printing speed? Please help.

Arif.


Nov 17 '05 #5

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

Similar topics

16
2574
by: Jason | last post by:
Hey, I'm an experience programmer but new to Python. I'm doing a simple implementation of a field morphing techinique due to Beier and Neely (1992) and I have the simple case working in Python 2.3 - but it's REALLY slow. Basically, you specify two directed line segments in the coordinate system of a raster image and use the difference...
0
1940
by: lubprog | last post by:
hi, I am printing jpg files which are on a disk. The file name is selected from a database and the file is located on the disk and then printed. I am able to print the file but it takes a long time to do it(between 35-40 seconds). I am posting the code in the print event handler , please suggest how i can speed up the printing.btw i am...
1
10263
by: chankey | last post by:
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...
0
946
by: The ants are driving me crazy | last post by:
Printing in .net 2003 using PrintDocument class seems to be slow. Has anyone else found this to be true? And found a work-around?
3
1900
by: Toral Shah | last post by:
hi i have made a data entry program and want to print my report in dot matrix printer. but the printing speed is really slow. but when i print my dos based reports the output is really fast. do i need to do some settings.. plz help me out with my query
33
2664
by: nw | last post by:
Hi all, I'm constantly confronted with the following two techniques, which I believe often produce less readable code, but I am told are faster therefore better. Can anyone help me out with counter examples and arguments? 1. The STL is slow. More specifically vector. The argument goes like this:
0
1445
by: Kerem Gümrükcü | last post by:
Hi, i use the code from this code sample on MSDN: for printing a 5 and sometimes 70 page text-only data: http://msdn.microsoft.com/en-us/library/ms404294.aspx The point is, that this is terribly slow and the preview is unbelievable slow, especially when you have a 70 page data you want to print. I use a PDF generator to print the data,...
12
3050
by: Eps | last post by:
Hi there, I am doing the following, this is a List of audio files. this.Where(p =p.Album == AnAudioFileObject.Album).Select(s => s.Artist).Distinct().Count() 1; The aim is to determine whether AnAudioFileObject is from an album that has various artists on it or just one artist.
1
5189
by: daschicken | last post by:
Hi guys, currently I'm encountering a strange behavior while using the PrinterJob class. I've got a little program printing some pages. Most of the time the printer does its job as it should. But sometimes it takes minutes printing a page which was printed before in seconds. It's absolutely random and not reproducible. Following, the...
0
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8179
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7933
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6578
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5700
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5372
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1431
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1155
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.