我希望在没有打印对话框的客户端打印收据,我使用mvc这是我解决方案来实现我的问题。 EPSON打印机安装在我的系统中。这个解决方案在我本地iis的主机上工作,但是当主机在服务器中并且从本地系统访问时出现“处理请求时出错”错误。在服务器中没有安装打印机。
$.ajax({
type: "POST",
url: '../Service/print',
cache: false,
data: { iprintData: printData, iprinterName: sPrinterName },
success: function (data) {
// alert('print Send Successfully');
},
error: function (ex) {
alert(ex.responseText);
// alert('error while Seding print');
}
});
这是我在控制器中的代码
public JsonResult print(string iprintData, string iprinterName) { Boolean bflag = false; System.Web.HttpContext.Current.Session["_printData"] = iprintData; PrintDocument printDocument = new PrintDocument(); printDocument.PrintController = new StandardPrintController(); printDocument.PrintPage += PrintDocumentOnPrintPage; printDocument.PrinterSettings.PrinterName = iprinterName; //printFont = new System.Drawing.Font("Arial", 10); printDocument.Print(); bflag = true; return Json(bflag, JsonRequestBehavior.AllowGet); } public static Image resizeImage(Image image, int new_height, int new_width) { Bitmap new_image = new Bitmap(new_height, new_width); Graphics g = Graphics.FromImage((Image)new_image); g.InterpolationMode = InterpolationMode.High; g.DrawImage(image, 0, 0, new_width, new_height); return new_image; } private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e) { string printstring = System.Web.HttpContext.Current.Session["_printData"].ToString(); string path = HttpContext.Server.MapPath("~/content/Images/logo.png"); System.Drawing.Image img = Image.FromFile(path); //img = resizeImage(img, 80, 60); e.Graphics.DrawImage(img, 6, 100); e.Graphics.DrawString(printstring, new System.Drawing.Font("ronnia", 9), Brushes.Black, 10, 150); }
任何人都可以帮助我吗?
答案 0 :(得分:0)
设置System.Drawing.dll属性
sizeof()
答案 1 :(得分:0)
function PrintReceipt() {
var PrintData = JSON.parse($("#receiptData").html())
if (PrintData.length > 0) {
$.ajax({
type: "POST",
url: "http://localhost:41963/printOrder",
data: JSON.stringify({ "PrintData": PrintData }), //reciept data
crossDomain: true,
success: function (response) {
},
error: function () {
}
});
}
}