从资源加载basefont [英] Load basefont from resource

查看:1646
本文介绍了从资源加载basefont的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ITextSharp并将插入项目中的字体文件作为资源加载。

I'm trying to use ITextSharp and load a font file inserted in my project as resource.

我尝试了不同的解决方案,但它们似乎都不起作用,这里我所做的一个样本:

I try different solutions but none of them seems to work, here a sample of what I did:

这个无法加载资源

  private static BaseFont _bfArial;
    public static BaseFont BfArial
    {
        get
        {
            if (_bfArial == null)
                _bfArial = BaseFont.CreateFont(@"Resources\Images\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            return _bfArial;
        }
    }

这个给我一个错误:'身份 - H'不是受支持的编码名称。

this one gives me an error: "'Identity-H' is not a supported encoding name."

 private static BaseFont _bfCourier;
    public static BaseFont BfCourier
    {
        get
        {
            if (_bfCourier == null)
                _bfCourier = BaseFont.CreateFont("Courier", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, FontsResources.cour, null);

            return _bfCourier;
        }
    }

以及我在解决方案中添加文件的方式

and here the way I add the files in my solution

你能帮我解决这个问题吗?谢谢

Can you please help me solving this issue? thank you

Andrea

推荐答案

尝试使用:

Byte[] fb = Properties.Resources.arialuni;
_bfArial = BaseFont.CreateFont("arialuni.ttf", BaseFont.CP1252, BaseFont.EMBEDDED, BaseFont.CACHED, fb, null);

属性出现在解决方案资源管理器中的GIGPrinting下,Properties.Resources是参考到资源文件夹。

"Properties" appear under "GIGPrinting" in the Solution Explorer and "Properties.Resources" is the reference to the resources folder.

这篇关于从资源加载basefont的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