ConverterHelper.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ComPDFKit_Conversion.Converter;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using Microsoft.AppCenter.Crashes.Ingestion.Models;
  10. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  11. using ComPDFKit_Conversion.Options;
  12. using PDF_Master.CustomControl;
  13. using Exception = System.Exception;
  14. using ImageMagick;
  15. using System.IO.Compression;
  16. using System.Windows;
  17. using System.Net.Mime;
  18. using System.Windows.Controls;
  19. using PDF_Master.Properties;
  20. using ComDocumentAIKit;
  21. namespace PDF_Master.Helper
  22. {
  23. public static class ConverterHelper
  24. {
  25. public static CPDFConverterWord wordConverter = null;
  26. public static CPDFConverterExcel excelConverter = null;
  27. public static CPDFConverterPPT pptConverter = null;
  28. public static CPDFConverterTxt txtConverter = null;
  29. public static CPDFConverterCsv csvConverter = null;
  30. public static CPDFConverterImg imgConverter = null;
  31. public static CPDFConverterRTF rtfConverter = null;
  32. public static CPDFConverterHTML htmlConverter = null;
  33. public static async Task<bool> WordConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertWordOptions wordOptions = null, bool IsCustomFileName = true)
  34. {
  35. bool result = false;
  36. try
  37. {
  38. int[] pageArray = pageIndexLists.ToArray();
  39. wordConverter = new CPDFConverterWord(inputpath, pawssword);
  40. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  41. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  42. ConvertError error = ConvertError.ERR_UNKNOWN;
  43. string filename = GetFileNameAddSuffix(outputFolder, outputFileName, ".docx");
  44. result = await Task.Run(() => wordConverter.Convert(outputFolder, ref outputFileName, wordOptions, pageArray, ref error, getProgress));
  45. if (result)
  46. {
  47. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  48. {
  49. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  50. }
  51. }
  52. }
  53. catch
  54. {
  55. }
  56. return result;
  57. }
  58. public static async Task<bool> PPTConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertPPTOptions pptOptions = null, bool IsCustomFileName = true)
  59. {
  60. bool result = false;
  61. try
  62. {
  63. int[] pageArray = pageIndexLists.ToArray();
  64. pptConverter = new CPDFConverterPPT(inputpath, pawssword);
  65. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  66. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  67. ConvertError error = ConvertError.ERR_UNKNOWN;
  68. string filename = GetFileNameAddSuffix(outputFolder, outputFileName, ".ppt");
  69. result = await Task.Run(() => pptConverter.Convert(outputFolder, ref outputFileName, pptOptions, pageArray, ref error, getProgress));
  70. if (result)
  71. {
  72. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  73. {
  74. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  75. }
  76. }
  77. }
  78. catch
  79. {
  80. }
  81. return result;
  82. }
  83. public static async Task<bool> ExcelConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertExcelOptions ExcelOption, bool IsCustomFileName = true)
  84. {
  85. bool result = false;
  86. try
  87. {
  88. excelConverter = new CPDFConverterExcel(inputpath, pawssword);
  89. int[] pageArray = pageIndexLists.ToArray();
  90. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  91. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  92. ConvertError error = ConvertError.ERR_UNKNOWN;
  93. result = await Task.Run(() => excelConverter.Convert(outputFolder, ref outputFileName, ExcelOption, pageArray, ref error, getProgress));
  94. if (result)
  95. {
  96. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  97. {
  98. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  99. }
  100. else if (outputFileName == "NoTable")
  101. {
  102. AlertsMessage alertsMessage = new AlertsMessage();
  103. alertsMessage.ShowDialog("", " No Table", App.ServiceLoader.GetString("Text_ok"));
  104. }
  105. }
  106. }
  107. catch
  108. {
  109. }
  110. return result;
  111. }
  112. //public static async Task<bool> TableConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword)
  113. //{
  114. // bool result = false;
  115. // try
  116. // {
  117. // int[] pageArray = pageIndexLists.ToArray();
  118. // tableConverter = new CPDFConverterTable(inputpath, pawssword);
  119. // string outputFolder = outputpath;
  120. // string outputFileName = Path.GetFileNameWithoutExtension(inputpath);
  121. // ConvertError error = ConvertError.ERR_UNKNOWN;
  122. // string filename = GetFileNameAddSuffix(outputFolder, outputFileName, ".xlsx");
  123. // result = await Task.Run(() => tableConverter.Convert(outputFolder, ref outputFileName, pageArray, ref error, getProgress));
  124. // }
  125. // catch (Exception ex)
  126. // {
  127. // }
  128. // return result;
  129. //}
  130. public static async Task<bool> CSVConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertCsvOptions csvOptions = null, bool IsCustomFileName = true)
  131. {
  132. bool result = false;
  133. try
  134. {
  135. int[] pageArray = pageIndexLists.ToArray();
  136. csvConverter = new CPDFConverterCsv(inputpath, pawssword);
  137. string outputFolder = "";
  138. string outputFileName = "";
  139. if (IsCustomFileName)
  140. {
  141. outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  142. outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  143. }
  144. else
  145. {
  146. outputFolder = outputpath;
  147. outputFileName = Path.GetFileNameWithoutExtension(inputpath);
  148. }
  149. ConvertError error = ConvertError.ERR_UNKNOWN;
  150. string filename = GetFileNameAddSuffix(outputFolder, outputFileName, ".csv");
  151. result = await Task.Run(() => csvConverter.Convert(outputFolder, ref outputFileName, csvOptions, pageArray, ref error, getProgress));
  152. if (result)
  153. {
  154. if (File.Exists(outputFileName))
  155. {
  156. if (IsCustomFileName)
  157. {
  158. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  159. {
  160. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  161. }
  162. }
  163. else
  164. {
  165. string FileName = CommonHelper.CreateFolder(outputFileName.Replace(".zip", ""));
  166. ZipFile.ExtractToDirectory(outputFileName, FileName);
  167. File.Delete(outputFileName);
  168. CommonHelper.ShowFileBrowser(FileName.Replace("/", "\\"));
  169. }
  170. }
  171. else
  172. {
  173. AlertsMessage alertsMessage = new AlertsMessage();
  174. alertsMessage.ShowDialog("", " No Table", App.ServiceLoader.GetString("Text_ok"));
  175. }
  176. }
  177. }
  178. catch
  179. {
  180. }
  181. return result;
  182. }
  183. public static async Task<bool> TxtConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertTxtOptions txtOptions = null, bool IsCustomFileName = true)
  184. {
  185. bool result = false;
  186. try
  187. {
  188. int[] pageArray = pageIndexLists.ToArray();
  189. txtConverter = new CPDFConverterTxt(inputpath, pawssword);
  190. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  191. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  192. ConvertError error = ConvertError.ERR_UNKNOWN;
  193. string filename = GetFileNameAddSuffix(outputFolder, outputFileName, ".txt");
  194. result = await Task.Run(() => txtConverter.Convert(outputFolder, ref outputFileName, txtOptions, pageArray, ref error, getProgress));
  195. if (result)
  196. {
  197. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  198. {
  199. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  200. }
  201. }
  202. }
  203. catch
  204. {
  205. }
  206. return result;
  207. }
  208. public static void ImageMagickPDFToImage(string imageType, string filePath, string outputFolder, string outputFileName, ref string FileName, double density = 150)
  209. {
  210. FileName = CommonHelper.CreateFolder(outputFolder + "\\" + outputFileName);
  211. ZipFile.ExtractToDirectory(filePath, FileName);
  212. var files = Directory.GetFiles(FileName, "*.png");
  213. int i = 0;
  214. var images = new MagickImageCollection();
  215. foreach (var file in files)
  216. {
  217. //pdf整体转为gif,将.gifoff改为.gif
  218. Trace.WriteLine(file);
  219. if (imageType == ".gifoff")
  220. {
  221. images.Add(file);
  222. images[i].AnimationDelay = 100; // in this example delay is 1000ms/1sec
  223. images[i].Flip();
  224. }
  225. using (var image = new MagickImage(file))
  226. {
  227. if (imageType != ".gifoff")
  228. {
  229. //Save frame as jpg
  230. //image.Format = MagickFormat.Jp2;
  231. //水平垂直DPI
  232. image.Density = new Density(density);
  233. image.Write(file.Remove(file.LastIndexOf(".png"), 4) + imageType);
  234. }
  235. // 删除该文件
  236. System.IO.File.Delete(file);
  237. }
  238. }
  239. if (imageType == ".gifoff")
  240. {
  241. // Optionally reduce colors
  242. var settings = new QuantizeSettings();
  243. settings.Colors = 256;
  244. images.Quantize(settings);
  245. // Optionally optimize the images (images should have the same size).
  246. images.Optimize();
  247. // Save gif
  248. int fileIndex = 1;
  249. if (File.Exists(outputFolder + "\\" + outputFileName + ".gif"))
  250. {
  251. while (fileIndex >= 1)
  252. {
  253. if (!File.Exists(outputFolder + "\\" + outputFileName + "_" + fileIndex + ".gif"))
  254. {
  255. images.Write(outputFolder + "\\" + outputFileName + ".gif");
  256. fileIndex = -1;
  257. }
  258. fileIndex++;
  259. }
  260. }
  261. else { images.Write(outputFolder + "\\" + outputFileName + ".gif"); }
  262. }
  263. //else {
  264. // int fileIndex = 1;
  265. // if (File.Exists(outputFolder + "\\" + outputFileName + ".zip"))
  266. // {
  267. // while (fileIndex>=1) {
  268. // if (!File.Exists(outputFolder + "\\" + outputFileName + "_" + fileIndex + ".zip"))
  269. // {
  270. // ZipFile.CreateFromDirectory(outputFolder + "\\" + outputFileName, outputFolder + "\\" + outputFileName + "_" + fileIndex + ".zip");
  271. // fileIndex=-1;
  272. // }
  273. // fileIndex++;
  274. // }
  275. // }
  276. // else { ZipFile.CreateFromDirectory(outputFolder + "\\" + outputFileName, outputFolder + "\\" + outputFileName + ".zip"); }
  277. //}
  278. //DirectoryInfo di = new DirectoryInfo(outputFolder + "\\" + outputFileName);
  279. //di.Delete(true);
  280. }
  281. public static async Task<bool> ImgConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, string imageType = ".png", CPDFConvertImgOptions imgOptions = null)
  282. {
  283. string FileName = "";
  284. bool result = false;
  285. try
  286. {
  287. int[] pageArray = pageIndexLists.ToArray();
  288. imgConverter = new CPDFConverterImg(inputpath, pawssword);
  289. string outputFolder = outputpath;
  290. string outputFileName = Path.GetFileNameWithoutExtension(inputpath);
  291. ConvertError error = ConvertError.ERR_UNKNOWN;
  292. if (imageType == ".png" || imageType == ".jpg")
  293. {
  294. result = await Task.Run(() => imgConverter.Convert(outputFolder, ref outputFileName, imgOptions, pageArray, ref error, getProgress));
  295. FileName = CommonHelper.CreateFolder(outputFileName.Replace(".zip", ""));
  296. ZipFile.ExtractToDirectory(outputFileName, FileName);
  297. FileInfo file = new FileInfo(outputFileName);
  298. if (file.Exists) { file.Delete(); }
  299. }
  300. else
  301. { //创建缓存文件夹
  302. string folderPath = Path.Combine(App.CurrentPath, "ConverterImg");
  303. //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
  304. //保险措施(猜测)
  305. if (File.Exists(folderPath))
  306. {
  307. File.Delete(folderPath);
  308. }
  309. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  310. if (!tempfolder.Exists)
  311. {
  312. tempfolder.Create();
  313. }
  314. //预览图缓存
  315. string saveName = Guid.NewGuid().ToString();
  316. string savePath = Path.Combine(folderPath, saveName);
  317. result = await Task.Run(() => imgConverter.Convert(folderPath, ref saveName, imgOptions, pageArray, ref error, getProgress));
  318. ImageMagickPDFToImage(imageType, saveName, outputFolder, outputFileName, ref FileName, imgOptions.ImageDpi);
  319. DirectoryInfo di = new DirectoryInfo(folderPath);
  320. di.Delete(true);
  321. }
  322. if (result)
  323. {
  324. //Process.Start(FileName.Replace("/", "\\"));
  325. CommonHelper.ShowFileBrowser(FileName.Replace("/", "\\"));
  326. }
  327. }
  328. catch
  329. {
  330. }
  331. return result;
  332. }
  333. public static async Task<bool> RTFConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertRTFOptions rtfOptions = null, bool IsCustomFileName = true)
  334. {
  335. bool result = false;
  336. try
  337. {
  338. int[] pageArray = pageIndexLists.ToArray();
  339. rtfConverter = new CPDFConverterRTF(inputpath, pawssword);
  340. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  341. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  342. ConvertError error = ConvertError.ERR_UNKNOWN;
  343. result = await Task.Run(() => rtfConverter.Convert(outputFolder, ref outputFileName, rtfOptions, pageArray, ref error, getProgress));
  344. if (result)
  345. {
  346. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  347. {
  348. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  349. }
  350. }
  351. }
  352. catch
  353. {
  354. }
  355. return result;
  356. }
  357. public static async Task<bool> HTMLConvert(string inputpath, string outputpath, OnProgress getProgress, List<int> pageIndexLists, string pawssword, CPDFConvertHTMLOptions HtmlOption, bool IsCustomFileName = true)
  358. {
  359. bool result = false;
  360. try
  361. {
  362. htmlConverter = new CPDFConverterHTML(inputpath, pawssword);
  363. int[] pageArray = pageIndexLists.ToArray();
  364. string outputFolder = outputpath.Remove(outputpath.LastIndexOf("\\"));
  365. string outputFileName = Path.GetFileNameWithoutExtension(outputpath);
  366. ConvertError error = ConvertError.ERR_UNKNOWN;
  367. result = await Task.Run(() => htmlConverter.Convert(outputFolder, ref outputFileName, HtmlOption, pageArray, ref error, getProgress));
  368. if (result)
  369. {
  370. if (!String.IsNullOrEmpty(outputFileName) && File.Exists(outputFileName.Replace("/", "\\")))
  371. {
  372. CommonHelper.ShowFileBrowser(outputFileName.Replace("/", "\\"));
  373. }
  374. }
  375. }
  376. catch
  377. {
  378. }
  379. return result;
  380. }
  381. public static void Clear(string ConvertType)
  382. {
  383. switch (ConvertType)
  384. {
  385. case "Word":
  386. if (wordConverter != null)
  387. {
  388. wordConverter.Cancel();
  389. }
  390. break;
  391. case "Excel":
  392. if (excelConverter != null)
  393. {
  394. excelConverter.Cancel();
  395. }
  396. break;
  397. case "PPT":
  398. if (pptConverter != null)
  399. {
  400. pptConverter.Cancel();
  401. }
  402. break;
  403. case "Text":
  404. if (txtConverter != null)
  405. {
  406. txtConverter.Cancel();
  407. }
  408. break;
  409. case "CSV":
  410. if (csvConverter != null)
  411. {
  412. csvConverter.Cancel();
  413. }
  414. break;
  415. case "RTF":
  416. if (rtfConverter != null)
  417. {
  418. rtfConverter.Cancel();
  419. }
  420. break;
  421. case "HTML":
  422. if (htmlConverter != null)
  423. {
  424. htmlConverter.Cancel();
  425. }
  426. break;
  427. case "Img":
  428. if (imgConverter != null)
  429. {
  430. imgConverter?.Cancel();
  431. }
  432. break;
  433. default:
  434. break;
  435. }
  436. }
  437. private static void StartFile(string path)
  438. {
  439. //Process.Start(path);
  440. }
  441. public static string GetFileNameAddSuffix(string path, string filename, string suffix)
  442. {
  443. int i = 1;
  444. string outname = filename;
  445. while (File.Exists(path + @"\" + outname + suffix))
  446. {
  447. outname = filename + $"({i.ToString()})";
  448. i++;
  449. }
  450. return outname;
  451. }
  452. public static Microsoft.Office.Interop.Word.Application word;
  453. public static Microsoft.Office.Interop.Excel.Application excele;
  454. public static Microsoft.Office.Interop.PowerPoint.Application ppt;
  455. public static string ConvertOfficeToPDF(string sourcepath, Microsoft.Office.Interop.Word.WdPaperSize paperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4, double margin = 0)
  456. {
  457. string folderPath = Path.GetTempPath();
  458. if (File.Exists(folderPath))
  459. {
  460. File.Delete(folderPath);
  461. }
  462. DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
  463. if (!tempfolder.Exists)
  464. {
  465. tempfolder.Create();
  466. }
  467. string targetPath = System.IO.Path.Combine(folderPath, Guid.NewGuid().ToString() + ".pdf");
  468. string ex = System.IO.Path.GetExtension(sourcepath).ToLower();
  469. switch (ex)
  470. {
  471. case ".doc":
  472. case ".docx":
  473. case "docm":
  474. case ".dot":
  475. case ".dotx":
  476. case ".dotm":
  477. case ".txt":
  478. case ".html":
  479. if (word == null)
  480. {
  481. word = new Microsoft.Office.Interop.Word.Application();
  482. }
  483. word.Visible = false;
  484. word.ShowWindowsInTaskbar = true;
  485. Microsoft.Office.Interop.Word.Document document = word.Documents.Open(sourcepath);
  486. var page = document.PageSetup;
  487. page.PaperSize = paperSize;
  488. if (margin > 0)
  489. {
  490. page.LeftMargin = page.TopMargin = page.RightMargin = page.BottomMargin = (float)margin;
  491. }
  492. document?.ExportAsFixedFormat(targetPath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
  493. document?.Close(false);
  494. if (word != null)
  495. {
  496. word.NormalTemplate.Saved = true;
  497. //word.Quit();
  498. }
  499. break;
  500. case ".xls":
  501. case ".xlsx":
  502. case ".xlsm":
  503. case ".xlsb":
  504. case ".xlam":
  505. case ".xltx":
  506. case ".xlt":
  507. if (excele == null)
  508. {
  509. excele = new Microsoft.Office.Interop.Excel.Application();
  510. }
  511. Microsoft.Office.Interop.Excel.Workbook workbook = null;
  512. excele.Visible = false;
  513. try
  514. {
  515. workbook = excele.Workbooks.Open(sourcepath);
  516. }
  517. catch
  518. {
  519. workbook = excele.Workbooks.Open(sourcepath, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "t", false, false, 0, true, 1, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlRepairFile);
  520. }
  521. workbook?.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, targetPath);
  522. workbook?.Close();
  523. //excele?.Quit();
  524. break;
  525. case ".ppt":
  526. case ".pptx":
  527. case ".pptm":
  528. case ".pptsx":
  529. case ".pps":
  530. case ".pptsm":
  531. case ".pot":
  532. case ".potm":
  533. if (ppt == null)
  534. {
  535. ppt = new Microsoft.Office.Interop.PowerPoint.Application();
  536. }
  537. Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
  538. //ppt.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue;
  539. //ppt.ShowStartupDialog = Microsoft.Office.Core.MsoTriState.msoFalse;
  540. //ppt.ShowWindowsInTaskbar = Microsoft.Office.Core.MsoTriState.msoFalse;
  541. presentation = ppt.Presentations.Open(sourcepath);
  542. presentation.ExportAsFixedFormat(targetPath, Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);
  543. presentation?.Close();
  544. //ppt?.Quit();
  545. break;
  546. }
  547. return targetPath;
  548. }
  549. /// <summary>
  550. /// 转档解锁跳转
  551. /// </summary>
  552. public static void convertUnlock()
  553. {
  554. Process.Start(new ProcessStartInfo(ServiceHelper.WebHost + "/windows/store/master?email=" + Settings.Default.UserDate.Email));
  555. }
  556. /// <summary>
  557. /// 获取OCR枚举
  558. /// </summary>
  559. /// <returns></returns>
  560. public static COCRLanguage GetCOCRLanguage()
  561. {
  562. try
  563. {
  564. string languageName = CommonHelper.LanguageName(App.CultureLanguage);
  565. string enumString = "COCRLanguage" + languageName; // 要转换的字符串
  566. COCRLanguage enumValue; // 目标枚举类型变量
  567. bool success = Enum.TryParse(enumString, out enumValue);
  568. if (success)
  569. {
  570. return enumValue;
  571. }
  572. else
  573. {
  574. return COCRLanguage.COCRLanguageEnglish;
  575. }
  576. }
  577. catch
  578. {
  579. return COCRLanguage.COCRLanguageEnglish;
  580. }
  581. }
  582. /// <summary>
  583. /// 将OCR语言枚举转为int
  584. /// </summary>
  585. /// <returns></returns>
  586. public static int GetCOCRLanguageInt() {
  587. if ((int)ConverterHelper.GetCOCRLanguage() <= 4)
  588. {
  589. return (int)ConverterHelper.GetCOCRLanguage();
  590. }
  591. else
  592. {
  593. return 2;
  594. }
  595. }
  596. }
  597. }