public void PrintInvoice() { var printJob = new ClientPrintJob(); printJob.ClientPrinter= new DefaultPrinter(); printJob.PrinterCommands = Resources.PrinterText; printJob.SendToClient(System.Web.HttpContext.Current.Response); }
//sid: user session id who is requesting a ClientPrintJob public void PrintCommands(string sid) { if (WebClientPrint.ProcessPrintJob(System.Web.HttpContext.Current.Request)) { HttpApplicationStateBase app = HttpContext.Application; //Create a ClientPrintJob obj that will be processed at the client side by the WCPP ClientPrintJob cpj = new ClientPrintJob(); //get printer commands for this user id object printerCommands = app[sid + PRINTER_COMMANDS]; if (printerCommands != null) { cpj.PrinterCommands = printerCommands.ToString(); cpj.FormatHexValues = true; } //get printer settings for this user id int printerTypeId = (int)app[sid + PRINTER_ID]; if (printerTypeId == 0) //use default printer { cpj.ClientPrinter = new DefaultPrinter(); } else if (printerTypeId == 1) //show print dialog { cpj.ClientPrinter = new UserSelectedPrinter(); } else if (printerTypeId == 2) //use specified installed printer { cpj.ClientPrinter = new InstalledPrinter(app[sid + INSTALLED_PRINTER_NAME].ToString()); } else if (printerTypeId == 3) //use IP-Ethernet printer { cpj.ClientPrinter = new NetworkPrinter(app[sid + NET_PRINTER_HOST].ToString(), int.Parse(app[sid + NET_PRINTER_PORT].ToString())); } else if (printerTypeId == 4) //use Parallel Port printer { cpj.ClientPrinter = new ParallelPortPrinter(app[sid + PARALLEL_PORT].ToString()); } else if (printerTypeId == 5) //use Serial Port printer { cpj.ClientPrinter = new SerialPortPrinter(app[sid + SERIAL_PORT].ToString(), int.Parse(app[sid + SERIAL_PORT_BAUDS].ToString()), (System.IO.Ports.Parity)Enum.Parse(typeof(System.IO.Ports.Parity), app[sid + SERIAL_PORT_PARITY].ToString()), (System.IO.Ports.StopBits)Enum.Parse(typeof(System.IO.Ports.StopBits), app[sid + SERIAL_PORT_STOP_BITS].ToString()), int.Parse(app[sid + SERIAL_PORT_DATA_BITS].ToString()), (System.IO.Ports.Handshake)Enum.Parse(typeof(System.IO.Ports.Handshake), app[sid + SERIAL_PORT_FLOW_CONTROL].ToString())); } //Send ClientPrintJob back to the client cpj.SendToClient(System.Web.HttpContext.Current.Response); } }
protected void Page_Init(object sender, System.EventArgs e) { if (WebClientPrint.ProcessPrintJob(this.Request)) { ClientPrintJob cpj = new ClientPrintJob(); cpj.ClientPrinter = new UserSelectedPrinter(); cpj.PrinterCommands = (string)Application[this.Request.QueryString["sid"] + CommonConstants.PrintCommand]; cpj.SendToClient(Response); } Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time }
public void PrintFile(string useDefaultPrinter, string printerName, string fileType) { string fileName = Guid.NewGuid().ToString("N") + "." + fileType; string filePath = null; switch (fileType) { case "PDF": filePath = "~/files/LoremIpsum.pdf"; break; case "TXT": filePath = "~/files/LoremIpsum.txt"; break; case "DOC": filePath = "~/files/LoremIpsum.doc"; break; case "XLS": filePath = "~/files/SampleSheet.xls"; break; case "JPG": filePath = "~/files/penguins300dpi.jpg"; break; case "PNG": filePath = "~/files/SamplePngImage.png"; break; case "TIF": filePath = "~/files/patent2pages.tif"; break; } if (filePath != null) { PrintFile file = new PrintFile(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Web.HttpUtility.UrlDecode(printerName)); } cpj.SendToClient(System.Web.HttpContext.Current.Response); } }
public void PrintCommands(string sid) { if (WebClientPrint.ProcessPrintJob(System.Web.HttpContext.Current.Request)) { HttpApplicationStateBase app = HttpContext.Application; //Create a ClientPrintJob obj that will be processed at the client side by the WCPP ClientPrintJob cpj = new ClientPrintJob(); //get printer commands for this user id object printerCommands = app[sid + PRINTER_COMMANDS]; if (printerCommands != null) { cpj.PrinterCommands = printerCommands.ToString(); cpj.FormatHexValues = true; } cpj.ClientPrinter = new UserSelectedPrinter(); //Send ClientPrintJob back to the client cpj.SendToClient(System.Web.HttpContext.Current.Response); } }
public void ShelfStockPrint(string Shelfstockid, string pagecopies) { int id = Convert.ToInt32(Shelfstockid); string printerName = @"AThermalZebraNet"; // Set printer name or UNC eg; @"\\CMCNMPS2\RcvShelf" var actionPDF = new Rotativa.ActionAsPdf("PrintShelfStockLabel", new { id }) { PageMargins = new Margins(2, 2, 0, 2), PageWidth = 200, PageHeight = 75, CustomSwitches = "--disable-smart-shrinking --load-error-handling ignore --copies " + pagecopies + "" }; byte[] pdfContent = actionPDF.BuildPdf(ControllerContext); // PDF stream content string fileName = Shelfstockid + ".pdf"; // Set file and extension name PrintFile file = new PrintFile(pdfContent, fileName); // Build file ClientPrintJob cpj = new ClientPrintJob(); // Create a ClientPrintJob and send it back to the client! cpj.PrintFile = file; // Set file to print cpj.ClientPrinter = new InstalledPrinter(printerName); // Set client printer //cpj.ClientPrinter = new NetworkPrinter("192.168.0.60", 9100); // Set IP printer: ipaddress, port cpj.SendToClient(System.Web.HttpContext.Current.Response); // Send it }
public void LabelPrint() { int pagecopies = 1; string printerName = @"AThermalZebraNet"; // @"\\CMCNMPS2\RcvShelf"; var actionPDF = new Rotativa.ActionAsPdf("PrintLabel") { PageMargins = new Margins(2, 2, 0, 2), PageWidth = 200, PageHeight = 75, CustomSwitches = "--disable-smart-shrinking --load-error-handling ignore --copies " + pagecopies + "" }; byte[] pdfContent = actionPDF.BuildPdf(ControllerContext); string fileName = "thermallabel.pdf"; // Create a temp file name for our PDF report... PrintFile file = new PrintFile(pdfContent, fileName); // Create a PrintFile object with the pdf report ClientPrintJob cpj = new ClientPrintJob(); // Create a ClientPrintJob and send it back to the client! cpj.PrintFile = file; // Set file to print... cpj.ClientPrinter = new InstalledPrinter(printerName); // Set client printer...//cpj.ClientPrinter = new NetworkPrinter("10.0.0.8", 9100); cpj.SendToClient(System.Web.HttpContext.Current.Response); // Send it... }
//sid: user session id who is requesting a ClientPrintJob public void PrintCommands(string sid) { if (WebClientPrint.ProcessPrintJob(System.Web.HttpContext.Current.Request)) { HttpApplicationStateBase app = HttpContext.Application; //Create a ClientPrintJob obj that will be processed at the client side by the WCPP ClientPrintJob cpj = new ClientPrintJob(); //get printer commands for this user id object printerCommands = app[sid + PRINTER_COMMANDS]; if (printerCommands != null) { cpj.PrinterCommands = printerCommands.ToString(); cpj.FormatHexValues = true; } //get printer settings for this user id int printerTypeId = (int)app[sid + PRINTER_ID]; if (printerTypeId == 0) //use default printer { cpj.ClientPrinter = new DefaultPrinter(); } else if (printerTypeId == 1) //show print dialog { cpj.ClientPrinter = new UserSelectedPrinter(); } else if (printerTypeId == 2) //use specified installed printer { cpj.ClientPrinter = new InstalledPrinter(app[sid + INSTALLED_PRINTER_NAME].ToString()); } else if (printerTypeId == 3) //use IP-Ethernet printer { cpj.ClientPrinter = new NetworkPrinter(app[sid + NET_PRINTER_HOST].ToString(), int.Parse(app[sid + NET_PRINTER_PORT].ToString())); } else if (printerTypeId == 4) //use Parallel Port printer { cpj.ClientPrinter = new ParallelPortPrinter(app[sid + PARALLEL_PORT].ToString()); } else if (printerTypeId == 5) //use Serial Port printer { cpj.ClientPrinter = new SerialPortPrinter(app[sid + SERIAL_PORT].ToString(), int.Parse(app[sid + SERIAL_PORT_BAUDS].ToString()), (System.IO.Ports.Parity)Enum.Parse(typeof(System.IO.Ports.Parity), app[sid + SERIAL_PORT_PARITY].ToString()), (System.IO.Ports.StopBits)Enum.Parse(typeof(System.IO.Ports.StopBits), app[sid + SERIAL_PORT_STOP_BITS].ToString()), int.Parse(app[sid + SERIAL_PORT_DATA_BITS].ToString()), (System.IO.Ports.Handshake)Enum.Parse(typeof(System.IO.Ports.Handshake), app[sid + SERIAL_PORT_FLOW_CONTROL].ToString())); } //Send ClientPrintJob back to the client cpj.SendToClient(System.Web.HttpContext.Current.Response); } }
protected void Page_Load(object sender, EventArgs e) { Neodynamic.SDK.Web.WebClientPrint.CreateScript(); //Is a Print Request? if (WebClientPrint.ProcessPrintJob(Request)) { bool useDefaultPrinter = (Request["useDefaultPrinter"] == "checked"); string printerName = Server.UrlDecode(Request["printerName"]); /* * Response.Redirect("PrinterReciept.aspx?PolicyNr=" + model.MemeberNumber.ToString() + * "&DatePaid=" + model.PaymentDate.ToString("YYYY-MMM-dd") + * "&AmountPaid=" + model.Amount.ToString() + * "&LateAmountPaid=" + model.LatePaymentPenalty.ToString() + * "&PolicyHolder=" + model.FullNames + * "&ReceivedBy=" + model.ReceivedBy + * "&TimePrinted=" + DateTime.Now.ToString("YYYY-MMM-dd hh:mm") + * "&Method=" + model.MethodOfPayment + * "&Notes=" + model.Notes + * "&Plan=" + model.PlanName); * * * Dim zlabel As New Com.SharpZebra.Example.BorderedLabel(" Branch Name...... " & vbTab & vbTab & ConfigurationManager.AppSettings("branch"), _ * " Receipt Nr....... " & vbTab & vbTab & intReceipt, _ * " Policy Nr........ " & vbTab & vbTab & txtMemberNo.Text.ToUpper, _ * " Date Paid........ " & vbTab & vbTab & dtDatepaid.ToString("dd-MMM-yyyy"), _ * " Amount Paid...... " & vbTab & vbTab & FormatCurrency(txtAmount.Text, 2), _ * " Policy Holder.... " & vbTab & vbTab & BL.pFullNames & " " & BL.pSurname, _ * " Received By...... " & vbTab & vbTab & txtRecievedBy.Text, _ * " Time Printed..... " & vbTab & vbTab & DateTime.Now.ToString("dd-MMM-yyyy hh:mm"), _ * " Method........... " & vbTab & vbTab & strMethod, _ * notes, _ * " Underwriter...... " & vbTab & vbTab & BL.pAddress4, "123", strAppName, dtAdditionalAppSettings.Rows(0).Item("slogan")) * * */ //Create ESC/POS commands for sample receipt string ESC = "0x1B"; //ESC byte in hex notation string NewLine = "0x0A"; //LF byte in hex notation string cmds = ESC + "@"; //Initializes the printer (ESC @) cmds += ESC + "!" + "0x38"; //Emphasized + Double-height + Double-width mode selected (ESC ! (8 + 16 + 32)) 56 dec => 38 hex cmds += "UnpluggIT"; //text to print cmds += NewLine + NewLine; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += "Policy Nr........ "; cmds += NewLine; cmds += "Date Paid........ "; cmds += NewLine + NewLine; cmds += "Amount Paid...... "; cmds += NewLine; cmds += "Policy Holder.... "; cmds += NewLine; cmds += "Time Printed..... " + System.DateTime.Now.ToString("dd-MMM-yyyy"); cmds += NewLine; cmds += "Method........... "; cmds += NewLine; cmds += "Product Name..... "; cmds += NewLine; cmds += System.DateTime.Now.ToString("dd-MMM-yyyy"); cmds += "0x1D 0x56 <m>"; //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set ESC/POS commands to print... cpj.PrinterCommands = cmds; cpj.FormatHexValues = true; //set client printer... if (useDefaultPrinter || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } //send it... cpj.SendToClient(Response); } }
public void Print() { //Create a ClientPrintJob obj that will be processed at the client side by the WCPP ClientPrintJob cpj = new ClientPrintJob(); //use default printer on the client machine cpj.ClientPrinter = new DefaultPrinter(); //set the commands to send to the printer cpj.PrinterCommands = Resources.PrinterText; cpj.SendToClient(System.Web.HttpContext.Current.Response); }