我有通过托管在IIS中的应用程序将pdf(从流生成)传输到网络打印机的场景。我尝试过使用PrintDocument.Print(),我遇到的问题是:1.文档正在排队等待大小为0字节的打印作业队列。 2.文档正在以拥有者名称作为machine_name排队到打印作业队列。 这里是我尝试使用PdfiumViewer(以从字节组的PrintDocument)和System.Drawing.Printing.PrintDocument的代码:如何通过托管在IIS中的应用程序打印到网络打印机
public void SendPdfToPrinter(byte[] byteArray, string fileName, string printerNetworkPath)
{
using (Stream fileStream = new MemoryStream(byteArray)) //byte array for the file content
{
var printerSettings = new System.Drawing.Printing.PrinterSettings
{
PrinterName = printerNetworkPath, //this is the printer full name. i.e. \\10.10.0.12\ABC-XEROX-01
PrintFileName = fileName, //file name. i.e. abc.pdf
PrintRange = System.Drawing.Printing.PrintRange.AllPages,
};
printerSettings.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
// Now print the PDF document
using (PdfiumViewer.PdfDocument document = PdfiumViewer.PdfDocument.Load(fileStream))
{
using (System.Drawing.Printing.PrintDocument printDocument = document.CreatePrintDocument())
{
printDocument.DocumentName = fileName;
printDocument.PrinterSettings = printerSettings;
printDocument.PrintController = new System.Drawing.Printing.StandardPrintController();
printDocument.Print();
}
}
它被测试,所以你可以依靠这个。谢谢 –