4
基本上,我想使用iTextSharp将一个字符串和一个条形码组合成一个单元格。 从它下面的代码是以下两行:iTextSharp在单个单元格中添加文本和条形码?
table.AddCell(tempstring);
table.AddCell(new text.Phrase(new text.Chunk(image39, 0, 0)));
完整的代码下面列出
using text = iTextSharp.text;
using pdf = iTextSharp.text.pdf;
text.Document doc = new text.Document();
pdf.PdfWriter writer = pdf.PdfWriter.GetInstance(doc, new FileStream(pdfgen.sWorkPath + "\\OrderNumber" + txtSellerNumber.Text.ToString() + ".pdf", FileMode.Create));
doc.Open();
pdf.PdfContentByte cb = writer.DirectContent;
pdf.Barcode39 code39 = new pdf.Barcode39();
code39.Code = txtSellerNumber.Text.ToString();
code39.StartStopText = false;
text.Image image39 = code39.CreateImageWithBarcode(cb, null, null);
iTextSharp.text.Table table = new iTextSharp.text.Table(3);
table.BorderWidth = 2;
table.BorderColor = new text.Color(0, 0, 255);
table.Padding = 3;
table.Spacing = 1;
text.Cell cell = new text.Cell("CHS");
cell.Header = true;
cell.Colspan = 3;
StringBuilder sb = new StringBuilder();
sb.Append("NAME" + Environment.NewLine);
sb.Append("Seller #" + txtSellerNumber.Text.ToString() + Environment.NewLine);
sb.Append("Size #" + txtSize1.Text.ToString() + Environment.NewLine);
sb.Append("Price #" + txtPrice1.Text.ToString() + Environment.NewLine);
sb.Append("Description : " + txtDescription1.Text.ToString() + Environment.NewLine);
string tempstring = sb.ToString();
//Wanting to combine the following two cells into 1
table.AddCell(tempstring);
table.AddCell(new text.Phrase(new text.Chunk(image39, 0, 0)));
//End
doc.Add(table);
doc.Close();
HttpContext.Current.Response.Redirect("~/OrderNumber" + txtSellerNumber.Text.ToString() + ".pdf", false);
谢谢@ steel-parker – 2013-09-07 12:22:26
添加图像到短语时,出现了一个“{”Insertion of illegal Element:34“}错误。您无法将图像添加到块。 – 2013-11-15 08:58:16