Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print list of images on paper.for this I have used PrintDocument Class.

When I give print, It will printing only first page.

After that I made one line as e.HasMorePages = true;

Then Its countineously printing on pages,even though I haven't much data,Images are repeating every time.

Below is my code.

When I insert e.HasMorePages=True;, it keeps on printing even though I passed two or three images.
C#
private void PrintPage(object o, PrintPageEventArgs e
    {
    List<eanbarcodeprintsourcemodel> EANBarcodePrintList = new
        List<eanbarcodeprintsourcemodel>();

    if (Session["Print"] != null)
        {
        int count = 50;
        EANBarcodePrintList = Session["Print"] as List<eanbarcodeprintsourcemodel>;
        for (int i = 0; i < EANBarcodePrintList.Count; i++)
            {
            string labelData = EANBarcodePrintList[i].ItemCode + " " +
                               EANBarcodePrintList[i].StyleNo + " " + 
                               EANBarcodePrintList[i].PlatingCode + " " +
                               EANBarcodePrintList[i].ColourCode;
            string MRPAmount = "MRP." + 
                               EANBarcodePrintList[i].ProductMRPAmount.
                                  ToString("N", new CultureInfo("te-IN"));

            e.Graphics.DrawString(labelData, 
                                  new Font("Tahoma", 7), 
                                  Brushes.Black, 
                                  new PointF(50, 40 + (count + 50 + (i * 50))));
            count += 30;
            e.Graphics.DrawImage(EANBarcodePrintList[i].NormakBarcodeImage, 
                                 50, 
                                 count + 70 + (i * 50), 150, 40);
            count += 20;
            e.Graphics.DrawString(EANBarcodePrintList[i].NormakBarcode, 
                                  new Font("Tahoma", 7), 
                                  Brushes.Black, 
                                  new PointF(90, 40 + (count + 50 + (i * 50))));
            count += 30;
            e.Graphics.DrawImage(EANBarcodePrintList[i].EanBarcodeImage, 
                                 50, 
                                 count + 70 + (i * 50), 150, 40);
            count += 20;
            e.Graphics.DrawString(EANBarcodePrintList[i].EANBarcode, 
                                  new Font("Tahoma", 7), 
                                  Brushes.Black, 
                                  new PointF(90, 40 + (count + 50 + (i * 50))));
            count += 10
            e.Graphics.DrawString(MRPAmount, 
                                  new Font("Tahoma", 7), 
                                  Brushes.Black, 
                                  new PointF(110, 40 + (count + 50 + (i * 50))));
            count += 30;
            }
        }

Can you please suggest Where I should put e.HasMorePages=true and e.HasMorePages=false; in above code?


Thanks in advance,
Kiran
Posted
Updated 28-May-14 8:32am
v3
Comments
ledtech3 13-Aug-13 10:23am    
without seeing more code it sounds like you are setting has more pages to true,but when it gets to the last page it is not getting set back to false, so just keeps printing until you stop it.

possibly need a counter to count the pages and then count up to the number of pages or down to zero then set has more pages to false .
kirankoleti 14-Aug-13 2:33am    
Can you please suggest Where I should put e.HasMorePages=true and e.HasMorePages=false; in above code?
gggustafson 28-May-14 14:33pm    
I moved your code up to the question. Please do not place code in a reply, it becomes unformatted. My comments follow.
Richard MacCutchan 13-Aug-13 11:30am    
Have you heard of loops and loop counters?
ledtech3 14-Aug-13 9:51am    
Here possibly this will help
http://msdn.microsoft.com/en-us/library/cwbe712d.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
the sample uses a counter on the length of the string to print.
While the length is greater than 0 then e.HasMorePages=true else e.HasMorePages=false

I'm not sure what you are doing there to be honest

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900