【问题标题】:Crystal Reports printing client side C#Crystal Reports 打印客户端 C#
【发布时间】:2014-09-28 05:35:13
【问题描述】:

我有一份报告,我想根据 GridView 中的按钮触发。这将生成一个标签并将其发送到连接的(本地)Zebra 打印机。当我在本地运行它时,它工作正常。打印机甚至不必是默认值。当我将文件复制到服务器并单击“打印”按钮时,没有任何反应。

        CrystalReportSource CrystalReportSource1 = new CrystalReportSource();
        CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();
        CrystalReportViewer1.HasPrintButton = true;
        // CrystalReportViewer1.PrintMode = "ActiveX";

        CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.EnableParameterPrompt = false;

        CrystalReportSource1.Report.FileName = "BinLocation2.rpt";
        TableLogOnInfo logOnInfo = new TableLogOnInfo();

        CrystalReportSource1.ReportDocument.SetParameterValue(0, Item);
        CrystalReportSource1.ReportDocument.SetParameterValue(1, binlocation);
        CrystalReportSource1.ReportDocument.SetParameterValue(2, Lot);
        CrystalReportSource1.ReportDocument.SetParameterValue(3, expiredate);
        CrystalReportSource1.ReportDocument.SetParameterValue(4, NDC);


        logOnInfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["SalesReportServerName"];
        logOnInfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["SalesReportDatabaseName"];
        logOnInfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["SalesReportUserID"];
        logOnInfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["SalesReportPassword"];

        TableLogOnInfos infos = new TableLogOnInfos();
        infos.Add(logOnInfo);
        CrystalReportViewer1.LogOnInfo = infos;

        try
        {

            CrystalReportSource1.ReportDocument.PrintToPrinter(1, false, 0, 0);
        }

我为 Visual Studio 安装了 redist 软件包。比较了 web.config 文件。打印机未安装在服务器上,但我希望在客户端完成此操作(没有提示打印)。有没有更好的方法来做到这一点?我错过了什么?

【问题讨论】:

    标签: c# asp.net printing crystal-reports


    【解决方案1】:

    首先,这就是我实现此功能的方式(后面会有解释):

    // get the user selected printer
    var printerName = Settings.Instance[profile].DirectPrinter;
    // enumerate the printers visible to the application
    var allPrinters = PrinterSettings.InstalledPrinters.OfType<string>().OrderBy(p => p).ToList();
    // Strip out PDF, XPS and any file based printers. These cause havoc on a server based print
    var acceptablePrinters = allPrinters.Except(allPrinters
                                                    .Where(s => Settings.Instance[profile].PrintersToIgnore
                                                            .Any(u => s.ToLower().Contains(u)))).ToList();
    if (acceptablePrinters.Contains(printerName))
    {
        report.PrintOptions.PrinterName = printerName;
        report.PrintToPrinter(copies, collate, 0, 0);
    }
    else
    {
       // Log the reason why the printer was rejected
       // Or you may choose to just print to default
    }
    

    解释

    PrintToPrinter 方法在服务器端运行,因此它只适用于服务器和 IIS 应用程序池标识可以“看到”的打印机。

    大多数 Zebra 打印机都将联网,因此可以使配置在整个网络中可见。但是,您需要允许在您的 asp.net 应用程序中进行配置以在运行时设置打印机名称(即使它始终相同),然后您可以调用 PrintToPrinter 将打印到网络打印机。

    在没有提示的情况下向客户打印实际上是不可能的,而且不建议这样做。为此,我允许用户选择打印到客户端,然后导出为 PDF,标准 PDF 打印对话框会提示用户进行打印机设置。添加此功能是为了允许打印到非网络打印机。

    【讨论】:

    • “大多数 Zebra 打印机都将联网” - 此处并非如此。打印机通过 USB 在本地连接。我正在测试应该允许我想要的第 3 方控件。
    • 啊,我明白了。您可以从 ASP.net 应用程序访问网络共享 USB 打印机,我有许多使用此选项的部署。我仍在寻找更强大的客户端打印选项,我愿意接受建议,那么这个第 3 方控件是什么?
    • 哇!这看起来很有希望,而且也不贵!尽管我仍然想为客户打印显示一个对话框,但有这个选项会很棒。谢谢。
    • 到目前为止,支持非常好,除了一些小问题之外,该软件运行良好。该软件基本上是一个 DLL,可在客户端 PC 上打开 Adob​​e,进行导出,然后自动打印 PDF。但是您可以通过代码获得一些灵活性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    相关资源
    最近更新 更多