Monday, September 8, 2008

C# Pagination Example Wanted

C# Pagination Example Wanted

Unlike Java Swing, which seemed to have a pretty painless way of printing text, C#/.NET is a bit ugly. (Or perhaps I haven't found the right method of making it painless.) To print to the printer, you use the Print method of PrintDocument, which in turn calls a PrintPage method that prints one page at a time. From this method, you draw everything onto a Graphics context just like you are drawing on the screen, and set the HasMorePages element of the PrintPageEventArgs to indicate whether there is another page to format.

What makes this ugly is that if you are trying to figure out how to print a report, you do sequentially: print out the title, and then a series of lines of information, perhaps a summary. I suspect that the way to make this happen in this page by page event driven scheme is to create some sort of output stream that the PrintPage event handler consumes, one page at a time.

There are a number of very simple printing examples out there--so simple that they don't deal with pagination. And there are some very complex schemes, that might make sense if I were a bit further along in my learning of this. But does anyone have a simple C# pagination example?

UPDATE: I came up with a solution, but it isn't very pretty. You can see it, and run the program, from here.

No comments:

Post a Comment