<$BlogRSDURL$>
My Blog Links
Site Links
Currently Reading
Blogroll
Archives
Tools
  • This page is powered by Blogger. Isn't yours?
  • Weblog Commenting and Trackback by HaloScan.com
  • 2RSS.com :: RSS directory
  • Listed on BlogShares
  • Blog Directory, Find A Blog, Submit A Blog, Search For The Best Blogs

Wednesday, March 10, 2004

Printing Blank Page After a Print Preview 

I just answered a post on GotDotNet about PrintDocument.Print only printing a blank page after showing the print preview dialog. This has happened to me a few times and seems to be something that others get tripped up on as well, so I decided to put up an entry about it.

The Symptom:
Your PrintDocument works fine when the user just prints it first. However, if the user does a print preview followed by a print, the result is a blank page rather than what it should be.

Typical Reason:
The PrintDialog uses the same instance of the PrintDocument as the PrintPreviewDialog, so you need to be sure to reset any important data during PrintDocument.OnBeginPrint. So, if you have anything that may be traversing lists or tables or keeping track of page numbers or whatever, they get set during the first run in the PrintPreviewDialog. So, when the PrintDialog is actually run, your PrintDocument may think it's already printed everything it needed to.

If this is the problem, you should be able to simulate it by calling the PrintPreviewDialog twice in a row with the same PrintDocument.

Here is a very good article on MSDN about .NET WinForms printing.

Comments: Post a Comment