MergeDialogViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKitViewer.PdfViewer;
  4. using Dropbox.Api.TeamLog;
  5. using Microsoft.Office.Interop.Word;
  6. using Microsoft.Win32;
  7. using PDF_Master.CustomControl;
  8. using PDF_Master.EventAggregators;
  9. using PDF_Master.Helper;
  10. using PDF_Master.Model;
  11. using PDF_Master.Model.Dialog.ToolsDialogs;
  12. using PDF_Master.Properties;
  13. using PDF_Master.Views.Dialog;
  14. using Prism.Commands;
  15. using Prism.Events;
  16. using Prism.Mvvm;
  17. using Prism.Services.Dialogs;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Collections.ObjectModel;
  21. using System.IO;
  22. using System.Linq;
  23. using System.Reflection;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. using System.Windows;
  27. using System.Windows.Controls;
  28. using System.Windows.Media;
  29. using System.Windows.Media.Imaging;
  30. using static Dropbox.Api.TeamLog.PaperDownloadFormat;
  31. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  32. namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
  33. {
  34. class MergeDialogViewModel : BindableBase, IDialogAware
  35. {
  36. // Fix:存储当前程序加载的文档的路径和tag,
  37. //如果路径相同则用tag里的密码解锁,
  38. //解锁失败再另行提权
  39. private string CurrentFilePath = string.Empty;
  40. private string currentLoadedPassword = string.Empty;
  41. private IEventAggregator eventAggregator;
  42. enum PageSizeType
  43. {
  44. kDefault = 0,
  45. A4 = 1,
  46. A3 = 2,
  47. Letter = 3,
  48. Legal = 4,
  49. Customized = 5,
  50. }
  51. #region 框架内容
  52. public string Title => "";
  53. public event Action<IDialogResult> RequestClose;
  54. public bool CanCloseDialog()
  55. {
  56. return true;
  57. }
  58. public void OnDialogClosed()
  59. {
  60. }
  61. public void OnDialogOpened(IDialogParameters parameters)
  62. {
  63. CPDFViewer pdfViewer = null;
  64. if (parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer) && pdfViewer != null && pdfViewer.Document != null)
  65. {
  66. VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(pdfViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  67. if (condition.IsDiscryptied)
  68. {
  69. if (!string.IsNullOrEmpty(condition.Password))
  70. {
  71. if (pdfViewer.Document.UnlockWithPassword(condition.Password))
  72. {
  73. pdfViewer.Document.CheckOwnerPassword(condition.Password);
  74. }
  75. }
  76. string unicode;
  77. if (parameters.TryGetValue<string>(ParameterNames.Unicode, out unicode))
  78. {
  79. this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
  80. }
  81. }
  82. currentLoadedPassword = pdfViewer.Document.Password;
  83. }
  84. if (pdfViewer != null && pdfViewer.Document != null)
  85. {
  86. CurrentFilePath = pdfViewer.Document.FilePath;
  87. List<string> list = new List<string>();
  88. list.Add(CurrentFilePath);
  89. AddFiles(list.ToArray());
  90. }
  91. string[] Paths;
  92. parameters.TryGetValue<string[]>(ParameterNames.FilePath, out Paths);
  93. if (Paths != null)
  94. {
  95. AddFiles(Paths);
  96. }
  97. }
  98. #endregion
  99. #region 定义与初始化
  100. public ObservableCollection<MergeObject> MergeObjectlist { get; set; }
  101. public DelegateCommand CancelCommand { get; set; }
  102. public DelegateCommand<object> PreviewCancelDownCommand { get; set; }
  103. public DelegateCommand MergeCommand { get; set; }
  104. public DelegateCommand<object> AddFilesCommand { get; set; }
  105. public DelegateCommand ClearCommand { get; set; }
  106. public DelegateCommand<object> SetPageSizeTypeCommand { get; set; }
  107. public IDialogService dialogs;
  108. private PageSizeType pageSizeType = PageSizeType.kDefault;
  109. private string inputWidth;
  110. public string InputWidth
  111. {
  112. get { return inputWidth; }
  113. set
  114. {
  115. SetProperty(ref inputWidth, value);
  116. }
  117. }
  118. private string inputHeight;
  119. public string InputHeight
  120. {
  121. get { return inputHeight; }
  122. set
  123. {
  124. SetProperty(ref inputHeight, value);
  125. }
  126. }
  127. private int comboBoxSelectedIndex = 0;
  128. public int ComboBoxSelectedIndex
  129. {
  130. get { return comboBoxSelectedIndex; }
  131. set
  132. {
  133. SetProperty(ref comboBoxSelectedIndex, value);
  134. }
  135. }
  136. public MergeDialogViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
  137. {
  138. this.eventAggregator = eventAggregator;
  139. dialogs = dialogService;
  140. MergeObjectlist = new ObservableCollection<MergeObject>();
  141. CancelCommand = new DelegateCommand(Cancel);
  142. PreviewCancelDownCommand = new DelegateCommand<object>(PreviewCancelDown);
  143. AddFilesCommand = new DelegateCommand<object>(ButtonAddFiles);
  144. MergeCommand = new DelegateCommand(Merge);
  145. ClearCommand = new DelegateCommand(Clear);
  146. SetPageSizeTypeCommand = new DelegateCommand<object>(SetPageSizeType);
  147. }
  148. #endregion
  149. #region 私有方法
  150. private void UpDataMergeObjectIndex()
  151. {
  152. for (int i = 0; i < MergeObjectlist.Count; i++)
  153. {
  154. MergeObjectlist[i].ItemIndex = i + 1;
  155. }
  156. }
  157. private void Cancel()
  158. {
  159. Clear();
  160. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  161. }
  162. /// <summary>
  163. /// 点击取消页面范围控件使失去焦点不生效
  164. /// </summary>
  165. private void PreviewCancelDown(object e)
  166. {
  167. var listView = e as ListView;
  168. if (listView != null)
  169. {
  170. if (listView.ItemsSource != null)
  171. {
  172. foreach (var item in listView.ItemsSource)
  173. {
  174. var pagerange= listView.ItemContainerGenerator.ContainerFromItem(item) as ListViewItem;
  175. if (pagerange != null)
  176. {
  177. var pagerangecombobox= CommonHelper.FindVisualChild<WritableComboBox>(pagerange);
  178. if(pagerangecombobox!=null)
  179. pagerangecombobox.IsloseFocus = false;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. public void ButtonAddFiles(object data)
  186. {
  187. int index = Convert.ToInt32(data);
  188. switch (index)
  189. {
  190. case 0:
  191. //打开文件
  192. ComboBoxSelectedIndex = 0;//打开文件弹窗会影响UI更新,所以手动更新
  193. AddFiles(OpenFile());
  194. break;
  195. case 1:
  196. //打开文件夹
  197. ComboBoxSelectedIndex = 1;//打开文件夹弹窗会影响UI更新,所以手动更新
  198. AddFiles(OpenFileFolder());
  199. break;
  200. case 2:
  201. //打开当前文件
  202. List<string> list = new List<string>();
  203. for (int i = 0; i < App.OpenedFileList.Count; i++)
  204. {
  205. list.Add(App.OpenedFileList[i]);
  206. }
  207. AddFiles(list.ToArray());
  208. break;
  209. default:
  210. break;
  211. }
  212. }
  213. private string[] OpenFileFolder()
  214. {
  215. System.Windows.Forms.FolderBrowserDialog openFile = new System.Windows.Forms.FolderBrowserDialog();
  216. if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
  217. {
  218. return null;
  219. }
  220. DirectoryInfo tempfolder = new DirectoryInfo(openFile.SelectedPath);
  221. FileInfo[] fileInfos = tempfolder.GetFiles();
  222. List<string> list = new List<string>();
  223. foreach (FileInfo item in fileInfos)
  224. {
  225. list.Add(item.FullName);
  226. }
  227. DirectoryInfo[] directoryInfos = tempfolder.GetDirectories();
  228. foreach (DirectoryInfo fileInfo in directoryInfos)
  229. {
  230. FileInfo[] fileinfo = fileInfo.GetFiles();
  231. foreach (FileInfo item in fileinfo)
  232. {
  233. list.Add(item.FullName);
  234. }
  235. }
  236. return list.ToArray();
  237. }
  238. private string[] OpenFile()
  239. {
  240. OpenFileDialog openFile = new OpenFileDialog();
  241. openFile.Multiselect = true;
  242. openFile.Filter = Properties.Resources.imageex.ToLower() + "|*";
  243. if (openFile.ShowDialog() == false)
  244. {
  245. return null;
  246. }
  247. return openFile.FileNames;
  248. }
  249. private void Merge()
  250. {
  251. bool result = true;
  252. CPDFDocument SaveDoc = CPDFDocument.CreateDocument();
  253. for (int i = 0; i < MergeObjectlist.Count; i++)
  254. {
  255. List<int> listnum = new List<int>();
  256. if (MergeObjectlist[i].SetPageRange == null || MergeObjectlist[i].SetPageRange.Count == 0)
  257. {
  258. AlertsMessage alertsMessage = new AlertsMessage();
  259. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  260. return;
  261. }
  262. }
  263. for (int i = 0; i < MergeObjectlist.Count; i++)
  264. {
  265. List<int> listnum = new List<int>();
  266. if (MergeObjectlist[i].SetPageRange == null || MergeObjectlist[i].SetPageRange.Count == 0)
  267. {
  268. AlertsMessage alertsMessage = new AlertsMessage();
  269. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  270. return;
  271. }
  272. }
  273. for (int i = 0; i < MergeObjectlist.Count; i++)
  274. {
  275. if (MergeObjectlist[i].SetPageRange == null)
  276. {
  277. AlertsMessage alertsMessage = new AlertsMessage();
  278. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("PageRangeWarning"), App.ServiceLoader.GetString("Text_ok"));
  279. }
  280. //图片
  281. if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() != ".pdf")
  282. {
  283. if (Path.GetExtension(MergeObjectlist[i].FilePath).Trim().ToLower() == ".gif")
  284. {//GIF下面方法产生虚影改成与图片转PDF一致
  285. System.Drawing.Image img = System.Drawing.Image.FromFile(MergeObjectlist[i].FilePath);
  286. string tempFileName = Path.GetTempPath() + "pngtemp.jpg";
  287. if (!PictureConverter.SaveJpeg(MergeObjectlist[i].FilePath, tempFileName))
  288. {
  289. MessageBoxEx.Show("图片格式有问题");
  290. }
  291. // 之前插入位置为零点导致插入为第一页,改为尾插 2023/5/24
  292. result = SaveDoc.InsertPage(SaveDoc.PageCount, img.Width, img.Height, tempFileName);
  293. try { if (File.Exists(tempFileName)) File.Delete(tempFileName); }
  294. catch
  295. { }
  296. if (!result)
  297. {
  298. SaveDoc.Release();
  299. return;
  300. }
  301. continue;
  302. }
  303. else
  304. {
  305. BitmapSource frame = MergeObjectlist[i].DocThumbnail;
  306. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  307. if (frame.Format != PixelFormats.Bgra32)
  308. {
  309. FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
  310. covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  311. }
  312. else
  313. {
  314. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  315. }
  316. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  317. // 之前插入位置为零点导致插入为第一页,改为尾插 2023/5/24
  318. result = SaveDoc.InsertPage(SaveDoc.PageCount, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  319. if (!result)
  320. {
  321. SaveDoc.Release();
  322. return;
  323. }
  324. continue;
  325. }
  326. }
  327. else
  328. {
  329. CPDFDocument tempDoc = CPDFDocument.InitWithFilePath(MergeObjectlist[i].FilePath);
  330. if (!string.IsNullOrEmpty(MergeObjectlist[i].Password))
  331. {
  332. tempDoc.UnlockWithPassword(MergeObjectlist[i].Password);
  333. }
  334. if (!string.IsNullOrEmpty(MergeObjectlist[i].SetPageRangeStr))
  335. {
  336. result = SaveDoc.ImportPages(tempDoc, MergeObjectlist[i].SetPageRangeStr);
  337. }
  338. else
  339. {
  340. //下拉框控件传出来的list是页面索引集合,
  341. //此处传给SDK的合并接口的是页码集合,因此需要将集合项遍历+1,只有合并接口是接收页码集合,其余接口是接受页面索引集合
  342. List<int> pageIndexs = new List<int>();
  343. for (int j = 0; j < MergeObjectlist[i].SetPageRange.Count; j++)
  344. {
  345. pageIndexs.Add(MergeObjectlist[i].SetPageRange[j] + 1);
  346. }
  347. result = SaveDoc.ImportPages(tempDoc, CommonHelper.GetPageParmFromList(pageIndexs));
  348. }
  349. if (!result)
  350. {
  351. SaveDoc.Release();
  352. tempDoc.Release();
  353. return;
  354. }
  355. tempDoc.Release();
  356. }
  357. }
  358. SaveFileDialog saveFileDialog = new SaveFileDialog();
  359. saveFileDialog.FileName = "Untitle";
  360. saveFileDialog.Filter = "PDF|*.pdf;";
  361. if (saveFileDialog.ShowDialog() == false)
  362. {
  363. return;
  364. }
  365. string path = saveFileDialog.FileName;
  366. System.Windows.Rect rect = new System.Windows.Rect();
  367. switch (pageSizeType)
  368. {
  369. case PageSizeType.kDefault:
  370. break;
  371. case PageSizeType.A4:
  372. rect.Width = CommonHelper.GetPageSizeFomrUnit(210);
  373. rect.Height = CommonHelper.GetPageSizeFomrUnit(297);
  374. break;
  375. case PageSizeType.A3:
  376. rect.Width = CommonHelper.GetPageSizeFomrUnit(297);
  377. rect.Height = CommonHelper.GetPageSizeFomrUnit(420);
  378. break;
  379. case PageSizeType.Letter:
  380. rect.Width = CommonHelper.GetPageSizeFomrUnit(216);
  381. rect.Height = CommonHelper.GetPageSizeFomrUnit(279);
  382. break;
  383. case PageSizeType.Legal:
  384. rect.Width = CommonHelper.GetPageSizeFomrUnit(216);
  385. rect.Height = CommonHelper.GetPageSizeFomrUnit(356);
  386. break;
  387. case PageSizeType.Customized:
  388. if (!string.IsNullOrEmpty(InputWidth) && !string.IsNullOrEmpty(InputHeight))
  389. {
  390. rect.Width = CommonHelper.GetPageSizeFomrUnit(Convert.ToInt32(InputWidth));
  391. rect.Height = CommonHelper.GetPageSizeFomrUnit(Convert.ToInt32(InputHeight));
  392. }
  393. else
  394. {
  395. rect.Width = CommonHelper.GetPageSizeFomrUnit(595);
  396. rect.Height = CommonHelper.GetPageSizeFomrUnit(841);
  397. }
  398. break;
  399. default:
  400. break;
  401. }
  402. if (rect.Width > 0 && rect.Height > 0)
  403. {
  404. //裁剪
  405. for (int i = 0; i < SaveDoc.PageCount; i++)
  406. {
  407. CPDFPage page = SaveDoc.PageAtIndex(i);
  408. page.CropPage(CPDFDisplayBox.MediaBox, rect);
  409. }
  410. }
  411. bool saveResult = SaveDoc.WriteToFilePath(path);
  412. SaveDoc.Release();
  413. CommonHelper.ShowFileBrowser(path);
  414. DialogParameters valuePairs = new DialogParameters();
  415. valuePairs.Add(ParameterNames.FilePath, path);
  416. RequestClose.Invoke(new DialogResult(ButtonResult.OK, valuePairs));
  417. }
  418. private void Clear()
  419. {
  420. MergeObjectlist.Clear();
  421. }
  422. private void SetPageSizeType(object button)
  423. {
  424. if (button is RadioButton)
  425. {
  426. pageSizeType = (PageSizeType)Convert.ToInt32((button as RadioButton).Tag);
  427. }
  428. }
  429. #endregion
  430. #region 公开方法
  431. public void DeleteItem(MergeObject merge)
  432. {
  433. MergeObjectlist.Remove(merge);
  434. UpDataMergeObjectIndex();
  435. }
  436. /// <summary>
  437. /// 拖拽插入
  438. /// </summary>
  439. public void MoveMerge(MergeObject targetNode, MergeObject soureNode)
  440. {
  441. int targetindex = MergeObjectlist.IndexOf(targetNode);
  442. MergeObjectlist.Remove(soureNode);
  443. if (targetNode.IsForward)
  444. {
  445. if (targetindex + 1 < MergeObjectlist.Count)
  446. {
  447. MergeObjectlist.Insert(targetindex + 1, soureNode);
  448. }
  449. else
  450. {
  451. MergeObjectlist.Add(soureNode);
  452. }
  453. }
  454. else
  455. {
  456. MergeObjectlist.Insert(targetindex, soureNode);
  457. }
  458. UpDataMergeObjectIndex();
  459. }
  460. public void AddFiles(string[] FilePath)
  461. {
  462. if (FilePath == null)
  463. {
  464. return;
  465. }
  466. bool showDialog = false;
  467. for (int i = 0; i < FilePath.Length; i++)
  468. {
  469. MergeObject mergeObject = new MergeObject();
  470. mergeObject.FilePath = FilePath[i];
  471. //通过路径判断文件是否已添加
  472. bool IsExists = false;
  473. for (int j = 0; j < MergeObjectlist.Count; j++)
  474. {
  475. if (MergeObjectlist[j].FilePath == mergeObject.FilePath)
  476. {
  477. IsExists = true;
  478. }
  479. }
  480. if (IsExists)
  481. {
  482. continue;
  483. }
  484. string FileType = Path.GetExtension(mergeObject.FilePath).Trim().ToLower();
  485. if (string.IsNullOrEmpty(FileType))
  486. {
  487. showDialog = true;
  488. //获取不到文件类型
  489. continue;
  490. }
  491. if (FileType != ".pdf")
  492. {
  493. string imagetype = "*" + FileType;
  494. string[] x = Properties.Resources.imageex.ToLower().Split(';');
  495. List<string> list = x.ToList();
  496. int imageindex = list.IndexOf(imagetype);
  497. if (imageindex < 0)
  498. {
  499. showDialog = true;
  500. //图片格式不支持
  501. continue;
  502. };
  503. mergeObject.DocName = Path.GetFileName(mergeObject.FilePath);
  504. mergeObject.DocPageCount = 1 + " " + App.MainPageLoader.GetString("Merge_ItemPages");
  505. mergeObject.SDKPageCount = 1;
  506. mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
  507. try
  508. {
  509. mergeObject.DocThumbnail = new BitmapImage(new Uri(mergeObject.FilePath));
  510. }
  511. catch (Exception)
  512. {
  513. showDialog = true;
  514. //解码错误
  515. continue;
  516. }
  517. }
  518. else
  519. {
  520. CPDFDocument doc = CPDFDocument.InitWithFilePath(mergeObject.FilePath);
  521. if (doc == null)
  522. {
  523. showDialog = true;
  524. //PDF打开失败
  525. continue;
  526. }
  527. ///Fix:
  528. ///情况分为:
  529. ///开启路径是当前路径:
  530. ///已解锁或本身就无密码->直接加入
  531. ///未解锁-> release
  532. ///
  533. /// 不是当前路径
  534. ///解锁或取消->
  535. ///
  536. if (CurrentFilePath == doc.FilePath)
  537. {
  538. if ((!(!doc.IsLocked && (SecurityHelper.CheckHaveAllPermissions(doc)))) &&
  539. (!(!string.IsNullOrEmpty(currentLoadedPassword) &&
  540. doc.UnlockWithPassword(currentLoadedPassword) &&
  541. (doc.CheckOwnerPassword(currentLoadedPassword) || SecurityHelper.CheckHaveAllPermissions(doc)))))
  542. {
  543. doc.Release();
  544. continue;
  545. }
  546. //添加的第一个文档有权限密码时,保存密码,避免合并时因没有密码导致合并失败
  547. //表现为在首页打开一个带权限的文档进入合并,点击合并按钮没有反应
  548. if (!string.IsNullOrEmpty(currentLoadedPassword))
  549. {
  550. mergeObject.Password = currentLoadedPassword;
  551. }
  552. }
  553. else
  554. {
  555. VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  556. if (condition.IsDiscryptied)
  557. {
  558. if (condition.Password != null)
  559. {
  560. mergeObject.Password = condition.Password;
  561. if (doc.UnlockWithPassword(condition.Password) && doc.CheckOwnerPassword(condition.Password))
  562. {
  563. }
  564. }
  565. }
  566. else
  567. {
  568. doc.Release();
  569. continue;
  570. }
  571. }
  572. mergeObject.DocName = doc.FileName;
  573. mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
  574. if (doc.PageCount > 1)
  575. {
  576. mergeObject.IsEvenPageIsEnabled = true;
  577. }
  578. else
  579. {
  580. mergeObject.IsEvenPageIsEnabled = false;
  581. }
  582. mergeObject.SDKPageCount = doc.PageCount;
  583. mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
  584. //获取第一页缩略图
  585. CPDFPage page = doc.PageAtIndex(0);
  586. Size size = doc.GetPageSize(0);
  587. byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
  588. WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
  589. page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
  590. WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
  591. WirteBitmap.Freeze();
  592. mergeObject.DocThumbnail = WirteBitmap;
  593. doc.Release();
  594. }
  595. MergeObjectlist.Add(mergeObject);
  596. UpDataMergeObjectIndex();
  597. }
  598. if (showDialog)
  599. {
  600. AlertsMessage alertsMessage = new AlertsMessage();
  601. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("ErrorFile_Warning"), App.ServiceLoader.GetString("Text_ok"));
  602. if (alertsMessage.result == ContentResult.Ok)
  603. {
  604. }
  605. }
  606. }
  607. #endregion
  608. }
  609. }