473,386 Members | 1,795 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,386 software developers and data experts.

Printing a document with multiple pages (page breaks)


I need to print two pages using PrintDocument, but there are some problems.

I've got something like that:
-button is pressed
-two pages need to be printed

The code is like that:

Expand|Select|Wrap|Line Numbers
  1. PrintDocument print_tab1 = new PrintDocument();
  3. in main():
  4.         print_tab1.PrintPage += new PrintPageEventHandler(printTab1);
  6.         private void print_tab1_but_Click(object sender, EventArgs e)
  7.         {
  9.             PrintDialog pd = new PrintDialog();
  10.             pd.Document = print_tab1;
  11.             if (pd.ShowDialog() == DialogResult.OK)
  12.             {
  13.                 print_tab1.Print();
  14.             }
  15.         }
  17.         private void printTab1(Object sender, PrintPageEventArgs e)
  18.         {
  19.             e.Graphics.DrawString("page 1", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  20.             e.HasMorePages = true;
  21.             e.Graphics.DrawString("page 2", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  22.             e.HasMorePages = false;
  23.         }
I've seen the following post: http://www.thescripts.com/forum/thread104989.html
But I can't figure out how to insert page break BEFORE the page actually ends and print the data that is FOMED IN THE SAME METHOD.

I understand that after printing a single page the method exits. But it doesn't when the page still has space to print on it. So I've got "page 1" and "page 2" on the same page.
And if I return from printTab1 explicitly, than how should I call it again and print ONLY the second page?

Would appreciate any help.
Jan 26 '07 #1
4 14546
So? No one can help?
Jan 28 '07 #2
4,871 Expert 4TB
Here is an example that may help:
Printing in C#

Note the use of hasmorepages...
Jan 28 '07 #3
As I stated in my first post I've seen a very similar example, where a block of text is printed. But what I need is two words example - one word on the first page and the other on the second. "while" is not suitable for this. For better understanding see my simple code snippet (which doesn't work, but you'll get the idea).
Jan 29 '07 #4
Ok. Managed to find a solution all by myself.
In case someone has the same problem in teh future:
Expand|Select|Wrap|Line Numbers
  1. int page = 1;
  2. private void printTab1(Object sender, PrintPageEventArgs e)
  3. {
  4.   if (page == 1)
  5.   {
  6.     e.Graphics.DrawString("page1", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  7.     e.HasMorePages = true;
  8.   }
  9.   if (page == 2)
  10.   {
  11.     e.Graphics.DrawString("page2", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  12.     e.HasMorePages = false;
  13.   }
  14.   page++;
  15. }
Jan 29 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

by: ray well | last post by:
hi, i need to print multiple pages on a printer. this is what i'm using now Sub Print() Dim PrintDoc As New PrintDocument AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText Do While...
by: al jones | last post by:
I'll try again as I'm obvioulsy standing in the middle of the forest and not seeing the trees ... I didn't think I was to old to learn new trick, but this has just about convinced me otherwise. I...
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
by: m.shidoshi | last post by:
I was recently put in charge of heading up my company's website, and while I have a lot of experience on the design side of things, I'm still very new to the programming side. When I started, the...
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
by: Richard MSL | last post by:
I have an application that prints documents that it creates. It uses what I believe is a standard .NET way of doing so, like this: PrintDocument pd = new PrintDocument(); pd.PrintPage += new...
by: ben.agnoli | last post by:
I have written the below class for printing out large jpg files (1 page wide, multiple pages high) over multiple pages. The class will get instantiated multiple times at once by a windows service....
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.