Click here to Skip to main content
14,450,530 members

I want change font size to print text

Pirasanthan asked:

Open original thread
This is my printing codes
Now it's printing as default font size. Now I want to change font size to print text, give me solution for that.

Thanks for advance.


public override string PrintKOTOrders(string connectionString, long[] orderDetailNumbers, string userName, bool isReprint)
{
    string error = string.Empty;

    RawPrinterHelper receiptPrinter = new RawPrinterHelper();

    ReceiptFunction receiptFunction = new ReceiptFunction();
    

    DataSet ds = receiptFunction.GetKOTNoteFromDataSet(connectionString, orderDetailNumbers);

    DataTable headerTable = new DataTable();
    DataTable foodTable = new DataTable();
    DataTable foodModifierTable = new DataTable();

    DataTable foodPrinters = new DataTable();
    DataTable foodModifierPrinters = new DataTable();
    DataTable reciprtPrinters = new DataTable();

    if (ds.Tables.Count > 0)
    {
        headerTable = ds.Tables[0];

        if (ds.Tables.Count > 1)
        {
            foodTable = ds.Tables[1];

            string[] printerName = { "PrinterName", "FoodDept" };

            foodPrinters = this.GetDistinctRecords(foodTable, printerName);

            if (ds.Tables.Count > 2)
            {
                foodModifierTable = ds.Tables[2];

                foodModifierPrinters = this.GetDistinctRecords(foodModifierTable, printerName);
            }

            reciprtPrinters = foodPrinters.Copy();
            reciprtPrinters.Merge(foodModifierPrinters);

            reciprtPrinters = this.GetDistinctRecords(reciprtPrinters, printerName);

        }
        else
        {
            error = "No Food Records";
        }
    }
    else
    {
        error = "No Header Records";
    }

    string displayString = string.Empty;

    foreach (DataRow printer in reciprtPrinters.Rows)
    {
        receiptPrinter.PrinterName = printer["PrinterName"].ToString();

        if (isReprint)
        {
            this.PrintImage.PrintDuplicateImage(receiptPrinter, 28);
        }
        
        displayString += Environment.NewLine;
        displayString += "Order No   : " + headerTable.Rows[0]["OrderId"].ToString().Trim() + "/" + printer["FoodDept"].ToString().Trim() + Environment.NewLine;
        displayString += "Order Date : " + headerTable.Rows[0]["OrderDate"].ToString() + Environment.NewLine;
        displayString += "Table(s)   : " + headerTable.Rows[0]["TableblNos"].ToString().Trim() + Environment.NewLine;
        displayString += "Res No     : " + headerTable.Rows[0]["ReservationID"].ToString().Trim() + "  No of Guest(s): " + headerTable.Rows[0]["NoOfGuest"].ToString().Trim() + Environment.NewLine;
        displayString += "Order Taken: " + userName + Environment.NewLine;
        displayString += "C  Item                         Quantity" + Environment.NewLine;
        displayString += "----------------------------------------" + Environment.NewLine;
        


        this.Print(receiptPrinter, displayString);
        displayString = string.Empty;

        string foodDepartmentID = printer["FoodDept"].ToString();

        string filter = string.Format("FoodDept = '{0}'", foodDepartmentID);
        DataRow[] foodPrinter = foodTable.Select(filter);

        foreach (DataRow foodRow in foodPrinter)
        {
            this.PrintKOTLines(foodRow, false, receiptPrinter, false);
        }

        filter = string.Empty;
        filter = string.Format("FoodDept = '{0}' AND ModifierString is NOT NULL", foodDepartmentID);

        DataRow[] foodModifierPrinter = foodModifierTable.Select(filter);

        foreach (DataRow foodRow in foodModifierPrinter)
        {
            this.PrintKOTLines(foodRow, false, receiptPrinter, false);

            // modifier print section

            string modifiers = foodRow["ModifierString"].ToString();

            string[] modifierArray = modifiers.Split(',');
            List<string> modifierList = new List<string>(modifierArray);

            var grouped = modifierList.GroupBy(s => s).Select(g => new { FoodID = g.Key.ToString().Trim(), Count = g.Count() });

            foreach (var item in grouped)
            {
                filter = string.Empty;
                filter = string.Format("FoodDept = '{0}' AND ModifierString is NULL AND  FoodID = '{1}'", foodDepartmentID, item.FoodID);

                DataRow[] modifierPrinter = foodModifierTable.Select(filter);

                if (modifierPrinter.Count() > 0)
                {
                    string modifierName = modifierPrinter[0]["NAME"].ToString();
                    int modifierCount = int.Parse(modifierPrinter[0]["Quantity"].ToString());

                    int foodCount = 1;
                    int.TryParse(foodRow["Quantity"].ToString(), out foodCount);
                    int modifierQuantity = 0;

                    if (modifierCount < 0)
                    {
                        modifierQuantity = foodCount * int.Parse(item.Count.ToString()) * modifierCount;
                    }
                    else
                    {
                        modifierQuantity = foodCount * int.Parse(item.Count.ToString());
                    }

                    int length = (31 - modifierName.Length);
                    if (length < 0)
                    {
                        length = 0;
                    }

                    if (modifierName.Length <= 25)////30
                    {
                        if (modifierQuantity.ToString().Length > 1)
                        {
                            displayString += "     " + modifierName + " ".PadLeft(length) + " " + modifierQuantity.ToString() + Environment.NewLine;
                        }
                        else
                        {
                            displayString += "     " + modifierName + " ".PadLeft(length) + "  " + modifierQuantity.ToString() + Environment.NewLine;
                        }
                    }
                    else
                    {
                        int p = 0;
                        while (modifierName.Substring(p, p + 26).Length >= 26)
                        {
                            if (modifierQuantity.ToString().Length > 1)
                            {
                                displayString += "    " + modifierName + " ".PadLeft(length) + "    " + modifierQuantity.ToString() + Environment.NewLine;
                            }
                            else
                            {
                                displayString += "    " + modifierName + " ".PadLeft(length) + "  " + modifierQuantity.ToString() + Environment.NewLine;
                            }

                            modifierName = modifierName.Substring(p + 26, modifierName.Length - 26);

                            if (modifierName.Length < 26)
                            {
                                displayString += ("    " + modifierName + Environment.NewLine);
                                break;
                            }

                        }

                    }

                    //displayStringL1 += "    " + modifierName + " ".PadLeft(length) + modifierQuantity.ToString() + Environment.NewLine;

                    this.Print(receiptPrinter, displayString);
                    displayString = string.Empty;
                }

            }

        }
        displayString += string.Empty + Environment.NewLine + Environment.NewLine;
        displayString = this.CutPrinterPaper(displayString);
        this.Print(receiptPrinter, displayString);
        displayString = string.Empty;
    }

    return error;

}
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100