[英]Crystal Reports printing client side C#
我有一個要基於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文件。 打印機未安裝在服務器上,但我希望在客戶端完成此操作(不提示打印)。 有沒有更好的方法可以做到這一點? 我想念什么?
首先,這就是我實現此功能的方式(將在后面進行說明):
// 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打印對話框提示用戶輸入打印機設置。 添加它是為了允許打印到非網絡打印機。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.