Procházet zdrojové kódy

compdfkit(windows) - form,pushbutton action

liuaoran před 1 rokem
rodič
revize
1690469756

+ 32 - 5
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml.cs

@@ -1,12 +1,17 @@
 using ComPDFKit.Import;
+using ComPDFKit.PDFAnnotation;
+using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFDocument.Action;
+using ComPDFKit.PDFPage;
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using System;
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media.Imaging;
@@ -15,7 +20,7 @@ namespace Compdfkit_Tools.PDFControl
 {
     public partial class PDFViewControl : UserControl
     {
-        public CPDFViewer PDFView { get;private set; }
+        public CPDFViewer PDFView { get; private set; }
 
         public bool CustomSignHandle { get; set; }
 
@@ -33,7 +38,7 @@ namespace Compdfkit_Tools.PDFControl
 
         private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
         {
-            if ((e is WidgetSignArgs) && CustomSignHandle==false)
+            if ((e is WidgetSignArgs) && CustomSignHandle == false)
             {
                 try
                 {
@@ -64,14 +69,14 @@ namespace Compdfkit_Tools.PDFControl
                         }
                     }
                 }
-                catch(Exception ex)
+                catch (Exception ex)
                 {
 
                 }
             }
         }
 
-        private void PDFView_PDFActionHandler(object sender,CPDFAction pdfAction)
+        private void PDFView_PDFActionHandler(object sender, CPDFAction pdfAction)
         {
             if (pdfAction != null)
             {
@@ -163,7 +168,7 @@ namespace Compdfkit_Tools.PDFControl
                 }
             }
 
-          
+
         }
 
         private void PDFView_MouseWheelZoomHandler(object sender, bool e)
@@ -201,5 +206,27 @@ namespace Compdfkit_Tools.PDFControl
             return standardZoom / 100;
         }
 
+        public bool CheckHasForm()
+        {
+            if (PDFView == null || PDFView.Document == null)
+                return false;
+
+            var document = PDFView.Document;
+            for (int i = 0; i < document.PageCount; i++)
+            {
+                CPDFPage page = document.PageAtIndex(i, false);
+                List<CPDFAnnotation> annotList = page.GetAnnotations();
+                if (annotList == null || annotList.Count < 1)
+                    continue;
+
+                List<CPDFWidget> formList = annotList.AsEnumerable().
+                    Where(x => x.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+                    .Cast<CPDFWidget>()
+                    .ToList();
+                if (formList.Count > 0)
+                    return true;
+            }
+            return false;
+        }
     }
 }

+ 0 - 2
Demo/Examples/ContentEditor/MainWindow.xaml.cs

@@ -1094,7 +1094,6 @@ namespace ContentEditor
                     pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
                     pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
                     pdfViewControl.PDFView?.ReloadDocument();
-                   
                 } 
                 if (ViewComboBox.SelectedIndex == 1)
                 {
@@ -1114,7 +1113,6 @@ namespace ContentEditor
                 }
             }
         }
-
         #endregion 
 
         #region Close window

+ 3 - 0
Demo/Examples/Samples/ImageExtractTest/ImageExtractTest.cs

@@ -31,6 +31,9 @@ namespace ImageExtractTest
             }
 
             ExtractImage(document);
+            Console.WriteLine("--------------------");
+            Console.WriteLine("Done");
+            Console.WriteLine("--------------------");
             Console.ReadLine();
         }
 

+ 85 - 13
Demo/Examples/Samples/InteractiveFormsTest/InteractiveFormsTest.cs

@@ -1,6 +1,8 @@
 using ComPDFKit.Import;
+using ComPDFKit.PDFAnnotation;
 using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFDocument.Action;
 using ComPDFKit.PDFPage;
 using ComPDFKit.PDFPage.Edit;
 using System;
@@ -33,51 +35,121 @@ namespace InteractiveFormsTest
             {
                 Console.WriteLine("Create forms failed."); 
             }
+            Console.WriteLine("--------------------");
+            Console.WriteLine("Done");
+            Console.WriteLine("--------------------");
+            Console.ReadLine();
         }
 
         static private void CreateTextField(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
             CPDFTextWidget textField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_TEXTFIELD) as CPDFTextWidget;
