I am trying to print an invoice. Invoices should be printed on several pages, but where the problem arises. I can perfectly print the invoice on one page, but as soon as the invoice does not fit on one page, the press just shuts down the first page.
Here is the code I'm using. "artikelen" is a list of articles (List). I read several similar examples, and I'm sure something is missing here.
(Edited: some someecceary code deleted)
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 < pageHeight
&& artikelPosition < this.artikelen.Count)
{
artikelPosition += 1;
yPos += 20;
}
if (artikelPosition < this.artikelen.Count)
{
e1.HasMorePages = true;
return;
}
else
{
e1.HasMorePages = false;
}
}
source
share