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"));
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
            }
        }