How to add two lines to one PDF cell?

I am creating a barcode. Now I want to insert the student code under the barcode label. How can i do this? My code

foreach (GridViewRow row in grdBarcode.Rows) { DataList dl = (DataList)row.FindControl("datalistBarcode"); PdfContentByte cb = new PdfContentByte(writer); PdfPTable BarCodeTable = new PdfPTable(6); BarCodeTable.SetTotalWidth(new float[] { 100,10,100,10,100,10 }); BarCodeTable.DefaultCell.Border = PdfPCell.NO_BORDER; Barcode128 code128 = new Barcode128(); code128.CodeType = Barcode.CODE128_UCC; foreach (DataListItem dli in dl.Items) { String barcodename= ((Label)dli.FindControl("lblBarCode")).Text; string studentcode= ((Label)dli.FindControl("lblStudCode")).Text; code128.Code = "*" + productID1 + "*"; iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null); BarCodeTable.AddCell(image128); BarCodeTable.AddCell(""); } doc.Add(BarCodeTable); 

My current exit enter image description here

I want to bring the student code also under the barcode label. Please show me a way to achieve this.

Or let me know how to pass a few parameters throgh pdftable.Addcell () function .. !!

+5
source share
2 answers

You add the Image object directly to PdfPCell as follows:

 iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null); BarCodeTable.AddCell(image128); 

The second line is a short abbreviation for what looks like this:

 PdfPCell cell = new PdfPCell(); cell.SetImage(image128); BarCodeTable.AddCEll(cell); 

This cell contains nothing more than an image. There is no room for text.

If you want to combine image and text, you need something like this:

 PdfPCell cell = new PdfPCell(); cell.AddElement(image128); Paragraph p = new Paragraph("Student name"); p.Alignment = Element.ALIGN_CENTER; cell.AddElement(p); BarCodeTable.AddCEll(cell); 
+2
source

try it

  var p = new Paragraph(); p.Add("First line text\n"); p.Add(" Second line text\n"); p.Add(" Third line text\n"); p.Add("Fourth line text\n"); myTable.AddCell(p); 

You can also get complicated and use a subtable if you need more control:

 var subTable = new PdfPTable(new float[] { 10, 100 }); subTable.AddCell(new PdfPCell(new Phrase("First line text")) { Colspan = 2, Border = 0 }); subTable.AddCell(new PdfPCell() { Border = 0 }); subTable.AddCell(new PdfPCell(new Phrase("Second line text")) { Border = 0 }); subTable.AddCell(new PdfPCell() { Border = 0 }); subTable.AddCell(new PdfPCell(new Phrase("Third line text")) { Border = 0 }); subTable.AddCell(new PdfPCell(new Phrase("Fourth line text")) { Colspan = 2, Border = 0 }); myTable.AddCell(subTable); 

http://www.mikesdotnetting.com/article/86/itextsharp-introducing-tables

0
source

All Articles