ABCPDF 字体打印布局 - 取决于机器
我正在使用 ABCPDF 通过 EMF 文件将 PDF 文件打印到本地打印机。我非常密切地基于 ABC PDF 的示例“ABCPDFView”项目。我的应用程序在我的 Windows 7 和 Windows XP 开发盒上运行良好,但是当我转移到 Windows 2003 测试盒时,简单的嵌入字体(如 Times New Roman 12)呈现完全错误(位置错误,而且又短又矮,几乎就像DPI 的错误非常严重)。
请注意,我已将 DPI 硬编码为 240,因为我使用的是强制 240x240 的奇怪大型机打印驱动程序。我可以将该驱动程序视为罪魁祸首,因为如果我在打印过程中在本地保存 EMF 文件,它会显示相同的布局问题。如果我渲染为 PNG 或 TIFF 文件,这在使用相同代码的所有服务器上看起来都很好(用 .png 代替 .emf)。最后,如果我使用 ABCPDFView 项目手动将随机文本框添加到我的 PDF 中,该文本在 EMF 文件中也会呈现错误。 (旁注,如果我使用 Acrobat 打印 PDF,文本呈现得很好)
更新:我为其他遇到此问题的人留下了一个有用的观点。我可以通过将 RenderTextAsText 设置为“0”来解决该问题(请参阅下面的代码)。这会强制 ABCPDF 将文本渲染为多边形,从而使问题消失。但这不是一个很好的解决方案,因为它大大增加了我的 EMF 文件的大小,并且这些多边形在我的最终打印文档中渲染得不太干净。
有人对这个奇怪的字体问题的原因有什么想法吗?
private void DoPrintPage(object sender, PrintPageEventArgs e)
{
using (Graphics g = e.Graphics)
{
//... omitted code to determine the rect, used straight from ABC PDF sample
mDoc.Rendering.DotsPerInch = 240 ;
mDoc.Rendering.ColorSpace = "RGB";
mDoc.Rendering.BitsPerChannel = 8;
mDoc.SetInfo(0, "RenderTextAsText", "0");//the magic is right here
byte[] theData = mDoc.Rendering.GetData(".emf");
using (MemoryStream theStream = new MemoryStream(theData))
{
using (Metafile theEMF = new Metafile(theStream))
{
g.DrawImage(theEMF, theRect);
}
}
//... omitted code to move to the next page
}
I am using ABCPDF to print a PDF file to a local printer via EMF file. I've based this very closely on ABC PDF's sample "ABCPDFView" project. My application worked fine on my Windows 7 and Windows XP dev boxes, but when I moved to a Windows 2003 test box, simple embedded fonts (like Times New Roman 12) rendered completely wrong (wrong spot, and short and squat, almost like the DPI's were crazily wrong).
Note that I've hardcoded the DPI to 240 here b/c I'm using a weird mainframe print driver that forces 240x240. I can discount that driver as the culprit as, if I save the EMF file locally during print, it shows the same layout problems. If I render to PNG or TIFF files, this looks just fine on all my servers using this same code (put .png in place of .emf). Finally, if I use the ABCPDFView project to manually add in a random text box to my PDF, that text also renders wrong in the EMF file. (Side note, if I print the PDF using Acrobat, the text renders just fine)
Update: I left out a useful point for anyone else having this problem. I can work around the problem by setting RenderTextAsText to "0" (see code below). This forces ABCPDF to render the text as polygons and makes the problem go away. This isn't a great solution though, as it greatly increases the size of my EMF files, and those polygons don't render nearly as cleanly in my final print document.
Anyone have any thoughts on the causes of this weird font problem?
private void DoPrintPage(object sender, PrintPageEventArgs e)
{
using (Graphics g = e.Graphics)
{
//... omitted code to determine the rect, used straight from ABC PDF sample
mDoc.Rendering.DotsPerInch = 240 ;
mDoc.Rendering.ColorSpace = "RGB";
mDoc.Rendering.BitsPerChannel = 8;
mDoc.SetInfo(0, "RenderTextAsText", "0");//the magic is right here
byte[] theData = mDoc.Rendering.GetData(".emf");
using (MemoryStream theStream = new MemoryStream(theData))
{
using (Metafile theEMF = new Metafile(theStream))
{
g.DrawImage(theEMF, theRect);
}
}
//... omitted code to move to the next page
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试升级到新版本的 abcpdf 8,它有自己的基于 Gecko 的渲染引擎,因此当 abcpdf 使用内置服务器版本的 IE 进行渲染时,您可以绕过此类问题。
Try upgrading to the new version of abcpdf 8, it has its own rendering engine based on Gecko and so you can bypass issues like this when abcpdf is using the inbuilt server version of IE for rendering.
我最初使用 1920x1080 分辨率进行 RDPing,通过将 RDP 切换到 1024x768 分辨率,问题就消失了。我的主程序作为服务运行,并从带有 1024x768 的 RDP 会话启动该服务修复了该问题。
我有一封带有 ABC PDF 的电子邮件,看看他们是否可以解释这一点并提供更优雅的解决方案,但目前这是可行的。
请注意,这是 ABC PDF 7,我不知道这个问题是否也适用于其他版本。
更新:ABC PDF 支持确认该服务可能正在缓存启动该过程的人员的显示分辨率。他们确认他们发现了远程桌面的一些其他奇怪问题,并鼓励我使用这个 1024x768 解决方法和/或远程启动该服务。
I was originally RDPing in with 1920x1080 resolution, by switching to 1024x768 res for RDP, the problem went away. My main program runs as a service, and starting this service from an RDP session w/ 1024x768 fixes it.
I have an email out w/ ABC PDF to see if they can explain this and offer a more elegant solution, but for now this works.
Please note that this is ABC PDF 7, I have no idea if this issue applies to other versions.
Update: ABC PDF support confirmed that its possible the service is caching the display resolution from the person that started the process. They confirmed that they've seen some other weird issues with Remote Desktop and encouraged me to use this 1024x768 workaround and/or start the service remotely.