public void PrintFile(string printerName, string pagesFrom, string pagesTo) { string fileName = Guid.NewGuid().ToString("N"); string filePath = "~/files/Project-Scheduling-Monitoring-Tool.xls"; PrintFileXLS file = new PrintFileXLS(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); if (string.IsNullOrEmpty(pagesFrom) == false) { file.PagesFrom = int.Parse(pagesFrom); } if (string.IsNullOrEmpty(pagesTo) == false) { file.PagesTo = int.Parse(pagesTo); } ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
public void PrintFile(string printerName, string pagesRange, string printInReverseOrder, string duplexPrinting) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "~/files/Sample-Employee-Handbook.doc"; PrintFileDOC file = new PrintFileDOC(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); file.PagesRange = pagesRange; file.PrintInReverseOrder = (printInReverseOrder == "true"); file.DuplexPrinting = (duplexPrinting == "true"); //file.DuplexPrintingDialogMessage = "Your custom dialog message for duplex printing"; ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
public IActionResult PrintFile(string printerName, string pagesRange, string printInReverseOrder, string manualDuplexPrinting) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "/files/Sample-Employee-Handbook.doc"; PrintFileDOC file = new PrintFileDOC(_hostEnvironment.ContentRootPath + filePath, fileName); file.PagesRange = pagesRange; file.PrintInReverseOrder = (printInReverseOrder == "true"); file.DuplexPrinting = (manualDuplexPrinting == "true"); //file.DuplexPrintingDialogMessage = "Your custom dialog message for duplex printing"; ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName)); } return(File(cpj.GetContent(), "application/octet-stream")); }
public void PrintImage(string useDefaultPrinter, string printerName, string imageFileName) { //create a temp file name for our image file... //Because we know the Card size is 3.125in x 4.17in, we can specify //it through a special format in the file name (see http://goo.gl/Owzr9o) so the //printing output size is honored; otherwise the output will be sized to Page Width & Height //specified by the printer driver default setting string fileName = imageFileName + "-PW=3.125-PH=4.17" + ".png"; //Create a PrintFile object with the image file PrintFile file = new PrintFile(Convert.FromBase64String((string)HttpContext.Application[imageFileName]), fileName); //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set file to print... cpj.PrintFile = file; //set client printer... if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } //send it... HttpContext.Response.ContentType = "application/octet-stream"; HttpContext.Response.BinaryWrite(cpj.GetContent()); HttpContext.Response.End(); }
public IActionResult PrintFile(string printerName, string pagesFrom, string pagesTo) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "/files/Project-Scheduling-Monitoring-Tool.xls"; PrintFileXLS file = new PrintFileXLS(_hostEnvironment.ContentRootPath + filePath, fileName); if (string.IsNullOrEmpty(pagesFrom) == false) { file.PagesFrom = int.Parse(pagesFrom); } if (string.IsNullOrEmpty(pagesTo) == false) { file.PagesTo = int.Parse(pagesTo); } ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName)); } return(File(cpj.GetContent(), "application/octet-stream")); }
public IActionResult PrintFile(string useDefaultPrinter, string printerName) { try { //full path of the PDF file to be printed string pdfFilePath = @"C:\Users\chanh\Downloads\Quote-13 (3).pdf"; //create a temp file name for our PDF file... string fileName = "MyFile-" + Guid.NewGuid().ToString("N"); //Create a PrintFilePDF object with the PDF file PrintFilePDF file = new PrintFilePDF(pdfFilePath, fileName); //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set file to print... cpj.PrintFile = file; //set client printer... //if (useDefaultPrinter == "checked" || printerName == "null") // cpj.ClientPrinter = new DefaultPrinter(); //else cpj.ClientPrinter = new InstalledPrinter("HP LaserJet Professional M1212nf MFP"); return(File(cpj.GetContent(), "application/octet-stream")); } catch (Exception ex) { return(Ok()); } }
public void PrintFile(string printerName, string trayName, string paperName, string printRotation, string pagesRange, string printAnnotations, string printAsGrayscale, string printInReverseOrder, string manualDuplexPrinting, string driverDuplexPrinting, string pageSizing, bool autoRotate, bool autoCenter) { if (manualDuplexPrinting == "true" && driverDuplexPrinting == "true") { manualDuplexPrinting = "false"; } string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "~/files/mixed-page-orientation.pdf"; PrintFilePDF file = new PrintFilePDF(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); file.PrintRotation = (PrintRotation)Enum.Parse(typeof(PrintRotation), printRotation);; file.PagesRange = pagesRange; file.PrintAnnotations = (printAnnotations == "true"); file.PrintAsGrayscale = (printAsGrayscale == "true"); file.PrintInReverseOrder = (printInReverseOrder == "true"); if (manualDuplexPrinting == "true") { file.DuplexPrinting = true; //file.DuplexPrintingDialogMessage = "Your custom dialog message for duplex printing"; } file.Sizing = (Sizing)Enum.Parse(typeof(Sizing), pageSizing); file.AutoCenter = autoCenter; file.AutoRotate = autoRotate; ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { if (trayName == "null") { trayName = ""; } if (paperName == "null") { paperName = ""; } cpj.ClientPrinter = new InstalledPrinter(printerName, true, trayName, paperName); if (driverDuplexPrinting == "true") { ((InstalledPrinter)cpj.ClientPrinter).Duplex = Duplex.Vertical; } } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
public IActionResult 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(_hostEnvironment.ContentRootPath + filePath, fileName); ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName)); } return(File(cpj.GetContent(), "application/octet-stream")); } else { return(BadRequest("File not found!")); } }
public void PrintCommands(string sid) { if (WebClientPrint.ProcessPrintJob(System.Web.HttpContext.Current.Request.Url.Query)) { 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()), (SerialPortParity)Enum.Parse(typeof(SerialPortParity), app[sid + SERIAL_PORT_PARITY].ToString()), (SerialPortStopBits)Enum.Parse(typeof(SerialPortStopBits), app[sid + SERIAL_PORT_STOP_BITS].ToString()), int.Parse(app[sid + SERIAL_PORT_DATA_BITS].ToString()), (SerialPortHandshake)Enum.Parse(typeof(SerialPortHandshake), app[sid + SERIAL_PORT_FLOW_CONTROL].ToString())); } //Send ClientPrintJob back to the client System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); } }
//sid: user session id who is requesting a ClientPrintJob public IActionResult PrintCommands(string sid) { try { //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 = _MemoryCache.Get <string>(sid + PRINTER_COMMANDS); if (printerCommands != null) { cpj.PrinterCommands = printerCommands.ToString(); cpj.FormatHexValues = true; } //get printer settings for this user id int printerTypeId = int.Parse(_MemoryCache.Get <string>(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(_MemoryCache.Get <string>(sid + INSTALLED_PRINTER_NAME)); } else if (printerTypeId == 3) //use IP-Ethernet printer { cpj.ClientPrinter = new NetworkPrinter(_MemoryCache.Get <string>(sid + NET_PRINTER_HOST), int.Parse(_MemoryCache.Get <string>(sid + NET_PRINTER_PORT))); } else if (printerTypeId == 4) //use Parallel Port printer { cpj.ClientPrinter = new ParallelPortPrinter(_MemoryCache.Get <string>(sid + PARALLEL_PORT)); } else if (printerTypeId == 5) //use Serial Port printer { cpj.ClientPrinter = new SerialPortPrinter(_MemoryCache.Get <string>(sid + SERIAL_PORT), int.Parse(_MemoryCache.Get <string>(sid + SERIAL_PORT_BAUDS)), (SerialPortParity)Enum.Parse(typeof(SerialPortParity), _MemoryCache.Get <string>(sid + SERIAL_PORT_PARITY)), (SerialPortStopBits)Enum.Parse(typeof(SerialPortStopBits), _MemoryCache.Get <string>(sid + SERIAL_PORT_STOP_BITS)), int.Parse(_MemoryCache.Get <string>(sid + SERIAL_PORT_DATA_BITS)), (SerialPortHandshake)Enum.Parse(typeof(SerialPortHandshake), _MemoryCache.Get <string>(sid + SERIAL_PORT_FLOW_CONTROL))); } //Send ClientPrintJob back to the client return(File(cpj.GetContent(), "application/octet-stream")); } catch (Exception ex) { return(BadRequest(ex)); } }
public void PrintCommands(string useDefaultPrinter, string printerName, int orderId) { var listOfItems = _invoiceDataManager.GetInvoiceByOrderId(orderId); //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 += "BEST DEAL STORES"; //text to print cmds += NewLine + NewLine; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += "COOKIES 5.00"; cmds += NewLine; cmds += "MILK 65 Fl oz 3.78"; cmds += NewLine + NewLine; cmds += "SUBTOTAL 8.78"; cmds += NewLine; cmds += "TAX 5% 0.44"; cmds += NewLine; cmds += "TOTAL 9.22"; cmds += NewLine; cmds += "CASH TEND 10.00"; cmds += NewLine; cmds += "CASH DUE 0.78"; cmds += NewLine + NewLine; cmds += ESC + "!" + "0x18"; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex cmds += "# ITEMS SOLD 2"; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += NewLine + NewLine; cmds += "11/03/13 19:53:17"; //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set ESCPOS commands to print... cpj.PrinterCommands = cmds; cpj.FormatHexValues = true; //set client printer... if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } //send it... System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
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)); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); } }
public IActionResult PrintCommands(string useDefaultPrinter, string printerName) { //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 += "BEST DEAL STORES"; //text to print cmds += NewLine + NewLine; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += "COOKIES 5.00"; cmds += NewLine; cmds += "MILK 65 Fl oz 3.78"; cmds += NewLine + NewLine; cmds += "SUBTOTAL 8.78"; cmds += NewLine; cmds += "TAX 5% 0.44"; cmds += NewLine; cmds += "TOTAL 9.22"; cmds += NewLine; cmds += "CASH TEND 10.00"; cmds += NewLine; cmds += "CASH DUE 0.78"; cmds += NewLine + NewLine; cmds += ESC + "!" + "0x18"; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex cmds += "# ITEMS SOLD 2"; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += NewLine + NewLine; cmds += "11/03/13 19:53:17"; //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set ESCPOS commands to print... cpj.PrinterCommands = cmds; cpj.FormatHexValues = true; //set client printer... if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } return(File(cpj.GetContent(), "application/octet-stream")); }
public void PrintFile(string printerName, string trayName, string paperName, string printRotation, string pagesRange, string printAnnotations, string printAsGrayscale, string printInReverseOrder) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "~/files/GuidingPrinciplesBusinessHR_EN.pdf"; PrintFilePDF file = new PrintFilePDF(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); file.PrintRotation = (PrintRotation)Enum.Parse(typeof(PrintRotation), printRotation);; file.PagesRange = pagesRange; file.PrintAnnotations = (printAnnotations == "true"); file.PrintAsGrayscale = (printAsGrayscale == "true"); file.PrintInReverseOrder = (printInReverseOrder == "true"); ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { if (trayName == "null") { trayName = ""; } if (paperName == "null") { paperName = ""; } cpj.ClientPrinter = new InstalledPrinter(printerName, true, trayName, paperName); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
public IActionResult PrintFile(string printerName, string trayName, string paperName, string printRotation, string pagesRange, string printAnnotations, string printAsGrayscale, string printInReverseOrder) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "/files/GuidingPrinciplesBusinessHR_EN.pdf"; PrintFilePDF file = new PrintFilePDF(_hostEnvironment.ContentRootPath + filePath, fileName); file.PrintRotation = (PrintRotation)Enum.Parse(typeof(PrintRotation), printRotation);; file.PagesRange = pagesRange; file.PrintAnnotations = (printAnnotations == "true"); file.PrintAsGrayscale = (printAsGrayscale == "true"); file.PrintInReverseOrder = (printInReverseOrder == "true"); ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { if (trayName == "null") { trayName = ""; } if (paperName == "null") { paperName = ""; } cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName), true, System.Net.WebUtility.UrlDecode(trayName), System.Net.WebUtility.UrlDecode(paperName)); } return(File(cpj.GetContent(), "application/octet-stream")); }
public void PrintCommands(string useDefaultPrinter, string printerName) { var array = printerName.Split('%'); printerName = null; printerName = "BIXOLON SRP-270"; for (int i = 0; i < array.Count(); i++) { if (i == 0) { printerName = printerName + array[i]; } else { printerName = printerName + " " + array[i]; } } printerName = "BIXOLON SRP-270"; //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 += "CHEMALONSO"; //text to print cmds += NewLine + NewLine; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += "COOKIES 5.00"; cmds += NewLine; cmds += "MILK 65 Fl oz 3.78"; cmds += NewLine + NewLine; cmds += "SUBTOTAL 8.78"; cmds += NewLine; cmds += "TAX 5% 0.44"; cmds += NewLine; cmds += "TOTAL 9.22"; cmds += NewLine; cmds += "CASH TEND 10.00"; cmds += NewLine; cmds += "CASH DUE 0.78"; cmds += NewLine + NewLine; cmds += ESC + "!" + "0x18"; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex cmds += "# ITEMS SOLD 2"; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += NewLine + NewLine; cmds += "11/03/13 19:53:17"; //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set ESCPOS commands to print... cpj.PrinterCommands = cmds; cpj.FormatHexValues = true; //set client printer... if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } //send it... System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }
public IActionResult 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 = null; if (fileType == "PDF") { file = new PrintFilePDF(_hostEnvironment.ContentRootPath + filePath, fileName); ((PrintFilePDF)file).PrintRotation = PrintRotation.None; //((PrintFilePDF)file).PagesRange = "1,2,3,10-15"; //((PrintFilePDF)file).PrintAnnotations = true; //((PrintFilePDF)file).PrintAsGrayscale = true; //((PrintFilePDF)file).PrintInReverseOrder = true; } else if (fileType == "TXT") { file = new PrintFileTXT(_hostEnvironment.ContentRootPath + filePath, fileName); ((PrintFileTXT)file).PrintOrientation = PrintOrientation.Portrait; ((PrintFileTXT)file).FontName = "Arial"; ((PrintFileTXT)file).FontSizeInPoints = 12; // Point Unit!!! //((PrintFileTXT)file).TextColor = "#ff00ff"; //((PrintFileTXT)file).TextAlignment = TextAlignment.Center; //((PrintFileTXT)file).FontBold = true; //((PrintFileTXT)file).FontItalic = true; //((PrintFileTXT)file).FontUnderline = true; //((PrintFileTXT)file).FontStrikeThrough = true; //((PrintFileTXT)file).MarginLeft = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginTop = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginRight = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginBottom = 1; // INCH Unit!!! } else { file = new PrintFile(_hostEnvironment.ContentRootPath + filePath, fileName); } ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName)); } return(File(cpj.GetContent(), "application/octet-stream")); } else { return(BadRequest("File not found!")); } }
public IActionResult PrintFile(string useDefaultPrinter, string printerName, string fileType, string wcp_pub_key_base64, string wcp_pub_key_signature_base64) { 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 "JPG": filePath = "/files/penguins300dpi.jpg"; break; case "PNG": filePath = "/files/SamplePngImage.png"; break; } if (filePath != null && string.IsNullOrEmpty(wcp_pub_key_base64) == false) { PrintFile file = null; if (fileType == "PDF") { file = new PrintFilePDF(_hostEnvironment.ContentRootPath + filePath, fileName); ((PrintFilePDF)file).PrintRotation = PrintRotation.None; //((PrintFilePDF)file).PagesRange = "1,2,3,10-15"; //((PrintFilePDF)file).PrintAnnotations = true; //((PrintFilePDF)file).PrintAsGrayscale = true; //((PrintFilePDF)file).PrintInReverseOrder = true; } else if (fileType == "TXT") { file = new PrintFileTXT(_hostEnvironment.ContentRootPath + filePath, fileName); ((PrintFileTXT)file).PrintOrientation = PrintOrientation.Portrait; ((PrintFileTXT)file).FontName = "Arial"; ((PrintFileTXT)file).FontSizeInPoints = 12; // Point Unit!!! //((PrintFileTXT)file).TextColor = "#ff00ff"; //((PrintFileTXT)file).TextAlignment = TextAlignment.Center; //((PrintFileTXT)file).FontBold = true; //((PrintFileTXT)file).FontItalic = true; //((PrintFileTXT)file).FontUnderline = true; //((PrintFileTXT)file).FontStrikeThrough = true; //((PrintFileTXT)file).MarginLeft = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginTop = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginRight = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginBottom = 1; // INCH Unit!!! } else { file = new PrintFile(_hostEnvironment.ContentRootPath + filePath, fileName); } //create an encryption metadata to set to the PrintFile EncryptMetadata encMetadata = new EncryptMetadata(wcp_pub_key_base64, wcp_pub_key_signature_base64); //set encyption metadata to PrintFile file.EncryptMetadata = encMetadata; //create ClientPrintJob for printing encrypted file ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName)); } //set the Encryption Metadata Response.Cookies.Append("wcp_enc_metadata", encMetadata.Serialize(), new Microsoft.AspNetCore.Http.CookieOptions() { Path = "/", HttpOnly = false, IsEssential = true //<- MUST BE SET TO TRUE; otherwise the cookie will not be appended! }); return(File(cpj.GetContent(), "application/octet-stream")); } else { return(BadRequest("File not found!")); } }
public IActionResult PrintFile(string printerName, string trayName, string paperName, string printRotation, string pagesRange, string printAnnotations, string printAsGrayscale, string printInReverseOrder, string manualDuplexPrinting, string driverDuplexPrinting, string pageSizing, string autoRotate, string autoCenter) { string fileName = Guid.NewGuid().ToString("N"); string filePath = filePath = "/files/mixed-page-orientation.pdf"; PrintFilePDF file = new PrintFilePDF(_hostEnvironment.ContentRootPath + filePath, fileName); file.PrintRotation = (PrintRotation)Enum.Parse(typeof(PrintRotation), printRotation);; file.PagesRange = pagesRange; file.PrintAnnotations = (printAnnotations == "true"); file.PrintAsGrayscale = (printAsGrayscale == "true"); file.PrintInReverseOrder = (printInReverseOrder == "true"); bool bManualDuplexPrinting = (manualDuplexPrinting == "true"); bool bDriverDuplexPrinting = (driverDuplexPrinting == "true"); if (bManualDuplexPrinting && bDriverDuplexPrinting) { bManualDuplexPrinting = false; } file.DuplexPrinting = bManualDuplexPrinting; if (bManualDuplexPrinting) { file.DuplexPrinting = bManualDuplexPrinting; //file.DuplexPrintingDialogMessage = "Your custom dialog message for duplex printing"; } file.Sizing = (Sizing)Enum.Parse(typeof(Sizing), pageSizing); file.AutoCenter = (autoCenter == "true"); file.AutoRotate = (autoRotate == "true"); ClientPrintJob cpj = new ClientPrintJob(); cpj.PrintFile = file; if (printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { if (trayName == "null") { trayName = ""; } if (paperName == "null") { paperName = ""; } cpj.ClientPrinter = new InstalledPrinter(System.Net.WebUtility.UrlDecode(printerName), true, System.Net.WebUtility.UrlDecode(trayName), System.Net.WebUtility.UrlDecode(paperName)); if (bDriverDuplexPrinting) { ((InstalledPrinter)cpj.ClientPrinter).Duplex = Duplex.Vertical; } } return(File(cpj.GetContent(), "application/octet-stream")); }
public void PrintFile(string useDefaultPrinter, string printerName, string fileType, string wcp_pub_key_base64, string wcp_pub_key_signature_base64) { 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 "JPG": filePath = "~/files/penguins300dpi.jpg"; break; case "PNG": filePath = "~/files/SamplePngImage.png"; break; } if (filePath != null && string.IsNullOrEmpty(wcp_pub_key_base64) == false) { //create print file to be encrypted PrintFile file = null; if (fileType == "PDF") { file = new PrintFilePDF(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ((PrintFilePDF)file).PrintRotation = PrintRotation.None; //((PrintFilePDF)file).PagesRange = "1,2,3,10-15"; //((PrintFilePDF)file).PrintAnnotations = true; //((PrintFilePDF)file).PrintAsGrayscale = true; //((PrintFilePDF)file).PrintInReverseOrder = true; } else if (fileType == "TXT") { file = new PrintFileTXT(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ((PrintFileTXT)file).PrintOrientation = PrintOrientation.Portrait; ((PrintFileTXT)file).FontName = "Arial"; ((PrintFileTXT)file).FontSizeInPoints = 12; // Point Unit!!! //((PrintFileTXT)file).TextColor = "#ff00ff"; //((PrintFileTXT)file).TextAlignment = TextAlignment.Center; //((PrintFileTXT)file).FontBold = true; //((PrintFileTXT)file).FontItalic = true; //((PrintFileTXT)file).FontUnderline = true; //((PrintFileTXT)file).FontStrikeThrough = true; //((PrintFileTXT)file).MarginLeft = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginTop = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginRight = 1; // INCH Unit!!! //((PrintFileTXT)file).MarginBottom = 1; // INCH Unit!!! } else { file = new PrintFile(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); } //create an encryption metadata to set to the PrintFile EncryptMetadata encMetadata = new EncryptMetadata(wcp_pub_key_base64, wcp_pub_key_signature_base64); //set encyption metadata to PrintFile file.EncryptMetadata = encMetadata; //create ClientPrintJob for printing encrypted file 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)); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; //set the ClientPrintJob content System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); //set the Encryption Metadata System.Web.HttpContext.Current.Response.Cookies.Add(new HttpCookie("wcp_enc_metadata", encMetadata.Serialize())); System.Web.HttpContext.Current.Response.End(); } }
public void PrintFile(string useDefaultPrinter, string printerName, string fileType, string wcp_pub_key_base64, string wcp_pub_key_signature_base64) { string fileName = Guid.NewGuid().ToString("N") + "." + fileType; string filePath = null; switch (fileType) { case "PDF": filePath = "~/files/LoremIpsum-PasswordProtected.pdf"; break; case "DOC": filePath = "~/files/LoremIpsum-PasswordProtected.doc"; break; case "XLS": filePath = "~/files/SampleSheet-PasswordProtected.xls"; break; } if (filePath != null && string.IsNullOrEmpty(wcp_pub_key_base64) == false) { //ALL the test files are protected with the same password for demo purposes //This password will be encrypted and stored in file metadata string plainTextPassword = "******"; //create print file with password protection PrintFile file = null; if (fileType == "PDF") { file = new PrintFilePDF(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ((PrintFilePDF)file).Password = plainTextPassword; //((PrintFilePDF)file).PrintRotation = PrintRotation.None; //((PrintFilePDF)file).PagesRange = "1,2,3,10-15"; //((PrintFilePDF)file).PrintAnnotations = true; //((PrintFilePDF)file).PrintAsGrayscale = true; //((PrintFilePDF)file).PrintInReverseOrder = true; } else if (fileType == "DOC") { file = new PrintFileDOC(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ((PrintFileDOC)file).Password = plainTextPassword; //((PrintFileDOC)file).PagesRange = "1,2,3,10-15"; //((PrintFileDOC)file).PrintInReverseOrder = true; } else if (fileType == "XLS") { file = new PrintFileXLS(System.Web.HttpContext.Current.Server.MapPath(filePath), fileName); ((PrintFileXLS)file).Password = plainTextPassword; //((PrintFileXLS)file).PagesFrom = 1; //((PrintFileXLS)file).PagesTo = 3; } //create an encryption metadata to set to the PrintFile EncryptMetadata encMetadata = new EncryptMetadata(wcp_pub_key_base64, wcp_pub_key_signature_base64); //set encyption metadata to PrintFile to ENCRYPT the Password to unlock the file file.EncryptMetadata = encMetadata; //create ClientPrintJob for printing encrypted file 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)); } System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); } }
public void PrintInvoice(string useDefaultPrinter, string printerName, MInvoice lInvoice) { var lLengthName = 8; var lLengthCDProduct = 10; var lLengthQtyProduct = 4; var lLengthTotal = 7; var lTotalInvoice = 0; //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 += "VideoJuegos RT"; //text to print cmds += ESC + "!" + "0x16"; cmds += NewLine; cmds += "Dirección: " + "Calle 38 No 7-73 C.C. BACAL Local 27-28 y 47"; cmds += NewLine; cmds += "Telefono: " + "3124121752"; cmds += NewLine + NewLine; cmds += "Factura De Venta: " + lInvoice.LCdInvoice; cmds += NewLine; var lNamecompleted = lInvoice.LCustomer.LNameCustomer; if (!string.IsNullOrEmpty(lInvoice.LCustomer.LLastNameCustomer)) { lNamecompleted += " " + lInvoice.LCustomer.LLastNameCustomer; } cmds += "Nombre cliente: " + lNamecompleted; cmds += NewLine + NewLine; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += "Codigo Nombre Cantidad Total "; cmds += NewLine; lInvoice.LListMInvoiceItem.ForEach(x => { var lCdProduct = x.LProduct.LCdProduct.PadRight(lLengthCDProduct); if (lCdProduct.Length > lLengthCDProduct) { lCdProduct = lCdProduct.Substring(0, lLengthCDProduct); } var lName = x.LProduct.LNameProduct.PadRight(lLengthName); if (lName.Length > lLengthName) { lName = lName.Substring(0, lLengthName); } var lQty = Convert.ToInt32(x.LQuantity); var lTotal = Convert.ToInt32(x.LValueTotal); lTotalInvoice += lTotal; cmds += lCdProduct + " " + lName + " " + lQty.ToString().PadRight(lLengthQtyProduct) + " " + lTotal.ToString().PadRight(lLengthTotal); cmds += NewLine; }); cmds += NewLine; cmds += "SUBTOTAL " + lTotalInvoice; cmds += NewLine; cmds += "TOTAL " + lTotalInvoice; cmds += NewLine + NewLine; cmds += ESC + "!" + "0x18"; //Emphasized + Double-height mode selected (ESC ! (16 + 8)) 24 dec => 18 hex cmds += "# PRODUCTOS VENDIDOS"; cmds += ESC + "!" + "0x00"; //Character font A selected (ESC ! 0) cmds += NewLine; cmds += DateTime.Now.ToLongDateString(); cmds += NewLine; cmds += DateTime.Now.ToLongTimeString(); cmds += NewLine + NewLine + NewLine + NewLine + NewLine + NewLine + NewLine + NewLine + NewLine; //Create a ClientPrintJob and send it back to the client! ClientPrintJob cpj = new ClientPrintJob(); //set ESCPOS commands to print... cpj.PrinterCommands = cmds; cpj.FormatHexValues = true; //set client printer... if (useDefaultPrinter == "checked" || printerName == "null") { cpj.ClientPrinter = new DefaultPrinter(); } else { cpj.ClientPrinter = new InstalledPrinter(printerName); } //send it... System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(cpj.GetContent()); System.Web.HttpContext.Current.Response.End(); }