开发者

iTextSharp Adding Text plus Barcode in a single cell?

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;
        开发者_StackOverflow    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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