我怎么能在一个单一的PDF小区添加两行? [英] How can I add two rows in a single pdf cell?
问题描述
我generatng条形码。现在我想的条形码标签下插入学生的代码。我怎么能这样做呢?我的代码是
I am generatng barcode. Now I want to insert the student code under the barcode label. How can I do this?My code is
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 present Output is
我要带学生代码也条形码标签下。请告诉我一个方法去实现它。
I want to bring the Student code also under the barcode label. Please show me a way to achieve it
还是让我知道如何传递多个参数throgh pdftable.Addcell()函数.. !!
Or let me know how to pass more than one parameters throgh pdftable.Addcell() function..!!
推荐答案
您要添加的图片
对象直接到 PdfPCell
是这样的:
You are adding the Image
object directly to a PdfPCell
like this:
iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null);
BarCodeTable.AddCell(image128);
第二行是短切的东西,看起来像这样:
The second line is a short cut for something that 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 an 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);
这篇关于我怎么能在一个单一的PDF小区添加两行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!