Kaynağa Gözat

compdfkit(windows) - 文字编辑创建文字块指定字体颜色,大小,透明度等参数

liyuxuan 1 yıl önce
ebeveyn
işleme
08f3566127

+ 25 - 10
Demo/Examples/Compdfkit_Tools/Edit/PDFTextEdit/PDFTextEditControl/PDFTextEditControl.xaml.cs

@@ -12,7 +12,7 @@ namespace Compdfkit_Tools.Edit
 {
     public partial class PDFTextEditControl : UserControl
     {
-        public CPDFViewer PDFView { get;private set; }
+        public CPDFViewer PDFView { get; private set; }
         public PDFEditEvent EditEvent { get; set; }
         public PDFTextEditControl()
         {
@@ -28,18 +28,25 @@ namespace Compdfkit_Tools.Edit
         public void SetPDFTextEditData(PDFEditEvent newEvent)
         {
             EditEvent = null;
-            if (newEvent!=null && newEvent.EditType==CPDFEditType.EditText)
+            if (newEvent != null && newEvent.EditType == CPDFEditType.EditText)
             {
-                if (newEvent.SystemFontNameList.Contains(newEvent.FontName) == false && string.IsNullOrEmpty(newEvent.FontName)==false)
+                if (newEvent.SystemFontNameList != null && newEvent.SystemFontNameList.Count == 0)
+                {
+                    newEvent.SystemFontNameList.Add("Helvetica");
+                    newEvent.SystemFontNameList.Add("Courier New");
+                    newEvent.SystemFontNameList.Add("Times New Roman");
+                }
+                if (newEvent.SystemFontNameList.Contains(newEvent.FontName) == false && string.IsNullOrEmpty(newEvent.FontName) == false)
                 {
                     newEvent.SystemFontNameList.Add(newEvent.FontName);
                 }
 
                 TextStyleUI.SetFontNames(newEvent.SystemFontNameList);
                 TextStyleUI.SelectFontName(newEvent.FontName);
-                TextStyleUI.SetFontStyle(newEvent.IsBold,newEvent.IsItalic);
+                TextStyleUI.SetFontStyle(newEvent.IsBold, newEvent.IsItalic);
                 TextStyleUI.SetFontSize(newEvent.FontSize);
-                OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(newEvent.Transparency * 100/255D)));
+                OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Ceiling(newEvent.Transparency * 100 / 255D)));
+                FontOpacitySlider.Value = ((int)(Math.Ceiling(newEvent.Transparency * 100 / 255D))) / 100D;
                 TextAlignUI.SetFontAlign(newEvent.TextAlign);
                 FontColorUI.SetCheckedForColor(newEvent.FontColor);
             }
