本文介绍了iTextSharp的添加文本以及条形码在一个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我想一个字符串条形码结合成使用iTextSharp的一个单元格。
从它下面的代码是以下两行:
table.AddCell(tempstring);
table.AddCell(新text.Phrase(新text.Chunk(image39,0,0)));
下面列出
完整的代码 使用文本= iTextSharp.text;使用PDF = iTextSharp.text.pdf
;
text.Document DOC =新text.Document();
pdf.PdfWriter作家= pdf.PdfWriter.GetInstance(文件,新的FileStream(pdfgen.sWorkPath +\\OrderNumber+ txtSellerNumber.Text.ToString()+.PDF的FileMode 。创建));
doc.Open();
pdf.PdfContentByte CB = writer.DirectContent;
pdf.Barcode39 CODE39 =新pdf.Barcode39();
code39.Code = txtSellerNumber.Text.ToString();
code39.StartStopText = FALSE;
text.Image image39 = code39.CreateImageWithBarcode(CB,NULL,NULL);
iTextSharp.text.Table表=新iTextSharp.text.Table(3);
table.BorderWidth = 2;
table.BorderColor =新text.Color(0,0,255);
table.Padding = 3;
table.Spacing = 1;
text.Cell电池=新text.Cell(CHS);
cell.Header = TRUE;
cell.Colspan = 3;
StringBuilder的SB =新的StringBuilder();
sb.Append(NAME+ Environment.NewLine);
sb.Append(「卖方#+ txtSellerNumber.Text.ToString()+ Environment.NewLine);
sb.Append(大小#+ txtSize1.Text.ToString()+ Environment.NewLine);
sb.Append(价格#+ txtPrice1.Text.ToString()+ Environment.NewLine);
sb.Append(描述:+ txtDescription1.Text.ToString()+ Environment.NewLine);
串tempstring = sb.ToString();
//婉婷以下两种细胞进入1 $ B $结合b table.AddCell(tempstring);
table.AddCell(新text.Phrase(新text.Chunk(image39,0,0)));
//结束
doc.Add(表);
doc.Close();
HttpContext.Current.Response.Redirect(〜/订单号码+ txtSellerNumber.Text.ToString()+.PDF,FALSE);
解决方案
其实很简单......
PdfPCell电池=新PdfPCell(table.DefaultCell / * *可选/);
cell.AddElement(tempString);
cell.AddElement(新text.Phrase(新text.Chunk(image39,0,0)));
table.AddCell(单元);
尝试了一些变化......你可能要experement了一下,像这样的
PdfPCell电池=新PdfPCell(table.DefaultCell / * *可选/);
短语词组=新词();
phrase.Add(新组块(tempString));
phrase.Add(新块(image39,0,0)));
cell.AddElement(短语);
table.AddCell(单元);
Basically, I want to combine a string with a barcode into a single cell using iTextSharp. From the code below it is the following two lines:
table.AddCell(tempstring);
table.AddCell(new text.Phrase(new text.Chunk(image39, 0, 0)));
FULL CODE LISTED BELOW
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);
解决方案
Rather simple actually...
PdfPCell cell = new PdfPCell( table.DefaultCell /* optional */ );
cell.AddElement( tempString );
cell.AddElement(new text.Phrase(new text.Chunk(image39, 0, 0)));
table.AddCell(cell);
try a few variations of that...you may have to experement a little, such as this
PdfPCell cell = new PdfPCell( table.DefaultCell /* optional */ );
Phrase phrase = new Phrase();
phrase.Add(new Chunk(tempString));
phrase.Add(new Chunk(image39, 0, 0)));
cell.AddElement( phrase );
table.AddCell(cell);
这篇关于iTextSharp的添加文本以及条形码在一个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!