.NET6 Ubuntu环境孟加拉字体无法正常显示问题排查
孟加拉字体在Ubuntu系统PDF中显示为方块的问题
- 问题现象:同一PDF文件在Windows系统中孟加拉字体显示正常,在Ubuntu系统中显示为方块(□)
- 对应截图:
- Windows正常显示效果:

- Ubuntu异常显示效果:

- Windows正常显示效果:
当前使用iTextSharp生成PDF,地址内容通过转换为图片的方式嵌入PDF,核心代码如下:
主逻辑代码
if (!string.IsNullOrEmpty(shippingAddressData.Address1)) { if (String.IsNullOrEmpty(shippingAddressData.Address2)) { var customercityStateZipCountry = await FormatAddressTextAsync(shippingAddressData); shippingAddress1 = shippingAddress1 + indent + "Address: " + shippingAddressData.Address1 + customercityStateZipCountry; } var customerAddress1Split = Split(shippingAddress1, 43); int i = 0; foreach (var customerAddress1BreakDown in customerAddress1Split) { if (i == 0) { var customerAddress1InBitMap = ConvertToBitMapDefault(customerAddress1BreakDown, 22f); Image customerAddress1InImage = Image.GetInstance(customerAddress1InBitMap, System.Drawing.Imaging.ImageFormat.Jpeg); shippingAddressPDF.AddCell(customerAddress1InImage); } else { var secondLine = indent + customerAddress1BreakDown; var customerAddress1InBitMap = ConvertToBitMapDefault(secondLine, 22f); Image customerAddress1InImage = Image.GetInstance(customerAddress1InBitMap, System.Drawing.Imaging.ImageFormat.Jpeg); shippingAddressPDF.AddCell(customerAddress1InImage); } i++; } }
辅助转换方法代码
public System.Drawing.Bitmap ConvertToBitMapDefault(string Text, float fontSize = 22f, int widthPoint = 0) { //string familyName = _fileProvider.Combine(_fileProvider.MapPath("~/App_Data/Pdf/"), "ARIALUNI.ttf"); //Path.Combine(CommonHelper.MapPath("~/App_Data/Pdf/"), "ARIALUNI.ttf"); string familyName = _fileProvider.Combine(_fileProvider.MapPath("~/App_Data/Pdf/"), _pdfSettings.FontFileName); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(850, 40, System.Drawing.Imaging.PixelFormat.Format24bppRgb); bitmap.SetResolution(500f, 200f); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage((System.Drawing.Image)bitmap); graphics.Clear(System.Drawing.Color.White); graphics.DrawString(Text ?? "", new System.Drawing.Font(familyName, fontSize, System.Drawing.FontStyle.Regular), System.Drawing.SystemBrushes.InfoText, (System.Drawing.PointF)new System.Drawing.Point(widthPoint, 3)); return bitmap; }
内容的提问来源于stack exchange,提问作者sina_Islam
相关产品推荐
相关产品推荐

