我正在使用 Amyuni PDF Creator .Net 使用 Windows 服务打印 PDF。
Windows 服务在本地系统用户帐户下运行。当我尝试使用上述库进行打印时,它以错误的字体打印 PDF。见附件(Wrong font in PDF printing)。
只有部分打印机存在此问题,例如 Brother MFC-8890DW 打印机。
但对于具有上述 windows 服务的同一台打印机,当取消选中上述打印机属性中的启用高级打印功能设置时,它可以正确打印 PDF。见附件(Disable Advanced printing features)。
using (FileStream file1 = new FileStream(pdfFile, FileMode.Open, FileAccess.Read))
{
using (IacDocument doc1 = new IacDocument())
{
doc1.Open(file1, string.Empty);
doc1.Copies = 1;
bool printed = doc1.Print(printer, false);
}
}
但相同的 Windows 服务可以为某些其他打印机(例如 HP LaserJet P1005)正确打印 PDF,启用高级打印功能已选中或未选中。
最佳答案
如果无法访问您正在使用的同一台打印机,则很难确切知道发生了什么。我最好的猜测是,当检查“启用高级打印功能”时,该打印机的驱动器遇到了处理流程级字体(使用GDI函数AddFontResourceEx)的问题。这就是 Amyuni PDF Creator 使用 PDF 文件中嵌入的字体的方式,您提供的文件就是这种情况。 一个可能的解决方法是使用 attribute "PrintAsImage" of the Document class 。
代码看起来像这样:
//set license key This is needed only with licensed version
acPDFCreatorLib.SetLicenseKey("your company", "your activation code");
//Create a new document instance
Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument(null);
doc.AttributeByName("PrintAsImage").Value =1;
//Open the file here (...)
//Print to default printer
pdfCreator1.Document.Print("", false);
另一种方法是使用 Amyuni PDF Creator 将文件保存为 xps,然后将 xps 文件发送到打印机:
// Create print server and print queue.
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
defaultPrintQueue.AddJob("my document", "c:\\temp\\mytempfile.xps", true);
免责声明:我为 Amyuni Technologies 工作。
关于c# - AmyuniPDF 以错误的字体(特殊字符)打印 PDF 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35035708/