我目前遇到PdfSharp/MigraDoc和PDF查看器的问题。我已使用EZFontResolver made by Thomas能够生成具有自定义字体的pdf。不幸的是PDF查看器无法呈现字体,我不知道为什么。我在Thomas的博客上看到一个错误described by Travis,其中指出,如果EZFontResolver没有多个粗体/斜体符号识别(例如“fontname | b | b”),则PdfDocumentRenderer.RenderDocument()失败。问题是,当我尝试这样的事:在pdf查看器中不加载字体
Document document = DdlReader.DocumentFromString(ddl);
_renderer = new DocumentRenderer(document);
_renderer.PrepareDocument();
比EZFontResolver被要求与名称类似字体“CustomFont的| B | b”的时候我只用PdfDocument.Save(它不会发生(...))而不是“customfont”。
我的pdf查看器重写DocumentViewer并查看FixedDocument类实例。有趣的是,保存的pdf文件中包含所有字体,但预览无法做到这一点(这是我的大问题)。即使我用解析器返回正确的字体,所有这些都会发生。
编辑:
的DDL是它看起来像这样的字符串:
"\\document
[
Info
{
Title = \"My file\"
Subject = \"My pdf file\"
Author = \"mikes\"
}
]
{
\\styles
{
Heading1 : Normal
{
Font
{
Name = \"My custom font\"
Bold = true
}
ParagraphFormat
{
Alignment = Center
SpaceBefore = \"0.5cm\"
SpaceAfter = \"0.5cm\"
}
}
header : Normal
{
Font
{
Name = \"My custom font\"
Size = 6
}
ParagraphFormat
{
Alignment = Center
}
}
当我特拉维斯删除的bug修复,除了在_renderer.PrepareDocument被甩出()(修复之后,堆栈跟踪显示多个“| b”的源也不在那里)。
那么有可能以任何其他方式在MigraDoc文件中设置自定义字体?有了这个bug,我很难展示整个过程,但我会尽力的。 – mikes
MDDDL文件描述了一个文档,任何字体都可以在这里“使用”。创建PDF文件的渲染器支持EZFontResolver使用的接口,您可以使用它来添加自定义字体。 DocumentViewer使用的渲染器不支持EZFontResolver - 您可以将已安装的字体或XPrivateFontCollection用于GDI构建。随EZFontResolver提供的字体将嵌入到PDF文件中,并可供任何PDF查看器使用。 –