@@ -77,11 +84,11 @@ namespace Compdfkit_Tools.Edit
         private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
         {
             Slider slider = sender as Slider;
-            if(OpacityTextBox!=null && FontOpacitySlider!=null)
+            if (OpacityTextBox != null && FontOpacitySlider != null)
             {
                 OpacityTextBox.Text = string.Format("{0}%", (int)(FontOpacitySlider.Value * 100));
             }
-          
+
             if (slider != null && slider.Tag != null && slider.Tag.ToString() == "false")
             {
                 return;
@@ -120,6 +127,14 @@ namespace Compdfkit_Tools.Edit
 
         private void PDFTextEditControl_Loaded(object sender, RoutedEventArgs e)
         {
+
+            TextStyleUI.TextFontChanged -= TextStyleUI_TextFontChanged;
+            TextStyleUI.TextBoldChanged -= TextStyleUI_TextBoldChanged;
+            TextStyleUI.TextItalicChanged -= TextStyleUI_TextItalicChanged;
+            TextStyleUI.TextSizeChanged -= TextStyleUI_TextSizeChanged;
+            TextAlignUI.TextAlignChanged -= TextAlignUI_TextAlignChanged;
+            FontColorUI.ColorChanged -= FontColorUI_ColorChanged;
+
             TextStyleUI.TextFontChanged += TextStyleUI_TextFontChanged;
             TextStyleUI.TextBoldChanged += TextStyleUI_TextBoldChanged;
             TextStyleUI.TextItalicChanged += TextStyleUI_TextItalicChanged;
@@ -150,7 +165,7 @@ namespace Compdfkit_Tools.Edit
             }
         }
 
-        private void TextAlignUI_TextAlignChanged(object sender,TextAlignType e)
+        private void TextAlignUI_TextAlignChanged(object sender, TextAlignType e)
         {
             if (EditEvent != null)
             {
@@ -161,7 +176,7 @@ namespace Compdfkit_Tools.Edit
 
         private void TextStyleUI_TextItalicChanged(object sender, bool e)
         {
-            if(EditEvent!=null)
+            if (EditEvent != null)
             {
                 EditEvent.IsItalic = e;
                 EditEvent.UpdatePDFEditByEventArgs();
@@ -194,7 +209,7 @@ namespace Compdfkit_Tools.Edit
                 if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double newOpacity))
                 {
                     OpacityTextBox.Text = selectItem.Content.ToString();
-                    FontOpacitySlider.Value = newOpacity/100.0;
+                    FontOpacitySlider.Value = newOpacity / 100.0;
                 }
             }
         }

+ 44 - 8
Demo/Examples/ContentEditor/MainWindow.xaml.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFPage;
+using ComPDFKit.PDFPage.Edit;
 using Compdfkit_Tools.Edit;
 using Compdfkit_Tools.Helper;
 using Compdfkit_Tools.PDFControl;
@@ -18,6 +19,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
+using System.Windows.Media;
 using System.Windows.Media.Imaging;
 
 namespace ContentEditor
@@ -83,6 +85,8 @@ namespace ContentEditor
 
         public event PropertyChangedEventHandler PropertyChanged;
 
+        private PDFEditEvent pdfTextCreateParam;
+
         #endregion
 
         public MainWindow()
@@ -190,7 +194,7 @@ namespace ContentEditor
         }
 
         #endregion
-           
+
         #region Expand and collapse Panel
 
         private void ExpandLeftPanel(bool isExpand)
@@ -212,7 +216,7 @@ namespace ContentEditor
         #endregion
 
         #region Context menu
-         
+
         private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
         {
             if (e != null && e.CommandType == CommandType.Context)
@@ -557,6 +561,7 @@ namespace ContentEditor
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
             }
             else
             {
@@ -588,7 +593,7 @@ namespace ContentEditor
                 parentMenu.Items.Add(opacityMenu);
             }
         }
