• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2171
  • Last Modified:

C# WinForms: Breaking up a PrintDocument into pages?

I have the code for the attached file printing fine (the word 'test'), but I need to find out how to parse my text file document into individual pages.

How does that work?

As you can see in the demo which I have working, this line:

e.Graphics.DrawString("test",new Font(FontFamily.GenericSerif,12),
                  Brushes.Black,100,100);

prints one word.  I have a multi-page text file.  Must I iterate through the lines and pass each line into DrawString()?  Is there an easier way?

Also, if I am to iterate, then I presume I must also determine if I am near a page break.  And this is starting to sound like a Printer Device Context object, which I hope I do not need to deal with.

Please let me know.

Thanks.
0
newbieweb
Asked:
newbieweb
2 Solutions
 
Bob LearnedCommented:
When working with the PrintDocument, you handle the Print event for each page printed.  If you need multiple pages, then set e.HasMorePages = true, until you are done.
0
 
Jacques Bourgeois (James Burger)Commented:
Printing with the PrintDocument is a pain, so do it only as a last resource. That is why report generators are so popular. Personnally, I usually use Microsoft Word when I need to control printing, because it takes care of a lot of stuff such as margins and page breaks automatically.

With the PrintDocument have to know where the cursor is and move it by giving new coordinates for each line that you want to print.

You have to take care of where you are in the page, and are the one that tells the system that a new page need to be printed, as TheLearnedOne told you.

Then, the Print event will be fired for the new page, and it is up to you to continue from where you where in the data after the previous page.
0
 
newbiewebAuthor Commented:
Thanks.  I had already discovered:

 e.HasMorePages = true

is key.

Thanks.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now