在 C# 中获取字体的字节数组
我目前正在使用 iTextSharp,并且我想使用自定义字体。
这是我到目前为止所拥有的:
PrivateFontCollection fonts;
FontFamily family = LoadFontFamily("TheFont.ttf", out fonts);
var reader = new PdfReader("KurtBonne_test.pdf");
var stamper = new PdfStamper(reader,
new FileStream("Kurt Bonne_test_withtext.pdf", FileMode.Create));
var over = stamper.GetOverContent(1);
over.BeginText();
var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
//var bf = BaseFont.CreateFont("Test", BaseFont.CP1252, BaseFont.EMBEDDED, true,?,?)
over.SetFontAndSize(bf, 10);
over.SetTextMatrix(0, 140);
over.ShowText("page " + 0);
over.EndText();
stamper.Close();
现在,显然,BaseFont.CreateFont 有一个带有此签名的重载方法:
BaseFont.CreateFont(string name, string encoding, bool cached, byte[] ttfAfm, byte[] pfb);
现在,我如何使用 TheFont.ttf?不知怎的,我需要一个字节数组(ttfAfm)......
I'm using iTextSharp at the moment and I would like to use a custom font.
Here's what I have so far:
PrivateFontCollection fonts;
FontFamily family = LoadFontFamily("TheFont.ttf", out fonts);
var reader = new PdfReader("KurtBonne_test.pdf");
var stamper = new PdfStamper(reader,
new FileStream("Kurt Bonne_test_withtext.pdf", FileMode.Create));
var over = stamper.GetOverContent(1);
over.BeginText();
var bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
//var bf = BaseFont.CreateFont("Test", BaseFont.CP1252, BaseFont.EMBEDDED, true,?,?)
over.SetFontAndSize(bf, 10);
over.SetTextMatrix(0, 140);
over.ShowText("page " + 0);
over.EndText();
stamper.Close();
Now, apparently, the BaseFont.CreateFont has an overloaded method with this signature:
BaseFont.CreateFont(string name, string encoding, bool cached, byte[] ttfAfm, byte[] pfb);
Now, how do I use TheFont.ttf? Somehow I need a bytearray (ttfAfm)...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论