HomePagePictureToPDFDialogViewModel.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. using PDF_Office.Model;
  2. using Prism.Commands;
  3. using System.Data;
  4. using Prism.Mvvm;
  5. using Prism.Services.Dialogs;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Diagnostics;
  12. using PDF_Office.CustomControl;
  13. using System.Windows;
  14. using PDF_Office.Helper;
  15. using PDF_Office.Model.Dialog.HomePageToolsDialogs;
  16. using ComPDFKit.PDFDocument;
  17. using System.Drawing;
  18. using DialogResult = Prism.Services.Dialogs.DialogResult;
  19. namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
  20. {
  21. public class HomePagePictureToPDFDialogViewModel : BindableBase, IDialogAware
  22. {
  23. #region 参数和属性
  24. private List<string> fileNames;
  25. private int fileNamesIndex = 0;
  26. private int FileNameNumber = 0;
  27. public IDialogService dialogs;
  28. public List<int> fileNamesView = new List<int>();
  29. public HomePagePictureToPDFDialogModel pictureToPDFModel=new HomePagePictureToPDFDialogModel();
  30. private string pictureToPDFGridIsEnabled = "True";
  31. public string PictureToPDFGridIsEnabled
  32. {
  33. get
  34. {
  35. return pictureToPDFGridIsEnabled;
  36. }
  37. set
  38. {
  39. SetProperty(ref pictureToPDFGridIsEnabled, value);
  40. }
  41. }
  42. private string setPictureToPDFGridIsEnabled = "True";
  43. public string SetPictureToPDFGridIsEnabled
  44. {
  45. get
  46. {
  47. return setPictureToPDFGridIsEnabled;
  48. }
  49. set
  50. {
  51. SetProperty(ref setPictureToPDFGridIsEnabled, value);
  52. }
  53. }
  54. private DataTable imagesDataTable = new DataTable();
  55. public DataTable ImagesDataTable
  56. {
  57. get { return imagesDataTable; }
  58. set
  59. {
  60. SetProperty(ref imagesDataTable, value);
  61. }
  62. }
  63. private DataTable imagesCurrentDataTable = new DataTable();
  64. public DataTable ImagesCurrentDataTable
  65. {
  66. get { return imagesCurrentDataTable; }
  67. set
  68. {
  69. SetProperty(ref imagesCurrentDataTable, value);
  70. }
  71. }
  72. private string removeIsEnable = "True";
  73. public string RemoveIsEnable
  74. {
  75. get { return removeIsEnable; }
  76. set
  77. {
  78. SetProperty(ref removeIsEnable, value);
  79. }
  80. }
  81. private string imageToPDFBtnIsEnable = "True";
  82. public string ImageToPDFBtnIsEnable
  83. {
  84. get { return imageToPDFBtnIsEnable; }
  85. set
  86. {
  87. SetProperty(ref imageToPDFBtnIsEnable, value);
  88. }
  89. }
  90. private string selectFileName = "File";
  91. public string SelectFileName
  92. {
  93. get { return selectFileName; }
  94. set
  95. {
  96. SetProperty(ref selectFileName, value);
  97. }
  98. }
  99. private Visibility addFileVisibility = Visibility.Hidden;
  100. public Visibility AddFileVisibility
  101. {
  102. get { return addFileVisibility; }
  103. set
  104. {
  105. SetProperty(ref addFileVisibility, value);
  106. RaisePropertyChanged();
  107. }
  108. }
  109. #endregion
  110. #region 委托声明
  111. public DelegateCommand ToPDFCommand { get; set; }
  112. public DelegateCommand ADDPictureCommand { get; set; }
  113. public DelegateCommand ADDPictureFilesCommand { get; set; }
  114. public DelegateCommand RemovePictureFileCommand { get; set; }
  115. public DelegateCommand SelectFileCommand { get; set; }
  116. #endregion
  117. public HomePagePictureToPDFDialogViewModel(IDialogService dialogs)
  118. {
  119. this.dialogs = dialogs;
  120. ToPDFCommand = new DelegateCommand(topdf);
  121. ADDPictureCommand = new DelegateCommand(addpicture);
  122. ADDPictureFilesCommand = new DelegateCommand(addpicturefiles);
  123. RemovePictureFileCommand = new DelegateCommand(removepicturefiles);
  124. SelectFileCommand = new DelegateCommand(selectFile);
  125. ImagesDataTable.Columns.Add("FileName");
  126. ImagesDataTable.Columns.Add("FileSize");
  127. ImagesDataTable.Columns.Add("FileState");
  128. ImagesCurrentDataTable.Columns.Add("FileState");
  129. this.dialogs = dialogs;
  130. }
  131. #region 逻辑函数
  132. private void topdf() {
  133. PictureToPDFGridIsEnabled = "False";
  134. if (pictureToPDFModel.Mode == HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles)
  135. {
  136. FolderBrowserDialog dlg = new FolderBrowserDialog();
  137. string saveSelectedPath = "";
  138. string SaveSelectedPath = "";
  139. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  140. {
  141. SaveSelectedPath = dlg.SelectedPath.Trim();
  142. saveSelectedPath = saveSelectedPath + "\\";
  143. }
  144. else { PictureToPDFGridIsEnabled = "True"; return; }
  145. fileNamesIndex = 0;
  146. string fileName = "";
  147. foreach (var filename in fileNames)
  148. {
  149. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  150. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  151. Image img = Image.FromFile(filename);
  152. if (img == null)
  153. {
  154. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  155. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  156. continue;
  157. }
  158. CPDFDocument topdfdoc = CPDFDocument.CreateDocument();
  159. FileInfo fileinfo = new FileInfo(filename);
  160. JpegInsertPage(ref topdfdoc, filename, fileinfo,img.Width,img.Height);
  161. Trace.WriteLine("Path.GetTempPath():" + Path.GetTempPath());
  162. fileName = savefilename(filename,saveSelectedPath);
  163. topdfdoc.WriteToFilePath(fileName);
  164. topdfdoc.Release();
  165. string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
  166. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  167. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  168. fileNamesIndex++;
  169. //System.Diagnostics.Process.Start("Explorer", "/select," + fileName);
  170. }
  171. System.Diagnostics.Process.Start("Explorer", "/select," + fileName);
  172. }
  173. if (pictureToPDFModel.Mode == HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile)
  174. {
  175. CPDFDocument topdfdoc = CPDFDocument.CreateDocument();
  176. int pageindex = 0;
  177. FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  178. System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
  179. sfd.FileName = "Untitle";
  180. sfd.Filter = "PDF|*.pdf;";
  181. string NewFileName = "";
  182. if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  183. {
  184. NewFileName=sfd.FileName;
  185. }
  186. else { PictureToPDFGridIsEnabled = "True"; return; }
  187. foreach (var filename in fileNames) {
  188. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  189. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  190. Image img = Image.FromFile(filename);
  191. if (img == null)
  192. {
  193. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  194. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  195. continue;
  196. }
  197. FileInfo fileinfo = new FileInfo(filename);
  198. JpegInsertPage(ref topdfdoc, filename, fileinfo,img.Width, img.Height, pageindex);
  199. pageindex++;
  200. string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
  201. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  202. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  203. fileNamesIndex++;
  204. }
  205. System.Diagnostics.Process.Start("Explorer", "/select," + NewFileName);
  206. topdfdoc.WriteToFilePath(CommonHelper.CreateFilePath(NewFileName));
  207. topdfdoc.Release();
  208. }
  209. if (pictureToPDFModel.Mode == HomePagePictureToPDFDialogModel.ToPDFFileMode.SelectFileName)
  210. {
  211. FolderBrowserDialog dlg = new FolderBrowserDialog();
  212. string saveSelectedPath = "";
  213. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  214. {
  215. saveSelectedPath = dlg.SelectedPath.Trim();
  216. saveSelectedPath = saveSelectedPath + "\\";
  217. }
  218. else {PictureToPDFGridIsEnabled = "True"; return; }
  219. CPDFDocument topdfdoc = CPDFDocument.InitWithFilePath(pictureToPDFModel.FilePath);
  220. if (topdfdoc == null)
  221. {
  222. Trace.WriteLine("Document==null");
  223. //TODO
  224. MessageBoxEx.Show("文档为空");
  225. PictureToPDFGridIsEnabled = "True";
  226. return;
  227. }
  228. if (topdfdoc.IsLocked)
  229. {
  230. DialogParameters value = new DialogParameters();
  231. value.Add(ParameterNames.PDFDocument, topdfdoc);
  232. dialogs.ShowDialog(DialogNames.VerifyPassWordDialog, value, e =>
  233. {
  234. if (e.Result == ButtonResult.OK)
  235. {
  236. if (e.Parameters.ContainsKey(ParameterNames.PassWord) && e.Parameters.GetValue<string>(ParameterNames.PassWord) != null)
  237. {
  238. topdfdoc.UnlockWithPassword(e.Parameters.GetValue<string>(ParameterNames.PassWord).ToString());
  239. }
  240. }
  241. });
  242. if (topdfdoc.IsLocked)
  243. {
  244. //未成功解密文档时,释放Document对象,返回
  245. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  246. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  247. fileNamesIndex++;
  248. PictureToPDFGridIsEnabled = "True";
  249. return;
  250. }
  251. }
  252. int pageindex = topdfdoc.PageCount;
  253. foreach (var filename in fileNames)
  254. {
  255. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  256. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
  257. Image img = Image.FromFile(filename);
  258. if (img == null)
  259. {
  260. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  261. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "error";
  262. continue;
  263. }
  264. FileInfo fileinfo = new FileInfo(filename);
  265. JpegInsertPage(ref topdfdoc, filename, fileinfo, img.Width, img.Height, pageindex);
  266. pageindex++;
  267. string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
  268. ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  269. ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
  270. fileNamesIndex++;
  271. }
  272. string saveselectedpath = CommonHelper.CreateFilePath(saveSelectedPath + topdfdoc.FileName+".pdf");
  273. topdfdoc.WriteToFilePath(saveselectedpath);
  274. System.Diagnostics.Process.Start("Explorer", "/select," + saveselectedpath);
  275. topdfdoc.Release();
  276. }
  277. PictureToPDFGridIsEnabled = "True";
  278. fileNamesIndex=0;
  279. }
  280. /// <summary>
  281. /// 设置保存后的文件名
  282. /// </summary>
  283. public string savefilename(string filename,string filepath)
  284. {
  285. FileInfo file = new FileInfo(filename);
  286. return CommonHelper.CreateFilePath(filepath + pictureToPDFModel.FrontFileNameLabel + file.Name.Replace(file.Extension,".pdf") + pictureToPDFModel.RearFileNameLabel);
  287. }
  288. #endregion
  289. #region 批量处理逻辑函数
  290. /// <summary>
  291. /// 选择PDF文件
  292. /// </summary>
  293. private void selectFile()
  294. {
  295. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  296. dlg.Multiselect = false;
  297. dlg.Filter = "PDF|*.pdf;*.PDF;";
  298. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  299. {
  300. SelectFileName=dlg.FileName;
  301. pictureToPDFModel.FilePath = dlg.FileName;
  302. ImageToPDFBtnIsEnable = "True";
  303. }
  304. }
  305. /// <summary>
  306. /// 添加图片文件
  307. /// </summary>
  308. private void addpicture()
  309. {
  310. FileNameNumber = fileNames.Count;
  311. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  312. dlg.Multiselect = true;
  313. dlg.Filter = "Picture|*.png;*.PNG;*.jpg;*.JPG;*.bmp;*.gif;*tiff;";
  314. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  315. {
  316. fileNames.AddRange(dlg.FileNames.ToList());
  317. RemoveExcess(ref fileNames);
  318. SetPictureToPDFGridIsEnabled = "True";
  319. AddFileVisibility = Visibility.Hidden;
  320. RemoveIsEnable = "True";
  321. updateListview("wait");
  322. }
  323. }
  324. public void addPicture(string filename)
  325. {
  326. FileNameNumber = fileNames.Count;
  327. fileNames.Add(filename);
  328. RemoveExcess(ref fileNames);
  329. SetPictureToPDFGridIsEnabled = "True";
  330. AddFileVisibility = Visibility.Hidden;
  331. RemoveIsEnable = "True";
  332. updateListview("wait");
  333. }
  334. /// <summary>
  335. /// 添加图片文件夹
  336. /// </summary>
  337. private void addpicturefiles()
  338. {
  339. FileNameNumber = fileNames.Count;
  340. FolderBrowserDialog dialog = new FolderBrowserDialog();
  341. dialog.Description = "请选择文件路径";
  342. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  343. {
  344. string foldPath = dialog.SelectedPath;
  345. var apps = System.IO.Directory.GetFiles(foldPath);
  346. foreach (string app in apps)
  347. {
  348. var fi = new FileInfo(app);
  349. if (fi.Extension == ".png" || fi.Extension == ".jpg" || fi.Extension == ".jpeg" || fi.Extension ==".bmp"|| fi.Extension == ".gif"|| fi.Extension == ".tiff")
  350. {
  351. fileNames.Add(app);
  352. }
  353. }
  354. RemoveExcess(ref fileNames);
  355. updateListview("wait");
  356. SetPictureToPDFGridIsEnabled = "True";
  357. AddFileVisibility = Visibility.Hidden;
  358. RemoveIsEnable = "True";
  359. }
  360. }
  361. /// <summary>
  362. /// 删除图片文件
  363. /// </summary>
  364. ///
  365. public void removepicturefiles()
  366. {
  367. FileNameNumber = fileNames.Count;
  368. //Trace.WriteLine(filenamesview);
  369. fileNames.Clear();
  370. if (fileNames.Count < 1)
  371. {
  372. SetPictureToPDFGridIsEnabled = "False";
  373. AddFileVisibility = Visibility.Visible;
  374. RemoveIsEnable = "False";
  375. }
  376. updateListview("wait");
  377. }
  378. public void removepicturefile() {
  379. FileNameNumber = fileNames.Count;
  380. Reverseorder(ref fileNamesView);
  381. foreach (int filenamesview in fileNamesView)
  382. {
  383. //Trace.WriteLine(filenamesview);
  384. fileNames.Remove(fileNames[filenamesview]);
  385. }
  386. if (fileNames.Count < 1)
  387. {
  388. SetPictureToPDFGridIsEnabled = "False";
  389. AddFileVisibility = Visibility.Visible;
  390. RemoveIsEnable = "False";
  391. }
  392. updateListview("wait");
  393. }
  394. public void removepdffile(int index)
  395. {
  396. ImagesCurrentDataTable.Rows.RemoveAt(index);
  397. fileNames.Remove(fileNames[index]);
  398. if (fileNames.Count < 1)
  399. {
  400. SetPictureToPDFGridIsEnabled = "False";
  401. AddFileVisibility = Visibility.Visible;
  402. RemoveIsEnable = "False";
  403. }
  404. updateListview("wait");
  405. }
  406. /// <summary>
  407. /// 打开文件图片
  408. /// </summary>
  409. public void openfiledialog(){
  410. foreach (int filenamesview in fileNamesView)
  411. {
  412. System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
  413. }
  414. }
  415. /// <summary>
  416. /// 删除重复的文件
  417. /// </summary>
  418. public void RemoveExcess(ref List<string> Filenames) {
  419. List<string> filenames = new List<string>();
  420. foreach (var fileName in Filenames)
  421. {
  422. if (!filenames.Contains(fileName))
  423. {
  424. filenames.Add(fileName);
  425. }
  426. }
  427. Filenames.Clear();
  428. Filenames = filenames;
  429. }
  430. /// <summary>
  431. /// 逆序int类型集合
  432. /// </summary>
  433. public void Reverseorder(ref List<int> Numbers)
  434. {
  435. Numbers=Numbers.OrderBy(a=>a).ToList();
  436. Numbers.Reverse();
  437. }
  438. /// <summary>
  439. /// 更新listview显示
  440. /// state 状态显示字符串
  441. /// </summary>
  442. public void updateListview(string state) {
  443. updateCurrentListview();
  444. DataTable imagesdatatable = new DataTable();
  445. imagesdatatable.Columns.Add("FileName");
  446. imagesdatatable.Columns.Add("FileSize");
  447. imagesdatatable.Columns.Add("FileState");
  448. int datatableindex = 0;
  449. foreach (var fileName in fileNames)
  450. {
  451. string file_all = fileName;
  452. FileInfo f = new FileInfo(file_all);
  453. string file_size = (((float)f.Length)/1024).ToString()+" K";
  454. imagesdatatable.Rows.Add(f.Name, file_size, ImagesCurrentDataTable.Rows[datatableindex]["FileState"]);
  455. datatableindex++;
  456. }
  457. ImagesDataTable = imagesdatatable;
  458. }
  459. /// <summary>
  460. /// 更新Currentlistview显示
  461. /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
  462. /// </summary>
  463. public void updateCurrentListview( string state = "wait")
  464. {
  465. if (fileNames.Count >= FileNameNumber)
  466. {
  467. for (int i = 0; fileNames.Count - FileNameNumber > i; i++)
  468. {
  469. ImagesCurrentDataTable.Rows.Add(state);
  470. }
  471. }
  472. else
  473. {
  474. Reverseorder(ref fileNamesView);
  475. foreach (int filenamesview in fileNamesView)
  476. {
  477. ImagesCurrentDataTable.Rows.RemoveAt(filenamesview);
  478. }
  479. }
  480. }
  481. #endregion
  482. #region 图片转换
  483. /// <summary>
  484. /// 图片转PNG
  485. /// picturefile 图片文件名
  486. /// filePath 保存路径
  487. /// </summary>
  488. public bool SavePng(string picturefile, string filePath)
  489. {
  490. Image img = Image.FromFile(picturefile);
  491. try
  492. {
  493. using (var bmp = new Bitmap(img.Width, img.Height))
  494. {
  495. bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
  496. using (var g = Graphics.FromImage(bmp))
  497. {
  498. g.Clear(Color.White);
  499. g.DrawImageUnscaled(img, 0, 0);
  500. }
  501. bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  502. }
  503. return true;
  504. }
  505. catch
  506. {
  507. return false;
  508. }
  509. }
  510. /// <summary>
  511. /// 图片转JPeG
  512. /// picturefile 图片文件名
  513. /// filePath 保存路径
  514. /// </summary>
  515. public bool SaveJpeg(string picturefile, string filePath)
  516. {
  517. Image img = Image.FromFile(picturefile);
  518. try
  519. {
  520. using (var bmp = new Bitmap(img.Width, img.Height))
  521. {
  522. bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
  523. using (var g = Graphics.FromImage(bmp))
  524. {
  525. g.Clear(Color.White);
  526. g.DrawImageUnscaled(img, 0, 0);
  527. }
  528. //存储各种格式
  529. //bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Gif);
  530. //bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  531. bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  532. }
  533. return true;
  534. }
  535. catch
  536. {
  537. return false;
  538. }
  539. }
  540. /// <summary>
  541. /// 插入JPeG图片
  542. /// topdfdoc 所要插入的文档
  543. /// filename 图片文件名
  544. /// fileinfo 文件信息
  545. /// width page宽
  546. /// height page高
  547. /// index 插入位置
  548. /// </summary>
  549. private void JpegInsertPage(ref CPDFDocument topdfdoc,string filename, FileInfo fileinfo,int width,int height,int index=0) {
  550. string tempFileName = "";
  551. if (fileinfo.Extension == ".jpg"|| fileinfo.Extension == ".jpeg")
  552. {
  553. topdfdoc.InsertPage(index, width, height, filename);
  554. }
  555. else
  556. {
  557. tempFileName = Path.GetTempPath() + "pngtemp.jpg";
  558. if (!PictureConverter.SaveJpeg(filename, tempFileName))
  559. {
  560. MessageBoxEx.Show("图片格式有问题");
  561. }
  562. topdfdoc.InsertPage(index, width, height, tempFileName);
  563. }
  564. }
  565. #endregion
  566. #region 构架行为
  567. public string Title => "图片转PDF";
  568. public event Action<IDialogResult> RequestClose;
  569. public bool CanCloseDialog()
  570. {
  571. return true;
  572. }
  573. public void OnDialogClosed()
  574. {
  575. }
  576. public void OnDialogOpened(IDialogParameters parameters)
  577. {
  578. string[] filepath=null;
  579. parameters.TryGetValue<string[]>(ParameterNames.FilePath, out filepath);
  580. if (filepath!=null)
  581. {
  582. fileNames=filepath.ToList();
  583. updateListview("wait");
  584. }
  585. }
  586. #endregion
  587. }
  588. }