使用iTextSharp dll,沒有直接的方式在條形碼圖像下面顯示文本。我試了一下,並有一個解決方法來顯示文本。這不是一個直接的解決方案,但會提供類似於條形碼圖像的預期輸出。
要生成條形碼圖像,我使用JP Hellemons在他的博客中共享的輸入。謝謝JP Hellemons! http://www.jphellemons.nl/post/Make-a-code128-barcode-with-C-sharp-and-iTextSharp.aspx
,我使用的代碼:
Barcode128 code128 = new Barcode128();
code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = false;
code128.Code = <<Barcode value>>;
// Create a blank image
System.Drawing.Bitmap bmpimg = new Bitmap(120,35); // provide width and height based on the barcode image to be generated. harcoded for sample purpose
Graphics bmpgraphics = Graphics.FromImage(bmpimg);
bmpgraphics.Clear(Color.White); // Provide this, else the background will be black by default
// generate the code128 barcode
bmpgraphics.DrawImage(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(0, 0));
//generate the text below the barcode image. If you want the placement to be dynamic, calculate the point based on size of the image
bmpgraphics.DrawString(<<Barcode value>>, new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(15, 24));
// Save the output stream as gif. You can also save it to external file
bmpimg.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
糾正我,如果我錯了..
如果您有任何的直接或簡單的解決方案,請分享..
可以幫助嗎?[this](http://stackoverflow.com/questions/3215522/itextsharp-adding-text-plus-barcode-in-a-single-cell)有幫助嗎? – 2011-02-07 03:28:15