我已經在 Windows 10 上設置了我的 iis 服務器,并且我已經在其上部署了一個 mvc-5 網絡應用程序,除了 Crystal Reports PrintToPrinter 之外,一切都運行良好,當我嘗試調用此方法時,沒有任何打印,網絡應用程序什么也不做,只是掛起那里。但是當我在同一臺機器上用 vs17 開發這個應用程序時,printToPrinter 方法工作正常。它只會在 iis 上發布后卡住。我努力了popt.PrinterName = printerSettings.PrinterName; rd.ReportClientDocument.PrintOutputController.PrintReport(popt);這個方法也是。這是我的實際代碼: DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(sqlQuery)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; sda.Fill(dt); } } } ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Reporting/Crystals/rptKitchenCopy.rpt"))); rd.SetDataSource(dt); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); PrinterSettings settings = new PrinterSettings(); System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument(); CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings(); System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings(); var dpn = settings.PrinterName; printerSettings.PrinterName = dpn; System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);我希望它也可以使用我在同一臺機器上托管的默認打印機在 iis 服務器中打印。C#asp.net-mvciis印刷水晶報表
1 回答

婷婷同學_
TA貢獻1844條經驗 獲得超8個贊
我找到了導致此問題的原因,因為我在 Windows 10 上托管和開發了我的 Web 應用程序(都在同一臺機器上),問題背后的原因是默認情況下我的 Windows 10 iis 正在檢測“microsoft print to pdf”作為默認值打印機,所以我已經從 Windows 功能中關閉了它并添加了
PrinterSettings 設置 = new PrinterSettings(); rd.PrintOptions.PrinterName = settings.PrinterName;
在我的代碼中。希望有人有同樣的問題。謝謝
- 1 回答
- 0 關注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消