You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First thanks to the author for providing a good library, but I had a problem with version 6.0, that is, using Chinese fonts will make an error, what can I do to solve it.
Error:
System.InvalidOperationException:“No appropriate font found for family name '宋体'. Implement IFontResolver and assign to 'GlobalFontSettings.FontResolver' to use fonts.”
Code:
// 创建一个新的PDF文档
using (PdfDocument document = new PdfDocument())
{
// 添加一页
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
// 加载字体
//XFont font = new XFont("simsun.ttc", 12, XFontStyleEx.Regular);
XFont font = new XFont("宋体", 12, XFontStyleEx.Regular);
// 绘制中文文本
gfx.DrawString("你好,世界!", font, XBrushes.Black, new XRect(50, 50, page.Width, page.Height), XStringFormats.TopLeft);
// 保存PDF文档
string outputPath = "D://output.pdf";
document.Save(outputPath);
}
The text was updated successfully, but these errors were encountered:
First thanks to the author for providing a good library, but I had a problem with version 6.0, that is, using Chinese fonts will make an error, what can I do to solve it.
Error:
Code:
The text was updated successfully, but these errors were encountered: