PDFEditHelper.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using ComPDFKit.PDFPage;
  2. using ComPDFKit.PDFPage.Edit;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.PdfViewer;
  5. using PDF_Master.Properties;
  6. using PDFSettings;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace PDF_Master.Helper
  13. {
  14. public static class PDFEditHelper
  15. {
  16. /// <summary>
  17. /// 获取本地配置,并且更新对应属性
  18. /// </summary>
  19. /// <returns></returns>
  20. public static PDFEditEvent GetPDFEditDefaultProperty(out DefaultEditProperty defaultEdit, CPDFViewer pdf)
  21. {
  22. PDFEditEvent editEvent = null;
  23. defaultEdit = SettingHelper.GetPDFEditDefaultProperty(CPDFEditType.EditText);
  24. if (defaultEdit == null)
  25. {
  26. defaultEdit = SetDefaultEdit();
  27. }
  28. editEvent = GetPDFEditEvent(defaultEdit, pdf);
  29. return editEvent;
  30. }
  31. /// <summary>
  32. /// 更新CPDFViewer的属性
  33. /// </summary>
  34. /// <param name="defaultEdit"></param>
  35. /// <param name="pdf"></param>
  36. /// <returns></returns>
  37. public static PDFEditEvent GetPDFEditEvent(DefaultEditProperty defaultEdit, CPDFViewer pdf)
  38. {
  39. PDFEditEvent dFEditEvent = new PDFEditEvent();
  40. dFEditEvent.FontName = defaultEdit.FontName;
  41. dFEditEvent.FontSize = defaultEdit.FontSize;
  42. dFEditEvent.TextAlign = defaultEdit.TextAlign;
  43. dFEditEvent.AutoBlock = defaultEdit.AutoBlock;
  44. dFEditEvent.ClipImage = defaultEdit.ClipImage;
  45. dFEditEvent.EditType = defaultEdit.EditType;
  46. dFEditEvent.FontColor = defaultEdit.FontColor;
  47. dFEditEvent.HorizontalMirror = defaultEdit.HorizontalMirror;
  48. dFEditEvent.IsBold = defaultEdit.IsBold;
  49. dFEditEvent.IsItalic = defaultEdit.IsItalic;
  50. dFEditEvent.ReplaceImagePath = defaultEdit.ReplaceImagePath;
  51. dFEditEvent.Rotate = defaultEdit.Rotate;
  52. dFEditEvent.Transparency = defaultEdit.Transparency;
  53. dFEditEvent.VerticalMirror = defaultEdit.VerticalMirror;
  54. pdf.SetPDFEditParam(dFEditEvent);
  55. return dFEditEvent;
  56. }
  57. public static DefaultEditProperty SetDefaultEdit()
  58. {
  59. DefaultEditProperty defaultEdit = new PDFSettings.DefaultEditProperty();
  60. defaultEdit.FontName = "Arial";
  61. defaultEdit.FontSize = 14;
  62. defaultEdit.TextAlign = TextAlignType.AlignLeft;
  63. defaultEdit.AutoBlock = true;
  64. defaultEdit.ClipImage = false;
  65. defaultEdit.EditType = ComPDFKit.PDFPage.CPDFEditType.EditText;
  66. defaultEdit.FontColor = System.Windows.Media.Color.FromArgb(255, 0, 0, 0);
  67. defaultEdit.HorizontalMirror = false;
  68. defaultEdit.VerticalMirror = false;
  69. defaultEdit.IsBold = false;
  70. defaultEdit.IsItalic = false;
  71. defaultEdit.ReplaceImagePath = null;
  72. defaultEdit.Rotate = 0;
  73. defaultEdit.Transparency = 255;
  74. SettingHelper.SetPDFEditProperty(defaultEdit);
  75. Settings.Default.Save();
  76. return defaultEdit;
  77. }
  78. }
  79. }