PDFEditHelper.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. defaultEdit.SystemFontNameList = new List<string>();
  75. SettingHelper.SetPDFEditProperty(defaultEdit);
  76. Settings.Default.Save();
  77. return defaultEdit;
  78. }
  79. }
  80. }