iTextSharp BarcodeEAN 13 改变宽度

iTextSharp BarcodeEAN 13 change width

我正在使用 iTextSharp 创建 EAN13 条形码,但我无法更改生成的条形码的宽度。 :( 使用 BarHeight = x

更改高度效果很好
System.Drawing.Image bm = code39.CreateDrawingImage(Color.Black, Color.White);
BarcodeEAN codeEan = new BarcodeEAN();
codeEan.CodeType = Barcode.EAN13;
codeEan.Code = "4035606872510";
codeEan.BarHeight = 130f;
codeEan.X = ... //not working
codeEan.Size = ... //also not working
bm = codeEan.CreateDrawingImage(Color.Black, Color.White);
bm.Save("D:\temp\foo.png", ImageFormat.Png);

/* Resizing only stretches the pixels with bad quality  */
iTextSharp.text.Image barcode = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Png);
barcode2.ScaleToFit(1200f, 130f);

自己找到解决办法.... 但对于有同样问题的人:

Document doc = new Document();
MemoryStream memStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memStream);
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
writer.CompressionLevel = PdfStream.BEST_COMPRESSION;
doc.Open();

PdfContentByte cb = writer.DirectContent;

BarcodeEAN codeEan = new BarcodeEAN();
codeEan.GenerateChecksum = true;
codeEan.CodeType = Barcode.EAN13;
codeEan.Code = "5449000101549";
codeEan.Font = null;

iTextSharp.text.Image imageEAN = codeEan.CreateImageWithBarcode(cb, null, null);
imageEAN.ScaleAbsolute(150, 50);
imageEAN.SetAbsolutePosition(doc.PageSize.Right - 186f, doc.PageSize.Bottom + 30f);
doc.Add(imageEAN);
...