星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

LatticeFileHelper.cs 14KB

vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 4 Jahren
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
vor 1 Jahr
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing.Printing;
  5. using System.Threading;
  6. namespace Common.system
  7. {
  8. using XHWK.WKTool.system;
  9. /// <summary>
  10. /// 点阵文件制作打印
  11. /// 创建时间:2020年9月1日
  12. /// </summary>
  13. public class LatticeFileHelper
  14. {
  15. /// <summary>
  16. /// 打印进程
  17. /// </summary>
  18. public static Process PrintProcess;
  19. /// <summary>
  20. /// 输出日志文件地址 每个文件2MB左右
  21. /// </summary>
  22. private static string _logPath = "";
  23. /// <summary>
  24. /// 运行配置 首次打开必须运行
  25. /// </summary>
  26. public static void RunPrintConfig()
  27. {
  28. string path = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintConfig.exe");
  29. Process myProcess = new Process();
  30. _logPath = CreateLog();
  31. myProcess.StartInfo.FileName = path; //绝对路径
  32. //myProcess.StartInfo.Arguments = "";
  33. myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  34. myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  35. myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  36. myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  37. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  38. myProcess.ErrorDataReceived += Output;
  39. myProcess.Start(); //启动线程
  40. myProcess.BeginErrorReadLine(); //开始异步读取
  41. myProcess.WaitForExit(); //阻塞等待进程结束
  42. myProcess.Close(); //关闭进程
  43. myProcess.Dispose(); //释放资源
  44. }
  45. /// <summary>
  46. /// 生成点阵打印文件
  47. /// </summary>
  48. /// <param name="pdfPath">PDF文件位置</param>
  49. /// <param name="savePath">保存文件位置 TPF</param>
  50. /// <param name="printResult">输出结果,非0为失败</param>
  51. /// <param name="standardError">错误信息</param>
  52. /// <param name="standardOutput">输出信息["1536.688.35.70","1536.688.35.71","1536.688.35.72"]</param>
  53. /// <param name="pointType">0 为方点,1 为圆点 默认方点</param>
  54. public static void GeneratingPdf
  55. (
  56. string pdfPath,
  57. string savePath,
  58. out int printResult,
  59. out string standardError,
  60. out string standardOutput,
  61. int pointType = 0
  62. )
  63. {
  64. //XML点阵文件位置
  65. string xmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
  66. string contentParameter;
  67. contentParameter = "-sMode=Generate \"-sPDF=" + pdfPath + "\" \"-sLIC=" + xmlFile + "\" \"-oTPF=" + savePath + "\" \"-dType=" + pointType + "\" "; //[-dType=0] [-dPrint=0] [-pStart=0]
  68. #region 制作点阵文件参数说明
  69. //-sMode = Generate - sPDF = d:\l\e.pdf - sLIC = d:\l\a.xml - oPDF = d:\l\11210.pdf"
  70. //当 - sMode = Generate,参数如下:
  71. //PrintTool.exe - sMode = Generate - sPDF = -sLIC = < -oPDF =| -oTPF=> [dType=] [-dPrint] [-pStart =]
  72. //- sPDF 原始 PDF 文件路径
  73. //- sLIC 点阵资源文件路径
  74. //- oPDF 生成的点阵 PDF 文件路径,-oPDF 与 - oTPF 至少设置一个。PDF 与 TPF 说明参见 2 生成文件类型说明
  75. //- oTPF 生成的 TPF 文件,-oPDF 与 - oTPF 至少设置一个。PDF 与 TPF 说明参见 2 生成文件类型说明
  76. //- dType 0 为方点,1 为圆点;可选参数,默认 0。详细参数区别,参见 3.1 点阵形状
  77. //- dPrint 0 为激光打印机,1 为印刷机;可选参数,默认 0。详细参数区别,参见 3.2 点阵 PDF 适用打印场景
  78. //- pStart 整数,选择从哪页点阵资源开始制作点阵文件, 即起始点阵资源页序号;可选参数,默认0。关于 - pStart 的功能说明,参见 1.3.1.高级设置
  79. #endregion
  80. while (PrintProcess != null)
  81. {
  82. Thread.Sleep(100);
  83. }
  84. Process[] killProcessArray = Process.GetProcessesByName("PrintTool");
  85. foreach (Process killProcess in killProcessArray)
  86. {
  87. killProcess.Kill();
  88. }
  89. PrintProcess = new Process();
  90. _logPath = CreateLog();
  91. PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe"); //绝对路径
  92. PrintProcess.StartInfo.Arguments = contentParameter;
  93. PrintProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  94. PrintProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  95. PrintProcess.StartInfo.RedirectStandardOutput = true;
  96. PrintProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  97. PrintProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  98. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  99. PrintProcess.ErrorDataReceived += Output;
  100. PrintProcess.Start(); //启动线程
  101. PrintProcess.WaitForExit(); //阻塞等待进程结束
  102. standardError = PrintProcess.StandardError.ReadToEnd();
  103. standardOutput = PrintProcess.StandardOutput.ReadToEnd();
  104. //PrintProcess.BeginErrorReadLine(); //开始异步读取
  105. Output("【制作点阵文件】错误:" + standardError);
  106. Output("【制作点阵文件】返回信息:" + standardOutput);
  107. printResult = PrintProcess.ExitCode; //打印结果 非0则为打印失败
  108. Output("【制作点阵文件】" + contentParameter); //记录打印日志
  109. PrintProcess.Close(); //关闭进程
  110. PrintProcess.Dispose(); //释放资源
  111. #region 进程是否已经释放
  112. bool isRunning = true;
  113. while (isRunning)
  114. {
  115. isRunning = false;
  116. Process[] processArray = Process.GetProcessesByName("PrintTool");
  117. if (processArray.Length > 0)
  118. {
  119. isRunning = true;
  120. Thread.Sleep(100);
  121. }
  122. }
  123. #endregion
  124. PrintProcess = null;
  125. }
  126. /// <summary>
  127. /// 获取打印机列表
  128. /// </summary>
  129. /// <param name="defaultPrinter">默认打印机</param>
  130. /// <returns>打印机列表</returns>
  131. public static List<string> GetPrinterList(out string defaultPrinter)
  132. {
  133. List<string> printersList = new List<string>();
  134. defaultPrinter = null;
  135. try
  136. {
  137. PrintDocument print = new PrintDocument();
  138. defaultPrinter = print.PrinterSettings.PrinterName; //默认打印机名
  139. foreach (string sPrint in PrinterSettings.InstalledPrinters) //获取所有打印机名称
  140. {
  141. printersList.Add(sPrint);
  142. }
  143. }
  144. catch (Exception)
  145. {
  146. // ignored
  147. }
  148. return printersList;
  149. }
  150. /// <summary>
  151. /// 打印TPF点阵文件
  152. /// </summary>
  153. /// <param name="tpfPath">TPF路径</param>
  154. /// <param name="printerNum">打印份数</param>
  155. /// <param name="printerName">打印机名称</param>
  156. /// <param name="printResult">输出结果,非0为失败</param>
  157. /// <param name="standardError">错误信息</param>
  158. /// <param name="standardOutput">输出信息</param>
  159. public static void PrinterTpfFile
  160. (
  161. string tpfPath,
  162. int printerNum,
  163. string printerName,
  164. out int printResult,
  165. out string standardError,
  166. out string standardOutput
  167. )
  168. {
  169. tpfPath = tpfPath.Replace("/", "\\");
  170. //XML点阵文件位置
  171. //string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
  172. string contentParameter = " -sMode=Print \"-sTPF=" + tpfPath + "\" \"-sPrinter=" + printerName + "\" \"-dCopy=" + printerNum + "\""; //\"-dPaperSize=9\"
  173. #region 打印参数说明
  174. //-sMode = Print,参数如下:
  175. //PrintTool.exe - sMode = Print - sTPF = [-dCopy =][-dPaperSize =] - sPrinter =
  176. //-sTPF 需要打印的 TPF 文件路径
  177. //- dCopy 整数,可选参数,打印份数,默认 1
  178. //- dPaperSize 整数,可选参数,设置打印纸张尺寸。不设置此值,系统自动选择匹配纸张打印;A4:"-dPaperSize=9" DMPAPER_A4 9 A4 210 x 297 mm 如
  179. // 需要手动设置纸张尺寸,不同尺寸纸张对应值,参见 https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes
  180. //- sPrinter 打印机名称
  181. // 打印完成后,如果打印成功,PrintTool.exe 退出值为 0。
  182. //如果打印失败,程序退出值为非 0。
  183. #endregion
  184. while (PrintProcess != null)
  185. {
  186. Thread.Sleep(100);
  187. }
  188. Process[] killProcessArray = Process.GetProcessesByName("PrintTool");
  189. foreach (Process killProcess in killProcessArray)
  190. {
  191. killProcess.Kill();
  192. }
  193. PrintProcess = new Process();
  194. _logPath = CreateLog();
  195. PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe").Replace("/", "\\");
  196. PrintProcess.StartInfo.Arguments = contentParameter;
  197. PrintProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
  198. PrintProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
  199. PrintProcess.StartInfo.RedirectStandardOutput = true;
  200. PrintProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
  201. PrintProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
  202. //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
  203. PrintProcess.ErrorDataReceived += Output;
  204. PrintProcess.Start(); //启动线程
  205. //PrintProcess.BeginErrorReadLine(); //开始异步读取
  206. PrintProcess.WaitForExit(); //阻塞等待进程结束
  207. standardError = PrintProcess.StandardError.ReadToEnd();
  208. standardOutput = PrintProcess.StandardOutput.ReadToEnd();
  209. Output("【制作点阵文件】错误:" + standardError);
  210. Output("【制作点阵文件】返回信息:" + standardOutput);
  211. printResult = PrintProcess.ExitCode; //打印结果 非0则为打印失败
  212. Output("【打印TPF文件】" + contentParameter); //记录打印日志
  213. PrintProcess.Close(); //关闭进程
  214. PrintProcess.Dispose(); //释放资源
  215. #region 进程是否已经释放
  216. bool isRunning = true;
  217. while (isRunning)
  218. {
  219. isRunning = false;
  220. Process[] processArray = Process.GetProcessesByName("PrintTool");
  221. if (processArray.Length > 0)
  222. {
  223. isRunning = true;
  224. Thread.Sleep(100);
  225. }
  226. }
  227. #endregion
  228. PrintProcess = null;
  229. }
  230. /// <summary>
  231. /// 创建日志文件
  232. /// </summary>
  233. /// <returns></returns>
  234. private static string CreateLog()
  235. {
  236. string logFileName = DateTime.Now.ToString("yyyyMMdd");
  237. string logFilePath = FileToolsCommon.GetFileAbsolutePath("/Log/PrintLog/");
  238. FileToolsCommon.CreateDirectory(logFilePath);
  239. string logName = logFilePath + logFileName + ".log";
  240. try
  241. {
  242. if (!FileToolsCommon.IsExistFile(logName))
  243. {
  244. FileToolsCommon.CreateFile(logName);
  245. //FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
  246. // "****************************************************************************************************\r\n");
  247. return logName;
  248. }
  249. else
  250. {
  251. int num = 0;
  252. while (FileToolsCommon.GetFileSizeByMb(logName) > 2)
  253. {
  254. num++;
  255. logName = logFilePath + logFileName + "_" + num + ".log";
  256. FileToolsCommon.CreateFile(logName);
  257. }
  258. //FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
  259. // "****************************************************************************************************\r\n");
  260. return logName;
  261. }
  262. }
  263. catch (Exception)
  264. {
  265. return logName;
  266. }
  267. }
  268. /// <summary>
  269. /// 输出日志
  270. /// </summary>
  271. /// <param name="message"></param>
  272. private static void Output(string message)
  273. {
  274. if (!string.IsNullOrEmpty(message))
  275. {
  276. FileToolsCommon.AppendText(_logPath, message + "\r\n");
  277. FileToolsCommon.AppendText(_logPath, "\r\n****************************************************************************************************" + "****************************************************************************************************\r\n");
  278. }
  279. }
  280. /// <summary>
  281. /// 输出结果
  282. /// </summary>
  283. /// <param name="sendProcess"></param>
  284. /// <param name="output"></param>
  285. private static void Output(object sendProcess, DataReceivedEventArgs output)
  286. {
  287. Output(output.Data);
  288. }
  289. }
  290. }