0

I'm trying to print multiple QR images in 1 page, but when i print i receive the last image only, the Code is:

int QRLoop = Convert.ToInt32(txtSerialTo.Text) - Convert.ToInt32(txtSerialFrom.Text) + 1;
for (int i = 0; i < QRLoop; i++)
{

int iSerial = Convert.ToInt32(txtSerialFrom.Text) + i;
string QRString = iSerial.ToString() + "," + dtpDate.Value.ToShortDateString() + "," + JobNr + "," + Batch + "," + LineNr + "," + Model;
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(QRString, QRCodeGenerator.ECCLevel.L, false, false, QRCodeGenerator.EciMode.Default, -1);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(1);
pbx[i].Image = qrCode.GetGraphic(1);
}

xx = 30;
yy = 0;
int x = 0;
for(int h = 0; h < QRLoop - 1; h++)
{
    p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
    {
        e1.Graphics.DrawImage(pbx[h].Image, xx, yy);
        e1.Graphics.DrawString((h + 1).ToString(), new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(xx + 45, yy + 5, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
    };
    xx += 91;
    x++;
    if (x == 4)
    {
        x = 0;
        xx = 30;
        yy += 47;
    }
}
p.Print();

Any help?

2
Contributors
5
Replies
26
Views
5 Days
Discussion Span
Last Post by hatem.ib
0

and yes i tried to debug with breakpoints and it was looping perfectly, but it prints only the last image, even i tried to do what loop does manually to check the problem, such as:

p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawImage(pbx[0].Image, 30, 0);
e1.Graphics.DrawString((1).ToString(), new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(75, 5, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};

p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawImage(pbx[1].Image, 121, 0);
e1.Graphics.DrawString((1).ToString(), new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(166, 5, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};

p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawImage(pbx[2].Image, 212, 0);
e1.Graphics.DrawString((1).ToString(), new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(257, 5, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};

p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawImage(pbx[3].Image, 303, 0);
e1.Graphics.DrawString((1).ToString(), new System.Drawing.Font("Arial", 9, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(348, 5, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};

p.Print();

and it printed the 4 images perfectly!!!

0

QRLoop Valued 16, but it could be changed, it's dynamic

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.