Link to home
Start Free TrialLog in
Avatar of nick81
nick81

asked on

Printing

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
Avatar of Nebulus_
Nebulus_

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.
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

Avatar of nick81

ASKER

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
Avatar of nick81

ASKER

Rereading it it seems slightly unclear

TranslateTransform works, its just that all the pages don't print.
More details please:
When you call RePrint and ReDraw, and what exactly ReDraw do?
Avatar of nick81

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Nebulus_
Nebulus_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nick81

ASKER

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
yes, if e.HasMorePages is true PrintPage another PrintPage event is raised for another page.