-         
+
         private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
         {
             editCommand.PopupMenu = new ContextMenu();
@@ -812,6 +817,25 @@ namespace ContentEditor
                     pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
                     pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
                     pdfViewControl.PDFView?.ReloadDocument();
+                    PDFEditEvent createParam = new PDFEditEvent();
+                    createParam.EditType = CPDFEditType.EditText;
+                    createParam.IsBold = true;
+                    createParam.IsItalic = true;
+                    createParam.FontSize = 14;
+                    createParam.FontName = "Courier New";
+                    createParam.FontColor = Colors.Red;
+                    createParam.TextAlign = TextAlignType.AlignRight;
+                    createParam.Transparency = 100;
+                    pdfViewControl.PDFView?.SetPDFEditParam(createParam);
+                    if (textEditControl == null)
+                    {
+                        textEditControl = new PDFTextEditControl();
+                    }
+                    textEditControl.SetPDFTextEditData(createParam);
+                    PropertyContainer.Child = textEditControl;
+                    PropertyContainer.Visibility = Visibility.Visible;
+                    RightPanelBtn.IsChecked = true;
+                    pdfTextCreateParam = createParam;
                 }
                 else
                 {
@@ -888,7 +912,7 @@ namespace ContentEditor
         #endregion
 
         #region Property changed
-         
+
         protected void OnPropertyChanged([CallerMemberName] string name = null)
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
@@ -902,7 +926,7 @@ namespace ContentEditor
         #endregion
 
         #region Event handle
-         
+
         private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
         {
             if (e == null)
@@ -930,9 +954,21 @@ namespace ContentEditor
             ViewSettingBtn.IsChecked = false;
             if (e == null)
             {
-                PropertyContainer.Child = null;
-                RightPanelBtn.IsChecked = false;
-                PropertyContainer.Visibility = Visibility.Collapsed;
+                PropertyContainer.Child = empytPanel;
+                if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
+                {
+                    if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
+                    {
+                        if (textEditControl == null)
+                        {
+                            textEditControl = new PDFTextEditControl();
+                        }
+                        textEditControl.SetPDFTextEditData(pdfTextCreateParam);
+                        PropertyContainer.Child = textEditControl;
+                        PropertyContainer.Visibility = Visibility.Visible;
+                        RightPanelBtn.IsChecked = true;
+                    }
+                }
                 return;
             }
 

+ 60 - 3
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -86,6 +86,8 @@ namespace PDFViewer
         public event Func<string[], bool> CheckExistBeforeOpenFileEvent;
         public event PropertyChangedEventHandler PropertyChanged;
         public event EventHandler FileChangeEvent;
+        private PDFEditEvent pdfTextCreateParam;
+        private PDFTextEditControl textEditControl = new PDFTextEditControl();
         #endregion
 
         public MainPage()
@@ -302,6 +304,23 @@ namespace PDFViewer
                     pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
                     pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
                     pdfViewControl.PDFView?.ReloadDocument();
+                    PDFEditEvent createParam = new PDFEditEvent();
+                    createParam.EditType = CPDFEditType.EditText;
+                    createParam.IsBold = true;
+                    createParam.IsItalic = true;
+                    createParam.FontSize = 14;
+                    createParam.FontName = "Courier New";
+                    createParam.FontColor = Colors.Red;
+                    createParam.TextAlign = TextAlignType.AlignRight;
+                    createParam.Transparency = 100;
+                    pdfViewControl.PDFView?.SetPDFEditParam(createParam);
+                    if (textEditControl == null)
+                    {
+                        textEditControl = new PDFTextEditControl();
+                    }
+                    textEditControl.SetPDFTextEditData(createParam);
+                    ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
+                    pdfTextCreateParam = createParam;
                 }
                 else
                 {
@@ -726,6 +745,7 @@ namespace PDFViewer
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
                 editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
             }
             else
             {
@@ -1073,7 +1093,27 @@ namespace PDFViewer
                     }
                     else
                     {
-                        ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                        bool expandEmpty = true;
+                        if (currentMode == "Content Editor")
+                        {
+                            if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
+                            {
+                                if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
+                                {
+                                    if (textEditControl == null)
+                                    {
+                                        textEditControl = new PDFTextEditControl();
+                                    }
+                                    textEditControl.SetPDFTextEditData(pdfTextCreateParam);
+                                    ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
+                                    expandEmpty = false;
+                                }
+                            }
+                        }
+                        if (expandEmpty)
+                        {
+                            ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
+                        }
                     }
                     if ((bool)ViewSettingBtn.IsChecked)
                     {
@@ -1153,7 +1193,19 @@ namespace PDFViewer
             {
                 pdfEditControl = null;
                 PropertyContainer.Child = pdfEditControl;
-                ExpandRightPropertyPanel(null, Visibility.Collapsed);
+
+                if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
+                {
+                    if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
+                    {
+                        if (textEditControl == null)
+                        {
+                            textEditControl = new PDFTextEditControl();
+                        }
+                        textEditControl.SetPDFTextEditData(pdfTextCreateParam);
+                        ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
+                    }
+                }
                 return;
             }
             if (Mouse.RightButton == MouseButtonState.Pressed)
@@ -1163,7 +1215,10 @@ namespace PDFViewer
             if (e.EditType == CPDFEditType.EditText)
             {
                 RightPanelButton.IsChecked = true;
-                PDFTextEditControl textEditControl = new PDFTextEditControl();
+                if (textEditControl == null)
+                {
+                    textEditControl = new PDFTextEditControl();
+                }
                 textEditControl.SetPDFTextEditData(e);
                 pdfEditControl = textEditControl as UIElement;
                 PropertyContainer.Child = pdfEditControl;
@@ -1272,6 +1327,7 @@ namespace PDFViewer
         /// </summary>
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
+            pdfTextCreateParam = null;
             if (isFirstLoad)
             {
                 isFirstLoad = false;
@@ -1417,6 +1473,7 @@ namespace PDFViewer
                 PageEditBarControl.Visibility = Visibility.Collapsed;
 
                 pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
+                pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
                 pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
                 pdfViewControl.PDFView?.ReloadDocument();
 

BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/build/x64/ComPDFKit.dll


BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/build/x86/ComPDFKit.dll


BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/lib/ComPDFKit.Desk.dll


BIN
Demo/Examples/packages/ComPDFKit.NetFramework.1.9.0/lib/ComPDFKit.Viewer.dll