如何在 C# 中的 iTextSharp pdf 中将位图显示为 jpeg 格式

How to display bitmap to jpeg formate in iTextSharp pdf in c#

我正在转换条形码中的文本,效果很好。然后将条形码转换为位图,工作正常。但是我不想保存条形码,而是想在 pdf 上显示它。 在这里,我使用 iTextSharp 生成 Pdf 和条形码。 下面是我的代码:-

Barcode128 code128 = new Barcode128
                            {
                                CodeType = Barcode.CODE128,
                                ChecksumText = true,
                                X = 1.1f,
                                BarHeight = 20,
                                GenerateChecksum = true,
                                StartStopText = true,
                                Code = "Angular 9"
                            };

Bitmap bms = new Bitmap(code128.CreateDrawingImage(Color.Black, Color.White));

我不想保存。但是直接显示在我的pdf

bb.Save("E:/API/MyBarCode.jpg", System.Drawing.Imaging.ImageFormat.Gif);

** 在 pdf 中附加我的 html,例如 this.Here img src 我正在创建动态文件名。在img src中我想直接传值** sb.Append("<img src='" + dta.Rows[0]["PATH"].ToString() + "'></img>");

那我可以吗?请帮忙。

您可以通过以下方式在 PDF 中显示您的条码(无需创建中间位图):

PdfContentByte canvas = writer.getDirectContent();
    
Barcode128 code128 = new Barcode128 { ... };
code128.placeBarcode(canvas, BaseColor.BLACK, BaseColor.BLACK);