PDFTextEditControl.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using ComPDFKit.Tool;
  5. using ComPDFKit.Tool.SettingParam;
  6. using ComPDFKit.Tool.UndoManger;
  7. using ComPDFKit.Viewer.Helper;
  8. using ComPDFKit.Controls.PDFControl;
  9. using ComPDFKitViewer;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Controls.Primitives;
  15. using System.Windows.Media;
  16. namespace ComPDFKit.Controls.Edit
  17. {
  18. public partial class PDFTextEditControl : UserControl
  19. {
  20. #region Property
  21. public CPDFViewerTool ToolView { get; private set; }
  22. public TextEditParam EditEvent { get; set; }
  23. //public List<PDFEditEvent> EditMultiEvents { get; set; }
  24. #endregion
  25. public PDFTextEditControl()
  26. {
  27. InitializeComponent();
  28. Loaded += PDFTextEditControl_Loaded;
  29. }
  30. #region Init PDFView
  31. public void InitWithPDFViewer(CPDFViewerTool newPDFView)
  32. {
  33. ToolView = newPDFView;
  34. }
  35. #endregion
  36. #region UI
  37. public void SetPDFTextEditData(TextEditParam newEvent)
  38. {
  39. if (newEvent.EditIndex<0)
  40. {
  41. EditEvent = null;
  42. }
  43. else
  44. {
  45. EditEvent = newEvent;
  46. }
  47. if (newEvent != null && newEvent.EditType == CPDFEditType.EditText)
  48. {
  49. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  50. List<string> sysfontList = new List<string>();
  51. if (textArea != null)
  52. {
  53. sysfontList = textArea.GetFontList();
  54. }
  55. if (sysfontList.Count == 0)
  56. {
  57. sysfontList.Add("Helvetica");
  58. sysfontList.Add("Courier New");
  59. sysfontList.Add("Times New Roman");
  60. }
  61. if (sysfontList.Contains(newEvent.FontName) == false && string.IsNullOrEmpty(newEvent.FontName) == false)
  62. {
  63. sysfontList.Add(newEvent.FontName);
  64. }
  65. TextStyleUI.SetFontNames(sysfontList);
  66. TextStyleUI.SelectFontName(newEvent.FontName);
  67. TextStyleUI.SetFontStyle(newEvent.IsBold, newEvent.IsItalic);
  68. TextStyleUI.SetFontSize(newEvent.FontSize);
  69. OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(newEvent.Transparency * 100 / 255D)));
  70. FontOpacitySlider.Value = ((int)(Math.Ceiling(newEvent.Transparency * 100 / 255D))) / 100D;
  71. TextAlignUI.SetFontAlign(newEvent.TextAlign);
  72. if (newEvent.FontColor != null && newEvent.FontColor.Length == 3)
  73. {
  74. FontColorUI.SetCheckedForColor(Color.FromRgb(
  75. newEvent.FontColor[0],
  76. newEvent.FontColor[1],
  77. newEvent.FontColor[2]));
  78. }
  79. }
  80. EditEvent = newEvent;
  81. }
  82. //public void SetPDFTextMultiEditData(List<PDFEditEvent> editEvents)
  83. //{
  84. // EditEvent = null;
  85. // EditMultiEvents = null;
  86. // if(editEvents!=null && editEvents.Count>0)
  87. // {
  88. // PDFEditEvent editEvent= editEvents[0];
  89. // if (editEvent != null && editEvent.EditType == CPDFEditType.EditText)
  90. // {
  91. // if (editEvent.SystemFontNameList != null && editEvent.SystemFontNameList.Count == 0)
  92. // {
  93. // editEvent.SystemFontNameList.Add("Helvetica");
  94. // editEvent.SystemFontNameList.Add("Courier New");
  95. // editEvent.SystemFontNameList.Add("Times New Roman");
  96. // }
  97. // if (editEvent.SystemFontNameList.Contains(editEvent.FontName) == false && string.IsNullOrEmpty(editEvent.FontName) == false)
  98. // {
  99. // editEvent.SystemFontNameList.Add(editEvent.FontName);
  100. // }
  101. // TextStyleUI.SetFontNames(editEvent.SystemFontNameList);
  102. // TextStyleUI.SelectFontName(editEvent.FontName);
  103. // TextStyleUI.SetFontStyle(editEvent.IsBold, editEvent.IsItalic);
  104. // TextStyleUI.SetFontSize(editEvent.FontSize);
  105. // OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(editEvent.Transparency * 100 / 255D)));
  106. // FontOpacitySlider.Value = ((int)(Math.Ceiling(editEvent.Transparency * 100 / 255D))) / 100D;
  107. // TextAlignUI.SetFontAlign(editEvent.TextAlign);
  108. // FontColorUI.SetCheckedForColor(editEvent.FontColor);
  109. // }
  110. // }
  111. // EditMultiEvents=editEvents;
  112. //}
  113. private void SliderOpacity_DragCompleted(object sender, DragCompletedEventArgs e)
  114. {
  115. Slider slider = sender as Slider;
  116. if (slider != null)
  117. {
  118. slider.Tag = "true";
  119. }
  120. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  121. if (textArea != null)
  122. {
  123. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  124. bool result;
  125. if (string.IsNullOrEmpty(textArea.SelectText))
  126. {
  127. string fontName = "Helvetica";
  128. float fontSize = 14;
  129. byte[] fontColor = { 0, 0, 0 };
  130. byte transparency = 255;
  131. bool isBold = false;
  132. bool isItalic = false;
  133. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  134. result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
  135. }
  136. else
  137. {
  138. result = textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
  139. }
  140. if (result)
  141. {
  142. PDFEditHistory editHistory = new PDFEditHistory();
  143. editHistory.EditPage = editPage;
  144. if (pdfPage != null)
  145. {
  146. editHistory.PageIndex = pdfPage.PageIndex;
  147. }
  148. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  149. ToolView.UpdateRender(oldRect, textArea);
  150. editPage.EndEdit();
  151. }
  152. }
  153. if (EditEvent != null && textArea == null)
  154. {
  155. EditEvent.Transparency = (byte)(FontOpacitySlider.Value * 255);
  156. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  157. defaultSettingParam.SetPDFEditParamm(EditEvent);
  158. }
  159. }
  160. private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  161. {
  162. Slider slider = sender as Slider;
  163. if (OpacityTextBox != null && FontOpacitySlider != null)
  164. {
  165. OpacityTextBox.Text = string.Format("{0}%", (int)(FontOpacitySlider.Value * 100));
  166. }
  167. if (slider != null && slider.Tag != null && slider.Tag.ToString() == "false")
  168. {
  169. return;
  170. }
  171. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  172. if (textArea != null)
  173. {
  174. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  175. bool result;
  176. if (string.IsNullOrEmpty(textArea.SelectText))
  177. {
  178. string fontName = "Helvetica";
  179. float fontSize = 14;
  180. byte[] fontColor = { 0, 0, 0 };
  181. byte transparency = 255;
  182. bool isBold = false;
  183. bool isItalic = false;
  184. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  185. result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], (byte)(FontOpacitySlider.Value * 255), isBold, isItalic);
  186. }
  187. else
  188. {
  189. result = textArea.SetCharsFontTransparency((byte)(FontOpacitySlider.Value * 255));
  190. }
  191. if (result)
  192. {
  193. PDFEditHistory editHistory = new PDFEditHistory();
  194. editHistory.EditPage = editPage;
  195. if (pdfPage != null)
  196. {
  197. editHistory.PageIndex = pdfPage.PageIndex;
  198. }
  199. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  200. ToolView.UpdateRender(oldRect, textArea);
  201. editPage.EndEdit();
  202. }
  203. }
  204. if (EditEvent != null && textArea == null)
  205. {
  206. EditEvent.Transparency = (byte)(FontOpacitySlider.Value * 255);
  207. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  208. defaultSettingParam.SetPDFEditParamm(EditEvent);
  209. }
  210. }
  211. private void Slider_DragStarted(object sender, DragStartedEventArgs e)
  212. {
  213. Slider slider = sender as Slider;
  214. if (slider != null)
  215. {
  216. slider.Tag = "false";
  217. }
  218. }
  219. #endregion
  220. #region Loaded
  221. private void PDFTextEditControl_Loaded(object sender, RoutedEventArgs e)
  222. {
  223. TextStyleUI.TextFontChanged -= TextStyleUI_TextFontChanged;
  224. TextStyleUI.TextBoldChanged -= TextStyleUI_TextBoldChanged;
  225. TextStyleUI.TextItalicChanged -= TextStyleUI_TextItalicChanged;
  226. TextStyleUI.TextSizeChanged -= TextStyleUI_TextSizeChanged;
  227. TextAlignUI.TextAlignChanged -= TextAlignUI_TextAlignChanged;
  228. FontColorUI.ColorChanged -= FontColorUI_ColorChanged;
  229. TextStyleUI.TextFontChanged += TextStyleUI_TextFontChanged;
  230. TextStyleUI.TextBoldChanged += TextStyleUI_TextBoldChanged;
  231. TextStyleUI.TextItalicChanged += TextStyleUI_TextItalicChanged;
  232. TextStyleUI.TextSizeChanged += TextStyleUI_TextSizeChanged;
  233. TextAlignUI.TextAlignChanged += TextAlignUI_TextAlignChanged;
  234. FontColorUI.ColorChanged += FontColorUI_ColorChanged;
  235. }
  236. #endregion
  237. #region Property changed
  238. private void TextStyleUI_TextSizeChanged(object sender, double e)
  239. {
  240. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  241. if (textArea != null)
  242. {
  243. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  244. bool result;
  245. if (string.IsNullOrEmpty(textArea.SelectText))
  246. {
  247. string fontName = "Helvetica";
  248. float fontSize = 14;
  249. byte[] fontColor = { 0, 0, 0 };
  250. byte transparency = 255;
  251. bool isBold = false;
  252. bool isItalic = false;
  253. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  254. result = textArea.SetCurTextStyle(fontName, (float)e, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
  255. }
  256. else
  257. {
  258. result = textArea.SetCharsFontSize((float)e,true);
  259. }
  260. if (result)
  261. {
  262. PDFEditHistory editHistory = new PDFEditHistory();
  263. editHistory.EditPage = editPage;
  264. if (pdfPage != null)
  265. {
  266. editHistory.PageIndex = pdfPage.PageIndex;
  267. }
  268. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  269. ToolView.UpdateRender(oldRect, textArea);
  270. editPage.EndEdit();
  271. }
  272. }
  273. if (EditEvent != null && textArea == null)
  274. {
  275. EditEvent.FontSize = e;
  276. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  277. defaultSettingParam.SetPDFEditParamm(EditEvent);
  278. }
  279. //if (EditMultiEvents != null)
  280. //{
  281. // foreach (PDFEditEvent editEvent in EditMultiEvents)
  282. // {
  283. // editEvent.FontSize = e;
  284. // }
  285. // PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
  286. //}
  287. }
  288. private void FontColorUI_ColorChanged(object sender, EventArgs e)
  289. {
  290. SolidColorBrush newBrush = FontColorUI.Brush as SolidColorBrush;
  291. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  292. if (textArea != null && newBrush != null)
  293. {
  294. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  295. bool result;
  296. if (string.IsNullOrEmpty(textArea.SelectText))
  297. {
  298. string fontName = "Helvetica";
  299. float fontSize = 14;
  300. byte[] fontColor = { 0, 0, 0 };
  301. byte transparency = 255;
  302. bool isBold = false;
  303. bool isItalic = false;
  304. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  305. result = textArea.SetCurTextStyle(fontName, fontSize, newBrush.Color.R, newBrush.Color.G, newBrush.Color.B, transparency, isBold, isItalic);
  306. }
  307. else
  308. {
  309. result = textArea.SetCharsFontColor(newBrush.Color.R, newBrush.Color.G, newBrush.Color.B);
  310. }
  311. if(result)
  312. {
  313. PDFEditHistory editHistory = new PDFEditHistory();
  314. editHistory.EditPage = editPage;
  315. if (pdfPage != null)
  316. {
  317. editHistory.PageIndex = pdfPage.PageIndex;
  318. }
  319. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  320. ToolView.UpdateRender(oldRect, textArea);
  321. editPage.EndEdit();
  322. }
  323. }
  324. if (EditEvent != null && textArea == null && newBrush != null)
  325. {
  326. byte[] Color = new byte[3];
  327. Color[0] = newBrush.Color.R;
  328. Color[1] = newBrush.Color.G;
  329. Color[2] = newBrush.Color.B;
  330. EditEvent.FontColor = Color;
  331. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  332. defaultSettingParam.SetPDFEditParamm(EditEvent);
  333. }
  334. }
  335. private void TextAlignUI_TextAlignChanged(object sender, TextAlignType e)
  336. {
  337. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  338. if (textArea != null)
  339. {
  340. bool result = false;
  341. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  342. if (textArea.SelectLineRects != null && textArea.SelectLineRects.Count > 0)
  343. {
  344. result = textArea.SetTextRangeAlign(e);
  345. }
  346. else
  347. {
  348. result = textArea.SetTextAreaAlign(e);
  349. }
  350. if (result)
  351. {
  352. PDFEditHistory editHistory = new PDFEditHistory();
  353. editHistory.EditPage = editPage;
  354. if (pdfPage != null)
  355. {
  356. editHistory.PageIndex = pdfPage.PageIndex;
  357. }
  358. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  359. ToolView.UpdateRender(oldRect, textArea);
  360. editPage.EndEdit();
  361. }
  362. }
  363. if (EditEvent != null && textArea == null)
  364. {
  365. EditEvent.TextAlign = e;
  366. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  367. defaultSettingParam.SetPDFEditParamm(EditEvent);
  368. }
  369. //if (EditMultiEvents != null)
  370. //{
  371. // foreach (PDFEditEvent editEvent in EditMultiEvents)
  372. // {
  373. // editEvent.TextAlign = e;
  374. // }
  375. // PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
  376. //}
  377. }
  378. private void TextStyleUI_TextItalicChanged(object sender, bool e)
  379. {
  380. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  381. if (textArea != null)
  382. {
  383. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  384. bool result;
  385. if (string.IsNullOrEmpty(textArea.SelectText))
  386. {
  387. string fontName = "Helvetica";
  388. float fontSize = 14;
  389. byte[] fontColor = { 0, 0, 0 };
  390. byte transparency = 255;
  391. bool isBold = false;
  392. bool isItalic = false;
  393. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  394. result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, e);
  395. }
  396. else
  397. {
  398. result = textArea.SetCharsFontItalic(e);
  399. }
  400. if (result)
  401. {
  402. PDFEditHistory editHistory = new PDFEditHistory();
  403. editHistory.EditPage = editPage;
  404. if (pdfPage != null)
  405. {
  406. editHistory.PageIndex = pdfPage.PageIndex;
  407. }
  408. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  409. ToolView.UpdateRender(oldRect, textArea);
  410. editPage.EndEdit();
  411. }
  412. }
  413. if (EditEvent != null && textArea == null)
  414. {
  415. EditEvent.IsItalic = e;
  416. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  417. defaultSettingParam.SetPDFEditParamm(EditEvent);
  418. }
  419. //if (EditMultiEvents != null)
  420. //{
  421. // foreach (PDFEditEvent editEvent in EditMultiEvents)
  422. // {
  423. // editEvent.IsItalic = e;
  424. // }
  425. // PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
  426. //}
  427. }
  428. private void TextStyleUI_TextBoldChanged(object sender, bool e)
  429. {
  430. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  431. if (textArea != null)
  432. {
  433. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  434. bool result;
  435. if (string.IsNullOrEmpty(textArea.SelectText))
  436. {
  437. string fontName = "Helvetica";
  438. float fontSize = 14;
  439. byte[] fontColor = { 0, 0, 0 };
  440. byte transparency = 255;
  441. bool isBold = false;
  442. bool isItalic = false;
  443. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  444. result = textArea.SetCurTextStyle(fontName, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, e, isItalic);
  445. }
  446. else
  447. {
  448. result = textArea.SetCharsFontBold(e);
  449. }
  450. if (result)
  451. {
  452. PDFEditHistory editHistory = new PDFEditHistory();
  453. editHistory.EditPage = editPage;
  454. if (pdfPage != null)
  455. {
  456. editHistory.PageIndex = pdfPage.PageIndex;
  457. }
  458. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  459. ToolView.UpdateRender(oldRect, textArea);
  460. editPage.EndEdit();
  461. }
  462. }
  463. if (EditEvent != null && textArea == null)
  464. {
  465. EditEvent.IsBold = e;
  466. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  467. defaultSettingParam.SetPDFEditParamm(EditEvent);
  468. }
  469. //if (EditMultiEvents != null)
  470. //{
  471. // foreach (PDFEditEvent editEvent in EditMultiEvents)
  472. // {
  473. // editEvent.IsBold = e;
  474. // }
  475. // PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
  476. //}
  477. }
  478. private void TextStyleUI_TextFontChanged(object sender, string e)
  479. {
  480. GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage);
  481. if (textArea != null)
  482. {
  483. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  484. bool result;
  485. if (string.IsNullOrEmpty(textArea.SelectText))
  486. {
  487. string fontName = "Helvetica";
  488. float fontSize = 14;
  489. byte[] fontColor = { 0, 0, 0 };
  490. byte transparency = 255;
  491. bool isBold = false;
  492. bool isItalic = false;
  493. textArea.GetTextStyle(ref fontName, ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  494. result = textArea.SetCurTextStyle(e, fontSize, fontColor[0], fontColor[1], fontColor[2], transparency, isBold, isItalic);
  495. }
  496. else
  497. {
  498. result = textArea.SetCharsFontName(e);
  499. }
  500. if (result)
  501. {
  502. PDFEditHistory editHistory = new PDFEditHistory();
  503. editHistory.EditPage = editPage;
  504. if (pdfPage != null)
  505. {
  506. editHistory.PageIndex = pdfPage.PageIndex;
  507. }
  508. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(editHistory);
  509. ToolView.UpdateRender(oldRect, textArea);
  510. editPage.EndEdit();
  511. }
  512. }
  513. if (EditEvent != null && textArea == null)
  514. {
  515. EditEvent.FontName = e;
  516. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  517. defaultSettingParam.SetPDFEditParamm(EditEvent);
  518. }
  519. //if (EditMultiEvents != null)
  520. //{
  521. // foreach (PDFEditEvent editEvent in EditMultiEvents)
  522. // {
  523. // editEvent.FontName = e;
  524. // }
  525. // PDFEditEvent.UpdatePDFEditList(EditMultiEvents);
  526. //}
  527. }
  528. private void OpacityComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  529. {
  530. ComboBoxItem selectItem = OpacityComboBox.SelectedItem as ComboBoxItem;
  531. if (selectItem != null && selectItem.Content != null)
  532. {
  533. if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double newOpacity))
  534. {
  535. OpacityTextBox.Text = selectItem.Content.ToString();
  536. FontOpacitySlider.Value = newOpacity / 100.0;
  537. }
  538. }
  539. }
  540. #endregion
  541. #region Text Edit
  542. private void GetTextArea(out CPDFEditTextArea textArea, out CPDFPage pdfPage, out CPDFEditPage editPage)
  543. {
  544. textArea = null;
  545. editPage = null;
  546. pdfPage = null;
  547. if (ToolView == null)
  548. {
  549. return;
  550. }
  551. if (EditEvent != null)
  552. {
  553. try
  554. {
  555. CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
  556. CPDFDocument pdfDoc = pdfViewer.GetDocument();
  557. pdfPage = pdfDoc.PageAtIndex(EditEvent.PageIndex);
  558. editPage = pdfPage.GetEditPage();
  559. List<CPDFEditArea> editAreas = editPage.GetEditAreaList();
  560. if (editAreas != null && editAreas.Count > EditEvent.EditIndex)
  561. {
  562. textArea = editAreas[EditEvent.EditIndex] as CPDFEditTextArea;
  563. }
  564. }
  565. catch (Exception ex)
  566. {
  567. }
  568. }
  569. else
  570. {
  571. CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
  572. CPDFDocument pdfDoc = pdfViewer.GetDocument();
  573. pdfPage = pdfDoc.PageAtIndex(0);
  574. editPage = pdfPage.GetEditPage();
  575. editPage.BeginEdit(CPDFEditType.EditText);
  576. editPage.EndEdit();
  577. }
  578. }
  579. #endregion
  580. }
  581. }