title: Using PrintDocument to print multiple pages
body: <p>I'm trying to print invoices. Invoices should be able to be printed on multiple pages, but that's where the problem kicks in. I can perfectly print an invoice on a single page, but as soon as the invoice doesn't fit on a single page, the printjob just quits on the first page.</p>
  
  <p>Here's the code I'm using. 'artikelen' is a list of articles (List). I have read several similar examples, and I'm fairly sure I'm missing something here.</p>
  
  <p>(Edited: some unneccesary code deleted)</p>
  
  <pre><code>public void PrintA4Factuur()
      {
          p = new PrintDocument();
          p.PrintPage +=
              new PrintPageEventHandler(printPage);
          printPreviewDialog.Document = p;
          printPreviewDialog.ShowDialog();
      }
  
  void printPage(object sender1, PrintPageEventArgs e1)
      {
  Graphics g = e1.Graphics;
  int yPos = 320;
  float pageHeight = e1.MarginBounds.Height;
  int artikelPosition = 0;
  while (yPos + 100 &lt; pageHeight
              &amp;&amp; artikelPosition &lt; this.artikelen.Count)
          {
              // Do stuff with articles (printing details in different rectangles
  
              artikelPosition += 1;
              yPos += 20;
          }
  
          if (artikelPosition &lt; this.artikelen.Count)
          {
              e1.HasMorePages = true;
              return;
          }
          else
          {
              e1.HasMorePages = false;
          }
  }
  </code></pre>