代码拉取完成,页面将自动刷新
using PdfSharp.Fonts; using System.Reflection; namespace pdfsharpDemo;/// <summary>/// 中文字体解析器/// </summary>public class ChineseFontResolver : IFontResolver{ /// <summary> /// 字体作为嵌入资源所在程序集 /// </summary> public static string FontAssemblyString { get; set; } = "pdfsharpDemo"; /// <summary> /// 字体作为嵌入资源所在命名空间 /// </summary> public static string FontNamespace { get; set; } = "pdfsharpDemo.Fonts"; /// <summary> /// 字体名称 /// </summary> public static class FamilyNames { // This implementation considers each font face as its own family. /// <summary> /// 仿宋 /// </summary> public const string SIMFANG = "simfang.ttf"; /// <summary> /// 黑体 /// </summary> public const string SIMHEI = "simhei.ttf"; /// <summary> /// 楷书 /// </summary> public const string SIMKAI = "simkai.ttf"; /// <summary> /// 隶书 /// </summary> public const string SIMLI = "simli.ttf"; /// <summary> /// 宋体 /// </summary> public const string SIMSUN = "simsun.ttf"; /// <summary> /// 宋体加粗 /// </summary> public const string SIMSUNB = "simsunb.ttf"; /// <summary> /// 幼圆 /// </summary> public const string SIMYOU = "simyou.ttf"; } /// <summary> /// Selects a physical font face based on the specified information /// of a required typeface. /// </summary> /// <param name="familyName">Name of the font family.</param> /// <param name="isBold">Set to <c>true</c> when a bold font face /// is required.</param> /// <param name="isItalic">Set to <c>true</c> when an italic font face /// is required.</param> /// <returns> /// Information about the physical font, or null if the request cannot be satisfied. /// </returns> public FontResolverInfo? ResolveTypeface(string familyName, bool isBold, bool isItalic) { // Note: PDFsharp calls ResolveTypeface only once for each unique combination // of familyName, isBold, and isItalic. return new FontResolverInfo(familyName, isBold, isItalic); // Return null means that the typeface cannot be resolved and PDFsharp forwards // the typeface request depending on PDFsharp build flavor and operating system. // Alternatively forward call to PlatformFontResolver. //return PlatformFontResolver.ResolveTypeface(familyName, isBold, isItalic); } /// <summary> /// Gets the bytes of a physical font face with specified face name. /// </summary> /// <param name="faceName">A face name previously retrieved by ResolveTypeface.</param> /// <returns> /// The bits of the font. /// </returns> public byte[]? GetFont(string faceName) { // Note: PDFsharp never calls GetFont twice with the same face name. // Note: If a typeface is resolved by the PlatformFontResolver.ResolveTypeface // you never come here. var name = $"{FontNamespace}.{faceName}"; using Stream stream = Assembly.Load(FontAssemblyString).GetManifestResourceStream(name) ?? throw new ArgumentException("No resource named '" + name + "'."); int num = (int)stream.Length; byte[] array = new byte[num]; stream.Read(array, 0, num); // Return the bytes of a font. return array; }}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。