Browse Source

ComPDFKit.Tool(Win) - 形状注释自动设置框选范围下文字为Content

liyuxuan 6 months ago
parent
commit
eb27472686
1 changed files with 27 additions and 1 deletions
  1. 27 1
      Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

+ 27 - 1
Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

@@ -1438,7 +1438,8 @@ namespace ComPDFKit.Tool
                     (float)rect.Top);
 
                 annotation.SetRect(cRect);
-                if(annotation.Type!=C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
+                SaveSharpAnnotBoundText(annotation);
+                if (annotation.Type!=C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
                 {
                     annotation.UpdateAp();
                 }
@@ -1498,6 +1499,31 @@ namespace ComPDFKit.Tool
             }
         }
 
+        private void SaveSharpAnnotBoundText(CPDFAnnotation boundAnnot)
+        {
+            if (boundAnnot == null || boundAnnot.Page == null || boundAnnot.Page.IsValid() == false)
+            {
+                return;
+            }
+
+            if (boundAnnot.Type != C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE && boundAnnot.Type != C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
+            {
+                return;
+            }
+
+            CPDFTextPage textPage=  boundAnnot.Page.GetTextPage();
+            if (textPage == null || textPage.IsValid()==false)
+            {
+                return;
+            }
+
+            string boundText = textPage.GetBoundedText(boundAnnot.GetRect());
+            if(string.IsNullOrEmpty(boundText)==false)
+            {
+                boundAnnot.SetContent(boundText);
+            }
+        }
+
         private void StickyAnnot_StickyPopupClosed(object sender, EventArgs e)
         {
             StickyNoteAnnot.StickyPopupClosed -= StickyAnnot_StickyPopupClosed;