【发布时间】:2023-03-08 05:59:01
【问题描述】:
我有一个 Windows 服务,它会在收到请求后打印 pdf 文件。它使用 PrintDocument,但对于某些打印机,它似乎忽略了我在代码中提供的打印机和托盘设置。
目前每台打印机都有几个托盘,这些托盘都作为单独的队列安装。对于某些打印机,我可以将(PrintDocument 的)PrinterName 属性设置为队列的名称,它工作正常。然而,一些打印机似乎忽略了这一点。我也尝试设置纸张来源,但这似乎总是被忽略。
这是用于打印的代码:
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = printer; //printer is send to the service along with the request
pd.Print();
再次重申:这适用于某些打印机,但并非适用于所有打印机。
我也尝试过这样使用 Papersource:
pd.PrinterSettings.DefaultPageSettings.PaperSource.SourceName =
pd.PrinterSettings.PaperSources[tray - 1].SourceName; //Tray is also send with the request
像这样:
pd.PrinterSettings.DefaultPageSettings.PaperSource =
pd.PrinterSettings.PaperSources[tray - 1];
我在这里做错了什么?
编辑:pdf文件中总是有内容,所以不能为空。
【问题讨论】:
-
你试过打印非空页吗?
-
我正在打印不能为空的 pdf 文件(如果是,它们永远不会到达服务中心)。所以文件中总是有内容。我应该在问题中说明这一点,抱歉。
标签: c# printdocument