我如何解决 CrystalReport PrintToPrinter 方法的问题

How can i fix the issue with CrystalReport PrintToPrinter method

我已经在 windows 10 上设置了我的 iis 服务器,并且我已经在其上部署了一个 mvc-5 web 应用程序,除了 Crystal Reports PrintToPrinter 之外,一切正常,当我尝试调用这个方法什么都不打印,网络应用程序什么也不做,只是挂在那里。但是当我在同一台机器上用 vs17 开发这个应用程序时,printToPrinter 方法工作正常。它只会在 iis 上发布后卡住。

我试过了

popt.PrinterName = printerSettings.PrinterName; rd.ReportClientDocument.PrintOutputController.PrintReport(弹出);

这个方法也是。 这是我的实际代码:

        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);

        CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions popt = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
        popt.PrinterName = printerSettings.PrinterName;
        rd.ReportClientDocument.PrintOutputController.PrintReport(popt);



        // rd.PrintOptions.PrinterName = "\ ";
       // rd.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
       // rd.PrintToPrinter(1, true, 1, 1);

        return File(stream, "application/pdf", "KitchenCopy.pdf");

我希望它也能使用我在同一台机器上托管的默认打印机在 iis 服务器中打印。

我找到了导致这个问题的原因,因为我在 windows 10 上托管和开发了我的网络应用程序(都在同一台机器上),问题背后的原因默认是我的 windows 10 iis 正在检测 'microsoft print to pdf' 作为默认打印机,因此我已从 windows 功能中关闭此功能并添加

PrinterSettings 设置 = new PrinterSettings(); rd.PrintOptions.PrinterName = settings.PrinterName;

在我的代码中。希望有人遇到同样的问题。谢谢