'Only print when PrintDocument.PrintPage has generated all pages

I have an object of type List<Image>. Now I want to print every item in the list in repeat until my document has reached 140 pages. This is my current code which does exactly this:

int printed = 0;

List<Image> images = new List<Image>();

foreach (var imagePath in product.Images)
{
    Image picture = Image.FromFile(imagePath);
    images.Add(picture);
}

int index = 0;

pd.PrintPage += (o, e) =>
{
    printed++;

    if (printed < configuration.PageAmount)
    {
        e.HasMorePages = true;
    }
    else
    {
        index = 0;
    }

    e.Graphics.DrawImage(images[index], e.PageBounds);
    index++;

    if (index >= images.Count)
    {
        index = 0;
    }    
};

pd.Print();

Unfortunately, due to the printer driver, I cannot start printing until all 140 pages have been generated. However, the print process already starts with the first call of e.Graphics.DrawImage. Is there any easy way to achive this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source