C# Print dialog not printing all pages in c#
  • Hello
    i am having a issue while printing multiple pages in c#. I tried all possibilities but is not fixed yet. My issue is that i want to print 1 row per page but it is not doing so. currently it is printing only first row on all pages. . Here is the code
    In PrintPageEvent

    for (int i = 0; i < dt.Rows.Count; i++)
    {

    string cell = dt.Rows[i][0].ToString();
    // string itemx = dr["item_id"].ToString().PadLeft(6,'0');
    string itemx = cell.PadLeft(6, '0');
    string item2 = "*" + itemx + "*";
    string item3 = "*UMS" + itemx + "*";
    e.Graphics.DrawString(itemx, new Font("Free 3 of 9", 30, FontStyle.Regular), Brushes.Black, xValue, yValue);
    e.Graphics.DrawString(item3, new Font("Courier New", 14, FontStyle.Regular), Brushes.Black, xValue, yValue2);

    // yValue = yValue + 70;
    // yValue2 = yValue2 + 70;
    if (totalnumberA < dt.Rows.Count)
    {
    e.HasMorePages = true;
    totalnumberA++; //return;
    //eturn;
    }
    else
    {
    e.HasMorePages = false;
    //totalnumberA++; //return;
    }

    }


    At Button Click Event
    try
    {
    DBConnection DB = new DBConnection();
    DB.cnTransact.Open();
    string sql = "select * from tbl_items where serialNo='122'";
    cm = new SqlCommand(sql, DB.cnTransact);
    SqlDataAdapter people = new SqlDataAdapter(cm);
    people.Fill(dt);

    //foreach (DataRow dr in dt.Rows)
    }


    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    finally
    {

    }

    totalnumberA = 0;
    PrintDialog dialog = new PrintDialog();
    PrintDocument printDocument = new PrintDocument();
    dialog.Document = printDocument;
    printDocument.DefaultPageSettings.PaperSize = paperSize;
    dialog.ShowDialog();

    printDocument.PrintPage += PrintDocumentOnPrintPage;
    printDocument.DocumentName = "Barcodes";
    printDocument.Print();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative