How to implement a PrintRange functionnality in my PrintDocument ?

G

Guest

Hi,

I try to use my own PreviewDialog with a PrinPreviewControl, to preview a
document of type MyPrintDocument, and I want to implement the PrintRange
functionnality (print some pages between 2 values).

I noticed that we can specified the PrintRange, FromPage and ToPage
properties of the PrintDocument.PrintSettings object, but, as said in MSDN :

"The FromPage, ToPage and PrintRange can also be set programmatically,
though the PrintDocument.PrintPage implementation is the same."

So I tried to do that in my class, inherited from PrintDocument, but I
failed ! In the PrintPage EventHandler, I made a treatment that paint
graphics for the specified pages, but I have blank pages ; I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

So, please, how to proceed ?

Thanks in advance.
 
D

Dave Sexton

Hi bp,

Can you post some code?
So I tried to do that in my class, inherited from PrintDocument, but I
failed

You don't need to derive from PrintDocument to print a range of pages. If you are deriving a class from PrintDocument for different
reasons then you should treat your document just as you would a PrintDocument.
I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

You must post some code for anyone to help you with this problem.
 
B

Bruce Wood

bp said:
Hi,

I try to use my own PreviewDialog with a PrinPreviewControl, to preview a
document of type MyPrintDocument, and I want to implement the PrintRange
functionnality (print some pages between 2 values).

I noticed that we can specified the PrintRange, FromPage and ToPage
properties of the PrintDocument.PrintSettings object, but, as said in MSDN :

"The FromPage, ToPage and PrintRange can also be set programmatically,
though the PrintDocument.PrintPage implementation is the same."

So I tried to do that in my class, inherited from PrintDocument, but I
failed ! In the PrintPage EventHandler, I made a treatment that paint
graphics for the specified pages, but I have blank pages ; I also tried to
specified a virtual printer for the page to ignore, in the QueryPageSettings
EventHandler, but it throws an exception...

So, please, how to proceed ?

I made the same mistake when I started working with PrintDocument: I
thought that there was some magic behind the scenes that would take
care of the "Print page n" and "Print pages from n to m" functionality.

There isn't: you have to do it all yourself.

In your case, what that means is that the first time your PrintPage
event handler is called, you have to check the FromPage setting in the
page settings, and print _that_ page. It's up to _you_ to skip over the
first n - 1 pages on the first call and go directly to page n and print
that.

It's also up to you (as you've probably already guessed) to signal
"nothing more to print" when you've finished rendering page m.

The underlying PrintDocument doesn't understand page numbers, and
(wisely) doesn't assume that pages are simply numbered from 1. (They
may not be: consider a document with table of contents on pages i, ii,
iii, and iv, then the content is numbered 1, 2, 3, .... In that case,
"print 2 to 4" means print (by count) pages 6 to 8.) All that the
underlying framework does is pass you the numbers and let you work out
what to do.

So, on the very first call to PrintPage, you'll be handed a blank
graphics surface and the number FromPage 3, for example. It's up to you
to go through the motions of rendering pages 1 and 2 (without really
doing it) and then draw page 3 on the graphics surface and return. Or,
perhaps, you have some clever trick for knowing what belongs on page 3
without having to ghost-draw pages 1 and 2, in which case just go for
it.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top