Semil Sebastian
Semil Sebastian

Reputation: 519

how to add 3 imagecell in a single line in pdf?

I have 3 cells, which contains images and text. Iwant to bring these 3 cells in a single line(Horizondally). Now it comes vertical wise how can I do it and also want to reduce the font size also.plese help me. My code is

 PdfPTable BarCodeTable = new PdfPTable(3);
 BarCodeTable.SetTotalWidth(new float[] { 100,100,100});
 Barcode128 code128 = new Barcode128();
            code128.CodeType = Barcode.CODE128_UCC;
            int count = 1;
            foreach (DataListItem dli in dl.Items)
            {

                string productID11 = ((Label)dli.FindControl("lblBarCode")).Text;
                string studid1 = ((Label)dli.FindControl("lblStudCode")).Text;
                if (count == 1)
                {
                    code128.Code = "*" + productID11 + "*";
                    iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null);
                    cell.AddElement(image128);
                    Paragraph p = new Paragraph("" + studid1 + "");
                    p.Alignment = Element.ALIGN_CENTER;
                    cell.AddElement(p);
                    count++;
                }
                else if(count==2)
                {
                    code128.Code = "*" + productID11 + "*";
                    iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null);
                    cell.AddElement(image128);
                    Paragraph p = new Paragraph("" + studid1 + "");
                    p.Alignment = Element.ALIGN_CENTER;
                    cell.AddElement(p);
                    count++;
                }
                else if (count == 3)
                {
                    code128.Code = "*" + productID11 + "*";
                    iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null);
                    cell.AddElement(image128);
                    Paragraph p = new Paragraph("" + studid1 + "");
                    p.Alignment = Element.ALIGN_CENTER;
                    cell.AddElement(p);
                    count = 1;
                }

                BarCodeTable.AddCell(cell);
            }

            doc.Add(BarCodeTable);

How can I display 3 cells in a single line itself? Expected output is enter image description here

or let me know can I add this cell to another pdf table cell?

Upvotes: 1

Views: 152

Answers (1)

Semil Sebastian
Semil Sebastian

Reputation: 519

Myself found an answer for this..Take a look once it may help someone.

  int count=1;
 foreach (DataListItem dli in dl.Items)
    {

     string barcode = ((Label)dli.FindControl("lblBarCode")).Text;
     string studcode = ((Label)dli.FindControl("lblStudCode")).Text;
     if (count == 1)
      {
         PdfPCell cell0 = new PdfPCell();
         code128.Code = "*" + barcode + "*";
         iTextSharp.text.Image image128111 = code128.CreateImageWithBarcode(cb, null, null);
         cell0.AddElement(image128111);
         Paragraph p = new Paragraph("" + studcode + "");
         p.Alignment = Element.ALIGN_CENTER;
         cell0.AddElement(p);
         BarCodeTable.AddCell(cell0);
         BarCodeTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
         BarCodeTable.AddCell(new Phrase(new Phrase("", times11)));
         count++;
      }
      else if (count == 2)
       {
          PdfPCell cell1 = new PdfPCell();
          code128.Code = "*" + barcode + "*";
          iTextSharp.text.Image image1281 = code128.CreateImageWithBarcode(cb, null, null);
          cell1.AddElement(image1281);
          Paragraph p1 = new Paragraph("" + studcode + "");
          p1.Alignment = Element.ALIGN_CENTER;
          cell1.AddElement(p1);
          BarCodeTable.AddCell(cell1);
          BarCodeTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
          BarCodeTable.AddCell(new Phrase(new Phrase("", times11)));
          count++;
        }
       else if(count==3)
        {
            PdfPCell cell2 = new PdfPCell();
            code128.Code = "*" + barcode + "*";
            iTextSharp.text.Image image1282 = code128.CreateImageWithBarcode(cb, null, null);
            cell2.AddElement(image1282);
            Paragraph p2 = new Paragraph("" + studcode + "");
            p2.Alignment = Element.ALIGN_CENTER;
            cell2.AddElement(p2);
            BarCodeTable.AddCell(cell2);
            count = 1;
         }
       }
     doc.Add(BarCodeTable);

The output would be like this, enter image description here

Upvotes: 1

Related Questions