Best practice for printing

Hello,

I'm trying to print with wxPython (on Win XP and with the help of wxPython in Action). My problem is that I don't know how to count the number of page to print.

As far as I know, we have to know the number of pages to print before printing. But my problem is that my printing is quite complex (with tables containing more or less big lines). My idea is to build directly the pages on the OnPreparePrinting. Like this I will know the number of pages (because they will be created), but ... I don't know how to do and more over if it is a good idea.

Then I'd like to know if some kind of best practice exists concerning the wx Printing

Sebastien

I don't know if there is something that could be called a best practice or not, usually the printing needs to be highly adapted to the specific needs of the application. In your case I would recommend partitioning the page drawing function into measuring only and drawing personalities. Perhaps just passing a flag to it would be okay. Then you can check the flag at various points along the way to determine if you should actually draw something, or just measure where the next something should be located. If you combine that with some way to indicate the starting position in your data structures, and then return the starting position for the next page, then calculating the number of pages would be as simple as this pseudo-code

  position = 0
  pages = 0
  while position is not endPosition:
    pages += 1
    position = DoDrawPage(position, measureOnly=True, dc)

If you also add code that keeps track of the starting positions of each page then that can be used when the print framework requests that a particular page be drawn to quickly get to the right position in your data structures.

···

On 7/25/10 3:23 AM, VINOT S�bastien wrote:

Hello,

I'm trying to print with wxPython (on Win XP and with the help of wxPython in Action). My problem is that I don't know how to count the number of page to print.

As far as I know, we have to know the number of pages to print before printing. But my problem is that my printing is quite complex (with tables containing more or less big lines). My idea is to build directly the pages on the OnPreparePrinting. Like this I will know the number of pages (because they will be created), but ... I don't know how to do and more over if it is a good idea.

Then I'd like to know if some kind of best practice exists concerning the wx Printing

--
Robin Dunn
Software Craftsman