?
Solved

Printing

Posted on 2003-03-27
9
Medium Priority
?
240 Views
Last Modified: 2010-04-15
Hi

I'm making a graph and want to print it out. When I print it out it looks good, but when I increase the size of the graph so it's bigger than 1 A4 it doesn't print it out on multiple pages, it only prints the part that will fit on one A4.

I have a method
Draw(Graphics g)
{
      g.drawLine(.................
      g.fillRectangle(.......
      etc etc
}
I call Draw with the printer object.
Do i have to work out how big the Draw method(size on paper) will be and then somehow tell the printer how many pages it will take??????

Any help would be appreciated, thx in advance.

Nick
0
Comment
Question by:nick81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 4

Expert Comment

by:Nebulus_
ID: 8218877
I don't know if exists a feature to print what you want, but very easy you can split your image into many pages. Here a small example:

I supose that my A4 page has 100X100 pixels, and my draw has 150X150 pixels (just a circle but can be everything).
To draw all pages I must calculate the number of pages (here 4) and to call Draw method with just one extra line of code:

first page:

Draw(Graphics g)
{
     g.TranslateTransform(0, 0);
     g.drawLine(.................
     g.fillRectangle(.......
     etc etc
}

second page:

Draw(Graphics g)
{
     g.TranslateTransform(-100, 0);
     g.drawLine(.................
     g.fillRectangle(.......
     etc etc
}

third page:

Draw(Graphics g)
{
     g.TranslateTransform(0, -100);
     g.drawLine(.................
     g.fillRectangle(.......
     etc etc
}

final page:

Draw(Graphics g)
{
     g.TranslateTransform(-100, -100);
     g.drawLine(.................
     g.fillRectangle(.......
     etc etc
}

You just need to manage the transformation for current page.
0
 
LVL 2

Expert Comment

by:nir2002
ID: 8252453
Hi Nick,

basicly what nebulus write is correct.

Draw(Graphics g)
{

    bool lastPage = //find if this page is last ....
    //do the specfic drawing for the page
    //...
    g.HasMorePages = !lastpage;
   
}

Best regards
Nir

0
 

Author Comment

by:nick81
ID: 8260953
Hi nir and nebulus,
TranslateTransform is real handy, although I haven't got it working yet.

I have made a double for loop, so that it works out from where to print from. So it goes from top left to bottom left.

But if you print out the pages like that, won't it mean there are for example 9 printing jobs(if it's 9 pages) instead of one printing job?

currently it's only printing one page for some reason, even though it loops multiple times.

my code :

public void RePrint(Graphics g, int width, int height)
          {
               int amountOfWidthPages = (int) ((this.Size.Width / width) + 1);
               int amountOfHeightPages = (int) ((this.Size.Height / height) + 1);
               Console.WriteLine(width);
               Console.WriteLine(height);
               
               Console.WriteLine(this.Size.Width);
               Console.WriteLine(this.Size.Height);

               Console.WriteLine(amountOfWidthPages);
               Console.WriteLine(amountOfHeightPages);

               for(int i = 0;i < amountOfWidthPages; i++)
               {
                    for(int j = 0;j < amountOfHeightPages; j++)
                    {
                         Console.WriteLine("hello");
                         ReDraw(g,(int)((-this.Size.Width / 2) + (i * width)),(int)((-this.Size.Height / 2) + (j * height)));
                    }
               }
          }

the code looks kind of stupid in this textBox but it should be clear enough.

width and height are width and height of the printing page
this.Size.Width and Height are the width and height of the form that i am printing.

What am i doing wrong.
I will award the points to nebulus as he came up with the answer. Although i'll do it later otherwise it will close this thread.

thx

Nick
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nick81
ID: 8260961
Rereading it it seems slightly unclear

TranslateTransform works, its just that all the pages don't print.
0
 
LVL 4

Expert Comment

by:Nebulus_
ID: 8261114
More details please:
When you call RePrint and ReDraw, and what exactly ReDraw do?
0
 

Author Comment

by:nick81
ID: 8282268
All that ReDraw does is draw a graph. It's quite big but it boils down to a bunch of lines and some text. It is also used to show the graph on the screen.
I added RePrint to print it on multiple pages. so RePrint calls ReDraw multiple times(amount dependent on amount of pages needed). This basically means the print call is made multiple times, but it only prints one page and even if it did work wouldn't it mean there are lots of print jobs in the print manager???
Is there not a way of pushing all the pages that need to be printed into one job and then to print it?

thx
nick
0
 
LVL 4

Accepted Solution

by:
Nebulus_ earned 400 total points
ID: 8282451
Maybe an example will be better:

I have something to print and I calculated that I need 4 pages for this operation: 2 for width and 2 for height.

This is the code:

// page counter
private int page;

...

// start printing
private void button1_Click(object sender, System.EventArgs e) {
  page = 0;
  printDocument1.Print();
}

// manage printing
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
  int dX = 0, dY = 0;
  switch(page) {
    case 0:
     dX = 0;
     dY = 0;
     break;
    case 1:
     dX = -e.PageBounds.Width;
     dY = 0;
     break;
    case 2:
     dX = 0;
     dY = -e.PageBounds.Height;
     break;
    case 3:
     dX = -e.PageBounds.Width;
     dY = -e.PageBounds.Height;
     break;
  }
  // inform printDocument object if we still have to print
  e.HasMorePages = (++page != 4) ;
  // do transformation
  e.Graphics.TranslateTransform(dX, dY);
  // this is my picture
  e.Graphics.DrawEllipse(Pens.Black, 550, 700, 600, 900);
}

this is a very simplified engine, but I think this will help you.
0
 

Author Comment

by:nick81
ID: 8283102
Great it works, although i still have to fine tune it. But that shouldn't be difficult.

the example was a great help, thx.

Just for clarification, when u have e.HasMorePages and its true, it goes back to the start of the printDocument1_PrintPage method? until it's false whereby it prints the total printjob???

thx a lot

Nick
0
 
LVL 4

Expert Comment

by:Nebulus_
ID: 8283185
yes, if e.HasMorePages is true PrintPage another PrintPage event is raised for another page.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question