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 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 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 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 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")); }