-            textField.SetRect(new CRect( 28, 32, 237, 75));
+            textField.SetRect(new CRect( 28, 32, 235, 75));
+            textField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            textField.SetWidgetBgRGBColor(new byte[] {240,255,240});
         }
 
         static private void CreatePushButton(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
-            CPDFPushButtonWidget textField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_PUSHBUTTON) as CPDFPushButtonWidget;
-            textField.SetRect(new CRect(28, 32, 237, 75));
+            CPDFPushButtonWidget pushButton1 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_PUSHBUTTON) as CPDFPushButtonWidget;
+            pushButton1.SetRect(new CRect(28, 150, 150, 100));
+            pushButton1.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            pushButton1.SetWidgetBgRGBColor(new byte[] { 180, 180, 220 });
+            pushButton1.SetButtonTitle("Go To Page 2");
+            CTextAttribute attribute = new CTextAttribute();
+            attribute.FontColor = new byte[] { 0, 0, 0 };
+            attribute.FontSize = 14;
+            attribute.FontName = "Helvetica";
+            pushButton1.SetTextAttribute(attribute);
+            CPDFGoToAction gotoAction = new CPDFGoToAction();
+            CPDFDestination dest = new CPDFDestination();
+            dest.PageIndex = 1;
+            gotoAction.SetDestination(document, dest);
+            pushButton1.SetButtonAction(gotoAction);
+            pushButton1.UpdateFormAp();
+
+            CPDFPushButtonWidget pushButton2 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_PUSHBUTTON) as CPDFPushButtonWidget;
+            pushButton2.SetRect(new CRect(168, 150, 290, 100));
+            pushButton2.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            pushButton2.SetWidgetBgRGBColor(new byte[] { 180, 180, 220 });
+            pushButton2.SetButtonTitle("Go To ComPDFKit");
+            CTextAttribute attribute2 = new CTextAttribute();
+            attribute2.FontColor = new byte[] { 0, 0, 0 };
+            attribute2.FontSize = 14;
+            attribute2.FontName = "Helvetica";
+            pushButton2.SetTextAttribute(attribute);
+
+            CPDFUriAction uriAction = new CPDFUriAction();
+            uriAction.SetUri("https://www.compdf.com/");
+
+            pushButton2.SetButtonAction(uriAction);
+            pushButton2.UpdateFormAp();
         }
 
         static private void CreateListBox(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
-            CPDFListBoxWidget listbox = page.CreateWidget(C_WIDGET_TYPE.WIDGET_LISTBOX) as CPDFListBoxWidget;
-            listbox.AddOptionItem(0, "1", "a");
-            listbox.AddOptionItem(1, "2", "b");
-            listbox.SetRect(new CRect(28, 32, 237, 75));
+            CPDFListBoxWidget listbox = page.CreateWidget(C_WIDGET_TYPE.WIDGET_LISTBOX) as CPDFListBoxWidget; 
+            listbox.SetRect(new CRect(28, 350, 150, 230));
+            listbox.AddOptionItem(0, "1", "ComPDFKit1");
+            listbox.AddOptionItem(1, "2", "ComPDFKit2");
+            listbox.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            listbox.SetWidgetBgRGBColor(new byte[] { 200, 180, 180 });
         }
 
         static private void CreateSignatureField(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
             CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
-            signatureField.SetRect(new CRect(28, 32, 237, 75));
+            signatureField.SetRect(new CRect(28, 420, 150, 370));
+
+            signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
         }
 
         static private void CreateCheckBox(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
-            CPDFCheckBoxWidget checkBox = page.CreateWidget(C_WIDGET_TYPE.WIDGET_CHECKBOX) as CPDFCheckBoxWidget;
-            checkBox.SetRect(new CRect(28, 32, 237, 75));
+            CPDFCheckBoxWidget checkBox1 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_CHECKBOX) as CPDFCheckBoxWidget;
+            checkBox1.SetRect(new CRect(28, 470, 48, 450));
+            checkBox1.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            checkBox1.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
+
+            CPDFCheckBoxWidget checkBox2 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_CHECKBOX) as CPDFCheckBoxWidget;
+            checkBox2.SetRect(new CRect(58, 470, 78, 450));
+            checkBox2.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            checkBox2.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
+
+            CPDFCheckBoxWidget checkBox3 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_CHECKBOX) as CPDFCheckBoxWidget;
+            checkBox3.SetRect(new CRect(88, 470, 108, 450));
+            checkBox3.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            checkBox3.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
         }
+
         static private void CreateRadioButton(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
-            CPDFRadioButtonWidget radioButton = page.CreateWidget(C_WIDGET_TYPE.WIDGET_RADIOBUTTON) as CPDFRadioButtonWidget;
-            radioButton.SetRect(new CRect(28, 32, 237, 75));
+            CPDFRadioButtonWidget radioButton1 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_RADIOBUTTON) as CPDFRadioButtonWidget;
+            radioButton1.SetRect(new CRect(28, 500, 48, 480));
+            radioButton1.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            radioButton1.SetWidgetBgRGBColor(new byte[] { 210, 180, 150 });
+            radioButton1.SetWidgetCheckStyle(C_CHECK_STYLE.CK_CIRCLE);
+
+            CPDFRadioButtonWidget radioButton2 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_RADIOBUTTON) as CPDFRadioButtonWidget;
+            radioButton2.SetRect(new CRect(58, 500, 78, 480));
+            radioButton2.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            radioButton2.SetWidgetBgRGBColor(new byte[] { 210, 180, 150 });
+            radioButton2.SetWidgetCheckStyle(C_CHECK_STYLE.CK_CIRCLE);
+
+            CPDFRadioButtonWidget radioButton3 = page.CreateWidget(C_WIDGET_TYPE.WIDGET_RADIOBUTTON) as CPDFRadioButtonWidget;
+            radioButton3.SetRect(new CRect(88, 500, 108, 480));
+            radioButton3.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
+            radioButton3.SetWidgetBgRGBColor(new byte[] { 210, 180, 150 });
+            radioButton3.SetWidgetCheckStyle(C_CHECK_STYLE.CK_CIRCLE);
         }
-         
+
         static private bool CreateForms(CPDFDocument document)
         {
             CreateTextField(document);

+ 1 - 0
Demo/Examples/Samples/InteractiveFormsTest/InteractiveFormsTest.csproj

@@ -49,6 +49,7 @@
     <Reference Include="System.Data" />
     <Reference Include="System.Net.Http" />
     <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="..\LicenseKey.cs">

+ 12 - 0
Demo/Examples/Viewer/MainWindow.xaml.cs

@@ -423,6 +423,18 @@ namespace Viewer
                 {
                     e.Handle = true;
                     e.PopupMenu = new ContextMenu();
+                    if (pdfViewControl.CheckHasForm())
+                    {
+                        MenuItem resetForms = new MenuItem();
+                        resetForms.Header = "Reset Forms";
+                        resetForms.Click += (o, p) =>
+                        {
+                            if (pdfViewControl != null)
+                            { 
+                                //pdfViewControl.PDFView?.ResetForm();
+                            }
+                        };
+                    }
 
                     MenuItem fitWidthMenu = new MenuItem();
                     fitWidthMenu.Header = "Automatically Resize";