Không có cách trực tiếp nào để hiển thị văn bản bên dưới hình ảnh mã vạch bằng cách sử dụng dll iTextSharp. Tôi đã thử như vậy và đã có một cách giải quyết để hiển thị văn bản. Đây không phải là giải pháp trực tiếp, nhưng sẽ cung cấp đầu ra tương tự như những gì được mong đợi từ hình ảnh mã vạch.
Để tạo hình ảnh mã vạch, tôi đã sử dụng các đầu vào được chia sẻ bởi JP Hellemons trong blog của mình. Cảm ơn JP Hellemons! http://www.jphellemons.nl/post/Make-a-code128-barcode-with-C-sharp-and-iTextSharp.aspx
Mã mà tôi đã sử dụng:
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);
Đúng tôi nếu tôi đã sai ..
Nếu bất kỳ của bạn có một giải pháp trực tiếp hoặc đơn giản hơn, xin vui lòng chia sẻ chúng ..
Nguồn
2012-02-09 14:34:37
Có thể trợ giúp [this] (http://stackoverflow.com/questions/3215522/itextsharp-adding-text-plus-barcode-in-a-single-cell) không? –