我有通過託管在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();
}
}
它被測試,所以你可以依靠這個。謝謝 –