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

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
0
nick81
Asked:
nick81
  • 4
  • 4
1 Solution
 
Nebulus_Commented:
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
 
nir2002Commented:
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
 
nick81Author Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
nick81Author Commented:
Rereading it it seems slightly unclear

TranslateTransform works, its just that all the pages don't print.
0
 
Nebulus_Commented:
More details please:
When you call RePrint and ReDraw, and what exactly ReDraw do?
0
 
nick81Author Commented:
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
 
Nebulus_Commented:
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
 
nick81Author Commented:
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
 
Nebulus_Commented:
yes, if e.HasMorePages is true PrintPage another PrintPage event is raised for another page.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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