我正在使用来自Windows服务的Amyuni pdf库,该服务作为LocalSystem帐户运行。以下是我用于打印的代码。
private void Initialize()
{
acPDFCreatorLib.Initialize();
acPDFCreatorLib.SetLicenseKey(licenseTo, activationCode);
}
......打印pdf
using (FileStream file1 = new FileStream(fileName, FileMode.Open, FileAccess.Read))
using (IacDocument doc1 = new IacDocument())
{
doc1.Open(file1, "");
doc1.AttributeByName("Title").Value = documentName;
doc1.SetAttributeForMultipleSelection("UnicodeFonts", true, false);
doc1.Copies = printEvent.Copies;
bool printed = doc1.Print(printerName, false);
PrintSystemJobInfo PrintSystemJobInfo = GetPrintJob(printerName, fileName);
if (printed)
{
Logger.Log(string.Format("[AMYUNI] PDF' {0} ' printed using printer {1}", documentName, printerName));
return true;
}
return false;
}
对于某些打印机' doc1.Print(printerName,false);'不工作,它没有返回结果。用于调用打印功能的线程永远不会返回。所以我们无法识别错误。
现在,我们计划的解决方案是为不同线程中的每台打印机初始化amyuni库实例。有了这个,我们将能够使我们的解决方案适用于其他打印机,即使它被一台打印机阻止(amyuni库冻结不响应)。
对于我们如何初始化多个库实例?
答案 0 :(得分:3)
此调用保持原样,但仅在主线程中:
private void Initialize()
{
acPDFCreatorLib.Initialize();
acPDFCreatorLib.SetLicenseKey(licenseTo, activationCode);
}
,剩下的部分分别是:
using (FileStream file1 = new FileStream(fileName, FileMode.Open, FileAccess.Read))
using (IacDocument doc1 = new IacDocument())
{
doc1.Open(file1, "");
doc1.AttributeByName("Title").Value = documentName;
doc1.SetAttributeForMultipleSelection("UnicodeFonts", true, false);
doc1.Copies = printEvent.Copies;
bool printed = doc1.Print(printerName, false);
PrintSystemJobInfo PrintSystemJobInfo = GetPrintJob(printerName, fileName);
if (printed)
{
Logger.Log(string.Format("[AMYUNI] PDF' {0} ' printed using printer {1}", documentName, printerName));
return true;
}
return false;
}
根据您的工作流程,您可能需要确保在该实例的打印完成之前未处理PDF Creator IacDocument实例。
免责声明:此答案由Amyuni Technologies的员工提供。