2015-07-11 14 views
5

Generuję kod kreskowy. Teraz chcę wstawić kod studenta pod etykietą z kodem kreskowym. W jaki sposób można to zrobić? Mój kod jestJak mogę dodać dwa wiersze w jednej komórce pdf?

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); 

Moja obecna wyjściowa jest enter image description here

chcę przynieść kod Student również pod etykietą z kodem kreskowym. Proszę mi pokazać sposób, aby to osiągnąć

Lub daj mi znać, jak przekazać więcej niż jeden parametr throgh funkcji pdftable.Addcell() .. !!

Odpowiedz

2

dodajesz obiekt Image bezpośrednio do a PdfPCell w następujący sposób:

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

Druga linia to skrót na coś, co wygląda tak:

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

Ten cell zawiera nic więcej niż obraz. Nie ma miejsca na tekst.

Jeśli chcesz połączyć obraz i tekst, trzeba coś takiego:

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

raz kolejny został zapisany me..Thaaankz drogiego looooot :) –

0

spróbować

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); 

Można również uzyskać skomplikowane i użyć podtabeli jeśli potrzebujesz większej kontroli:

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

Powiązane problemy