使用自定义字体在Azure上使用PDFsharp [英] PDFsharp on Azure with Custom Fonts

查看:117
本文介绍了使用自定义字体在Azure上使用PDFsharp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure上的Web应用程序使用PDFsharp 1.32创建PDF.因为它是Azure Web应用程序,所以我无法安装字体.

I am using a webapp on azure to create a PDF using PDFsharp 1.32. As it is a Azure webapp I cannot install fonts.

因此,我在嵌入式字体选项中使用了以下内容:

Therefore I am using the following with embedded font options:

var globalFontCollection = XPrivateFontCollection.Global;
_fontBytes = File.ReadAllBytes(_pathToFont);   
globalFontCollection.AddFont(_fontBytes, _fontName);

但是,这不起作用.不会出现任何错误,就好像字体是未知的并退回到默认字体一样.如果我安装了该字体,它将起作用,因此我知道其余代码是正确的.

However this does not work. There is no error just acts as if the font is not known and falls back to the default. If I install the font it works so I know the rest of the code is correct.

其他代码显示了使用具有不同参数的AddFont,但是这些参数对我来说不可用,而查看源代码,这是唯一实现的方法.

Other code shows using AddFont with different parameters however those are not available to me and looking at the source code this is the only implemented method.

有人知道正确的代码以允许我们使用未安装的字体吗?

Does anyone know the correct code to allow us to use non installed fonts?

推荐答案

已经全面修订了PDFsharp 1.50的字体处理-还考虑了Azure和Medium Trust.我建议对Azure使用PDFsharp 1.50(最新版本为beta 3)或更高版本.我认为WPF的构建将是适当的.
新的IFontResolver使您可以更好地控制字体处理.
PDFsharp 1.50的示例程序包包括一个示例.另外,您也可以使用第三方的 EZFontResolver .

The font handling of PDFsharp 1.50 was overhauled - also with Azure and Medium Trust in mind. I'd recommend using PDFsharp 1.50 (latest version is beta 3) or later for Azure. I think the WPF build will be appropriate.
The new IFontResolver gives you better control of font handling.
The samples package for PDFsharp 1.50 includes a sample. Alternatively you can use EZFontResolver from a third party.

关于PDFsharp 1.32:有不同的内部版本,它们暴露了AddFont的不同重载.我也建议使用Azure的WPF构建.
字体处理是特定于平台的(GDI +或WPF).要使平台使用自定义字体,可能很难获得字体名称正确".
PDFsharp 1.32包含一个有效的WPF示例,该示例使用资源中的字体.您可以使用此示例开始.

With respect to PDFsharp 1.32: there are different builds that expose different overloads for AddFont. I'd also recommend the WPF build for Azure.
Font handling is platform-specific (GDI+ or WPF). It can be difficult to get the font names "correct" to have the platform use the custom font.
PDFsharp 1.32 includes a working WPF sample that uses a font from a resource. You can use this sample to get started.

GDI +不是Azure网站的选项.因此,WPF是必经之路.我将在新的IFontResolver接口上使用1.50版.通过EZFontResolver实现,易于使用. PDFsharp 1.50的一个示例显示了IFontResolver的实现,如果您想在没有EZFontResolver的情况下将其用作模板,则可以将其用作模板.

GDI+ is not an option for Azure web sites as far as I know. So WPF is the way to go. I would use version 1.50 with the new IFontResolver interface. With the EZFontResolver implementation it is easy to use. There is a sample for PDFsharp 1.50 that shows an implementation of IFontResolver that can be used as a template if you want to do it without EZFontResolver.

这篇关于使用自定义字体在Azure上使用PDFsharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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