I am facing issue with the spire barcode generation with fontsize . When ever input of barcode increase from 5 the size of image increases , I need to adjust it to the fix dimension.
BarcodeSettings settings = new BarcodeSettings();
settings.Data = AccessionNo;
settings.HasBorder = false;
settings.ShowText = true;
settings.ShowTextOnBottom = true;
settings.TextAlignment = System.Drawing.StringAlignment.Center;
settings.TextColor = System.Drawing.Color.Black;
settings.Type = Spire.Barcode.BarCodeType.Code128;
settings.Code128SetMode = Code128SetMode.OnlyA;
settings.TextFont = new System.Drawing.Font("Helvetica", 8, FontStyle.Regular);
string resultString = Regex.Match(AccessionNo, @"\d+").Value;
//if(Convert.ToInt32(resultString) > 9)
//{
// settings.TextFont = new System.Drawing.Font("Helvetica", 7, FontStyle.Regular);
// settings.DpiX = 121;
//settings.DpiY = 121;
//}
//else
//{
//settings.TextFont = new System.Drawing.Font("Helvetica", 8, FontStyle.Regular);
//settings.DpiX = 140;
//settings.DpiY = 140;
//}
settings.DpiX = 121;
settings.DpiY = 121;
settings.Unit = GraphicsUnit.Millimeter;
settings.BarHeight = 6;
settings.TopMargin = 0f;
settings.LeftMargin = 0f;
settings.RightMargin = 0f;
settings.BottomMargin = 0f;
settings.ShowTopText = false;
System.Drawing.Image barcode = null;
`
Before setting the height and width, you need to add this line of code: settings.AutoResize = false;
Example:
int width = 400;
int height = 200;
settings.AutoResize = false;
settings.X = 3.0f;
//Bar height
settings.BarHeight = height * 0.6f;
//Image width and height
settings.ImageWidth = width;
settings.ImageHeight = height;
//....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.