Goran Bibic

Goran Bibic

  • 452
  • 2.9k
  • 177.5k

Bar code instead text in column c#

Jul 1 2020 7:38 AM
Itextsharp
 
Need in last column instead text need to be bar code 128 from that text
 
 
 
Or can be image to be  paste across text in column
 
Bar code c# code:
 
  1. //Adding DataRow  
  2.            foreach (DataGridViewRow row in OperacijeDataGridView.Rows)  
  3.            {  
  4.                foreach (DataGridViewCell cell in row.Cells)  
  5.                {  
  6.                    PdfPCell cell2 = new PdfPCell(new Phrase(cell.Value.ToString(), calibri));  
  7.                    cell2.HorizontalAlignment = Element.ALIGN_LEFT;  
  8.   
  9.                    Barcode128 code128 = new Barcode128();  
  10.                    code128.CodeType = Barcode.CODE128_RAW;  
  11.                    code128.ChecksumText = true;  
  12.                    code128.GenerateChecksum = true;  
  13.                    code128.Code = Barcode128.GetRawText(row.Cells[1].Value.ToString(), false, Barcode128.Barcode128CodeSet.AUTO);  
  14.                    System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));  
  15.                    iTextSharp.text.Image barCode = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Png);  
  16.                    //PdfPCell pdfCell = new PdfPCell();  
  17.                    PdfPTable tmpTable = new PdfPTable(1);  
  18.                    tmpTable.WidthPercentage = 100;  
  19.                    PdfPCell tmpCell = new PdfPCell(barCode);  
  20.                    tmpTable.AddCell(new Paragraph(row.Cells[12].Value.ToString().ToUpper(), calibri));  
  21.                    barCode.ScaleAbsolute(70, 30); //100x40  
  22.                    tmpCell.FixedHeight = 40;//60  
  23.                    tmpCell.HorizontalAlignment = Element.ALIGN_CENTER;  
  24.                    tmpCell.VerticalAlignment = Element.ALIGN_MIDDLE;  
  25.                    tmpCell.BorderWidth = 0;  
  26.                    tmpTable.AddCell(tmpCell);  
  27.                    tmpTable.DefaultCell.BorderWidth = 0;  
  28.                    tmpTable.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;  
  29.                    tmpTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;  
  30.                    //tmpTable.AddCell(new Paragraph(row.Cells[4].Value.ToString().ToUpper(), calibri6));  
  31.                    //tmpTable.AddCell(new Paragraph(row.Cells[12].Value.ToString().ToUpper(), calibri));  
  32.                   // pdfCell.AddElement(tmpTable);  
  33.                    tmpCell.AddElement(tmpTable);  
  34.                    pdfTable.AddCell(tmpCell);  
  35.   
  36.                    pdfTable.AddCell(cell2);  
  37.                }  
  38.            } 
 

Answers (2)