473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to get number of pages for printing...?

Tim
Hi,

I am creating my own method for printing. I am using PrintDocument and
cycling through the data and creating new pages as neccessary.

My question is, how can I know that total number of pages so that I can put
"Page 1 of 5" on the first page and also I would know when to draw the
report footer?

Can anyone offer any advice?

Tim
Nov 17 '05 #1
3 15229
Tim,

Well, that's completely up to you. Since you are printing out
everything custom, you have to figure out, according to the data you are
laying out, what the number of pages will be. That's completely up to you.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <ti*@home.com> wrote in message
news:m8********************@news20.bellglobal.com. ..
Hi,

I am creating my own method for printing. I am using PrintDocument and
cycling through the data and creating new pages as neccessary.

My question is, how can I know that total number of pages so that I can
put "Page 1 of 5" on the first page and also I would know when to draw the
report footer?

Can anyone offer any advice?

Tim

Nov 17 '05 #2
Hi Nicholas, Hi Tim

I have a similar Problem. Creating my own "PrintPreview" I like to show
a Page-Selctor like: "Page ... of XYZ"

I think its not up to me....

E.G.
If there is a PrintDocument (created manually or by ReportGenerator
....) I can set the PrinterSettings and the PageSettings -->
consequently the number of Pages need to calculatet.

Besides :
The PrintPreviewControl.StartPage can not set to values >=
"PageCount"-1

There is a (not reliable) workaround to get the number of pages
(ppv1 is a PrintPreviewControl)

int currentPage = this.ppv1.StartPage;
this.ppv1.StartPage = 999999;
int pages = this.ppv1.StartPage+1;
this.ppv1.StartPage = currentPage;

No Exception happends but
pages contains now the number of pages of the PrintDocumnet "previewd"
with ppv1.

Funnily enough this works only it the PrintPreviewControl is visible on
screen !? So at the moment i do without "Page ... of XYZ"
Hope there is a propper way to get "Number of pages"
Peter
Nicholas Paldino [.NET/C# MVP] schrieb:
Tim,

Well, that's completely up to you. Since you are printing out
everything custom, you have to figure out, according to the data you are
laying out, what the number of pages will be. That's completely up to you.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tim" <ti*@home.com> wrote in message
news:m8********************@news20.bellglobal.com. ..
Hi,

I am creating my own method for printing. I am using PrintDocument and
cycling through the data and creating new pages as neccessary.

My question is, how can I know that total number of pages so that I can
put "Page 1 of 5" on the first page and also I would know when to draw the
report footer?

Can anyone offer any advice?

Tim


Nov 17 '05 #3
Tim, Peter:

The only way to get the number of pages of a custom PrintDocument is to
do a "dry run" of the entire printing process in order to determine the
page count, then do it again for real. Here is why.
From the .NET Framework's point of view, your PrintDocument is a black

box. All the Framework can do is call your OnBeginPrint following by
successive calls to OnPrintPage until OnPrintPage sets HasMorePages to
false. The outside agent doing the printing (the PrintPreviewControl,
for example) has absolutely no idea what's going on inside there, and
so has no idea how you determine which is the last page to print.

Given that, how could it ever determine, by itself, how many pages
there are to print? Since your routines are doing the page layout, your
routines are the only ones with any hope of knowing how many pages
there will be.

Peter's trick with PrintPreviewControl works only because the first
thing that PrintPreviewControl does when it displays is call your
PrintDocument object to render all of the pages. Since it's rendered
all of the pages once, it knows how many pages there are. That's why it
"knows" only when it's visible on the screen: because it's only at that
moment that it bothers to render the entire print document into visible
pages.

However, this doesn't help if you want to display "Page x of y" at the
bottom of each page. In this case, you yourself have to take a dry run
through the printing process and count the pages when you first create
an instance of your PrintDocument. Remember: your code is the only part
of the program that has any idea of what the pages look like, and
therefore how many there will be. As Nicholas said, it's up to you to
roll your own page counting algorithm. It may be as simple as counting
a particular kind of record ("one per page") or as complicated as
actually going through the motions of printing everything just to get
the page count. Whether you can take a short route depends upon how
you're laying out your data on the pages.

Nov 17 '05 #4

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

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
16
by: gb | last post by:
Hi All, Ive created a popup page using 'var openWindow = window.open("new","pop")' And added content using openWindow.document.write(" "); statements. But now I would like to be able to print...
5
by: Steven T. Hatton | last post by:
If you happen to have Accelerated C++ by Koenig and Moo, and haven't gotten around to reading it, I suggest you count the pages between page 18 and page 51. I came up with zero. This is very...
0
by: Greg Reed | last post by:
I have a 4 column report and wondered if there is column number property. I have more complicated uses for it but basically could I Have column number shown at ctop of each column 1 ...
1
by: Martin | last post by:
Does anyone know how to create the total number of pages? I am using the printpreview, pagesetup, and printdocument. I am printing contents from a richtextbox. I have it already printing but I...
1
by: Pedro | last post by:
Hi all; I have one small app. written in vb.net and somewhere i create one document which can be printed using one printdialog. Before printing it, i want to advise user's from the number of...
0
by: Eduard | last post by:
Hello there, I've an issue with Vb.Net printing. I have to print some product code but i only get one or two pages printed instead of all pages. If i print to an Adobe PDF printer all works...
8
by: cyberdwarf | last post by:
Hi I need to print a report which will always output an even number of pages (this is for duplex printing). ie, if the report ends with an odd number of pages, I need to output a blank sheet... ...
2
by: ad | last post by:
There are some uses in my windows 2003 domain. The can print with a printer in a pc. How can I caculate the numbers of pages of a users?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.