/// <summary> /// 虚拟打印 /// </summary> /// <param name="GetNums">报表相关参数</param> /// <param name="GetMargin">打印机边距数组</param> /// <param name="printCount">打印份数</param> /// <param name="url">ref 虚拟打印生成的文件路径</param> /// <param name="printName">ref 打印机名称</param> /// <param name="fielParam">生成文件名的参数数组</param> /// <returns>实现打印并返回ReportDocument</returns> public ReportDocument VirtualPrint(string[] GetNums, double[] GetMargin, int printCount, ref string url, string folder, ref string printName, string[] fileParam) { string msgStr = "【" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff") + "】 准备参数 \r\n"; ReportDocument doc = new ReportDocument(); try { //string folder = Server.MapPath("PDF"); string PaperSize = ""; string fileName = GetfileName(ref PaperSize, fileParam); // 获取 纸张类型 ,文件名称 if (fileParam[0].ToLower() == "blsample" && Convert.ToInt32(GetNums[4]) > -1) { fileName = fileName.Insert(fileName.LastIndexOf("_"), "_" + GetNums[4]); } if (string.IsNullOrEmpty(fileName)) { return(null); } // 设置文件类型 string ff = HttpContext.Current.Request["format"]; int format = string.IsNullOrEmpty(ff) ? 4 : Convert.ToInt32(ff); GetPrintName(ref printName, PaperSize, PrintImgSetting.PIS.FileFormat(format)); // 获取可用的打印机名称 UpdatePrinterStatus(printName, 1, fileParam); // 更新打印机状态 //PrintImgSetting pis = new PrintImgSetting(); // 配置虚拟打印机 相关属性 //文件打印像素 int size = 240; // 设置文件是否连续显示 string cm = HttpContext.Current.Request["CreateMode"]; int mode = string.IsNullOrEmpty(cm) ? 0 : Convert.ToInt32(cm); string randomFolder = "/PreviewTemp/" + (string.IsNullOrEmpty(folder) ? DateTime.Now.ToString("hhmmssffff") : folder); MoveFile mf = new MoveFile(); mf.CreateDirectory(HttpContext.Current.Server.MapPath(randomFolder)); //设置文件目录 //PrintImgSetting.PIS.SetFileFolder(printName, HttpContext.Current.Server.MapPath(randomFolder)); //Thread.Sleep(300); //PrintImgSetting.PIS.SetFileName(printName, fileName); //设置文件名称 //Thread.Sleep(300); //PrintImgSetting.PIS.SetFileFormat(printName, format); //设置文件路径 //Thread.Sleep(300); //PrintImgSetting.PIS.SetCreateMode(printName, mode); //设置文件连续显示 //Thread.Sleep(300); PrintZanSetting.PrintSetting(printName, HttpContext.Current.Server.MapPath(randomFolder), fileName, null); msgStr += "【" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff") + "】 开始打印,打印机:" + printName + " ; 用户:" + FSecurityHelper.CurrentUserDataGET()[0] + "," + FSecurityHelper.CurrentUserDataGET()[12] + " ; 报表类型:" + GetNums[0].Substring(GetNums[0].LastIndexOf("\\") + 1) + " ; SeedID :" + GetNums[3] + "\r\n"; doc = ToPrintPaper(GetNums, GetMargin, printCount, printName); //实现打印功能 msgStr += "【" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss fff") + "】 打印完成,开始执行预览 \r\n------------------------------------------------------\r\n"; //打印机生成的文件路径 url = randomFolder + "/" + fileName + "." + PrintImgSetting.PIS.FileFormat(format); //Thread.Sleep(1000); // 等待打印文件读写 UpdatePrinterStatus(printName, 0, fileParam); // 更新打印机状态 PrinterLOG.WriterLog(msgStr, printName, false); return(doc); //Setframe(url); } catch (Exception exp) { PrinterLOG.WriterLog(exp.Message, printName, true); UpdatePrinterStatus(printName, 0, fileParam); // 更新打印机状态 return(null); //HttpContext.Current.Response.Write(exp.Message); //HttpContext.Current.Response.Flush(); //HttpContext.Current.Response.Close(); } }
/// <summary> /// 虚拟打印 /// </summary> /// <param name="GetNums">报表相关参数</param> /// <param name="GetMargin">打印机边距数组</param> /// <param name="printCount">打印份数</param> /// <param name="url">ref 虚拟打印生成的文件路径</param> /// <param name="printName">ref 打印机名称</param> /// <param name="fielParam">生成文件名的参数数组</param> /// <returns>实现打印并返回ReportDocument</returns> public ReportDocument VirtualPrint(string[] GetNums, double[] GetMargin, int printCount, ref string url, string folder, ref string printName, string[] fileParam) { ReportDocument doc = new ReportDocument(); try { //string folder = Server.MapPath("PDF"); string PaperSize = ""; string fileName = GetfileName(ref PaperSize, fileParam); // 获取 纸张类型 ,文件名称 if (fileParam[0].ToLower() == "blsample" && Convert.ToInt32(GetNums[4]) > -1) { fileName = fileName.Insert(fileName.LastIndexOf("_"), "_" + GetNums[4]); } if (string.IsNullOrEmpty(fileName)) { return(null); } GetPrintName(ref printName, PaperSize); // 获取可用的打印机名称 UpdatePrinterStatus(printName, 1, fileParam); // 更新打印机状态 //PrintImgSetting pis = new PrintImgSetting(); // 配置虚拟打印机 相关属性 // 设置文件类型 string ff = HttpContext.Current.Request["format"]; int format = string.IsNullOrEmpty(ff) ? 4 : Convert.ToInt32(ff); //文件打印像素 int size = 240; // 设置文件是否连续显示 string cm = HttpContext.Current.Request["CreateMode"]; int mode = string.IsNullOrEmpty(cm) ? 0 : Convert.ToInt32(cm); string randomFolder = "/PreviewTemp/" + (string.IsNullOrEmpty(folder) ? DateTime.Now.ToString("hhmmssffff") : folder); MoveFile mf = new MoveFile(); mf.CreateDirectory(HttpContext.Current.Server.MapPath(randomFolder)); //设置文件目录 PrintImgSetting.PIS.SetFileFolder(printName, HttpContext.Current.Server.MapPath(randomFolder)); Thread.Sleep(300); PrintImgSetting.PIS.SetFileName(printName, fileName); //设置文件名称 Thread.Sleep(300); PrintImgSetting.PIS.SetFileFormat(printName, format); //设置文件路径 Thread.Sleep(300); PrintImgSetting.PIS.SetCreateMode(printName, mode); //设置文件连续显示 Thread.Sleep(300); doc = ToPrintPaper(GetNums, GetMargin, printCount, printName); //实现打印功能 //打印机生成的文件路径 url = randomFolder + "/" + fileName + "." + PrintImgSetting.PIS.FileFormat(format); Thread.Sleep(2000); // 等待打印文件读写 UpdatePrinterStatus(printName, 0, fileParam); // 更新打印机状态 return(doc); //Setframe(url); } catch (Exception exp) { UpdatePrinterStatus(printName, 0, fileParam); // 更新打印机状态 return(null); //HttpContext.Current.Response.Write(exp.Message); //HttpContext.Current.Response.Flush(); //HttpContext.Current.Response.Close(); } }