private void PopulateBarCode(int PurchaseID)
    {
        try
        {
            StringBuilder sbBarcode = new StringBuilder();
            string thisBarcode = string.Empty;
            if (txtSearch.Text.Trim() != "Search")
            {
                objPI.SearchText = txtSearch.Text.Trim();
            }
            else
            {
                objPI.SearchText = "";
            }


            SaleBLL objSaleBLL = new SaleBLL();

            List<Sale> objData = new List<Sale>();
            objData = objSaleBLL.GetAllProductBarCode(objPI, PurchaseID);

            if (objData != null)
            {
                int Kounter = 0;
                for (int i = 0; i < objData.Count; i++)
                {
                    int PurchaseQuantity =(int)objData[i].Quantity;
                    
                    for (int ii = 0; ii < PurchaseQuantity; ii++)
                    {
                        thisBarcode = BarcodeHTML;
                        thisBarcode = thisBarcode.Replace("[brandname]", objData[i].Brand);
                        thisBarcode = thisBarcode.Replace("[productname]", objData[i].ProductName);
                        thisBarcode = thisBarcode.Replace("[productsize]", objData[i].SizeName);
                        thisBarcode = thisBarcode.Replace("[sellingprice]", string.Format("{0:0.00}", objData[i].Price));
                        string BarCode = objData[i].BarCode;
                        thisBarcode = thisBarcode.Replace("[dvbarcode]", "dvbarcode" + (Kounter + 1).ToString());
                        thisBarcode = thisBarcode.Replace("[barcode]", BarCode);
                        thisBarcode = thisBarcode.Replace("[dvbarcodePrint]", "dvbarcodePrint" + (Kounter + 1).ToString());
                        thisBarcode = thisBarcode.Replace("[barcodePrint]", "[barcodePrint" + (Kounter + 1).ToString() + "]");
                        thisBarcode = thisBarcode.Replace("[QuantityID]", "txtQuantity" + (Kounter + 1).ToString());
                        //thisBarcode = thisBarcode.Replace("[chkPrint]", "chkPrint" + (Kounter + 1).ToString());
                        thisBarcode = thisBarcode.Replace("[imageID]", "PrinterID" + (Kounter + 1).ToString());
                        thisBarcode = thisBarcode.Replace("[thisID]", (Kounter + 1).ToString());
                        sbBarcode.Append(thisBarcode);
                        Kounter++;
                    }
                    
                }
            }

            dvBarcodes.InnerHtml = sbBarcode.ToString();
        }
        catch (Exception ex)
        {
            SendMail.MailMessage("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
        }
    }
    private void PopulateBarCode(int PurchaseID)
    {
        //Rectangle pageSize = new Rectangle(842, 595);
        Rectangle pageSize = new Rectangle(62,29);
        //Document document = new Document(PageSize.A4_LANDSCAPE, 10, 10, 10, 10);
        Document document = new Document(pageSize, 0, 0, 2, 0);
        string TimeStamp = DateTime.Now.Ticks.ToString();
        try
        {
            StringBuilder sbBarcode = new StringBuilder();
            string thisBarcode = string.Empty;

            objPI.SearchText = "";

            SaleBLL objSaleBLL = new SaleBLL();

            List<Sale> objData = new List<Sale>();
            objData = objSaleBLL.GetAllProductBarCode(objPI, PurchaseID);


            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~") + "/Handler/BarCode_" + TimeStamp + ".pdf", FileMode.Create));
            document.Open();
            PdfContentByte pdfContentByte = pdfWriter.DirectContent;
            iTextSharp.text.Image img;

            if (objData != null)
            {
                int Kounter = 0;
                for (int i = 0; i < objData.Count; i++)
                {
                    int PurchaseQuantity = (int)objData[i].Quantity;

                    for (int ii = 0; ii < PurchaseQuantity; ii++)
                    {
                        if (Kounter > 0)
                            document.NewPage();

                        PdfPTable table = new PdfPTable(2);
                        //table.TotalWidth = 176f;
                        //fix the absolute width of the table
                        //table.LockedWidth = true;

                        //relative col widths in proportions
                        //float[] widths = new float[] { 1f, 1f };
                        //table.SetWidths(widths);
                        table.HorizontalAlignment = 1;
                        //leave a gap before and after the table
                        //table.SpacingBefore = 1f;
                        //table.SpacingAfter = 1f;
                        table.WidthPercentage = 95;

                        PdfPCell cell = new PdfPCell(new Phrase(objData[i].Brand, new Font(Font.FontFamily.HELVETICA, 3f, Font.BOLD)));
                        cell.Colspan = 2;
                        cell.Border = 0;
                        cell.Padding = 0f;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);

                        cell = new PdfPCell(new Phrase(objData[i].ProductName, new Font(Font.FontFamily.HELVETICA, 2f, Font.NORMAL)));
                        cell.Colspan = 2;
                        cell.Border = 0;
                        cell.Padding = 0f;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);

                        cell = new PdfPCell(AddSize(objData[i].SizeName));
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        cell.Border = 0;
                        cell.Padding = 0f;
                        table.AddCell(cell);

                        cell = new PdfPCell(new Phrase("€ " + string.Format("{0:0.00}", objData[i].Price), new Font(Font.FontFamily.HELVETICA, 4f, Font.BOLD)));
                        cell.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right
                        cell.Border = 0;
                        cell.Padding = .5f;
                        table.AddCell(cell);

                        pdfContentByte = pdfWriter.DirectContent;
                        img = GetBarcode128(pdfContentByte, objData[i].BarCode, false, Barcode.CODE128);

                        cell = new PdfPCell(); //new Phrase(new Chunk(img, 0, 0)));
                        cell.AddElement(img);
                        cell.Colspan = 2;
                        cell.Border = 0;
                        cell.Padding = 0f;
                        //cell.FixedHeight = img.Height + 200;
                        cell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
                        table.AddCell(cell);

                        document.Add(table);

                        Kounter++;
                    }

                }
                document.Close();

            }

            HttpContext context = HttpContext.Current;
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AppendHeader("Content-Disposition", "attachment; filename=Barcode_" + TimeStamp + ".pdf");
            Response.WriteFile(Server.MapPath("~/Handler/BarCode_" + TimeStamp + ".pdf"));
            Response.Flush();
            Response.Close();
            if (File.Exists(Server.MapPath("~/Handler/BarCode_" + TimeStamp + ".pdf")))
            {
                File.Delete(Server.MapPath("~/Handler/BarCode_" + TimeStamp + ".pdf"));
            }

        }
        catch (Exception ex)
        {
            if (document.IsOpen())
                document.Close();
            SendMail.MailMessage("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
            Response.Write(ex.ToString());
        }
    }