瀏覽代碼

ComPDFKit.Tool(pdftech) - 修改图章创建保存

liyuxuan 8 月之前
父節點
當前提交
da81e1b685

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

@@ -1005,6 +1005,38 @@ namespace ComPDFKit.Tool
             }
         }
 
+        private bool SaveStampImageData(CPDFAnnotation annotation,CRect stampRect)
+        {
+            CPDFStampAnnotation stampAnnot=annotation as CPDFStampAnnotation;
+            if(viewerTool==null || stampAnnot == null ||stampAnnot.GetStampType()!=C_STAMP_TYPE.IMAGE_STAMP)
+            {
+                return false;
+            }
+
+            try
+            {
+                DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
+                StampParam stampParam = defaultSettingParam.StampParamDef;
+                byte[] imageData = null;
+                int imageWidth = 0;
+                int imageHeight = 0;
+                PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
+
+                if (imageData != null && imageWidth > 0 && imageHeight > 0)
+                {
+                    stampAnnot.SetRect(stampRect);
+                    stampAnnot.SetImageStamp(imageData,imageWidth,imageHeight,stampParam.Rotation);
+                    return true;
+                }
+            }
+            catch (Exception ex) 
+            { 
+
+            }
+
+            return false;
+        }
+
         private void SaveCreateAnnotation(ref CPDFAnnotation annotation, ref MouseEventObject e)
         {
             if (annotation == null)
@@ -1218,7 +1250,10 @@ namespace ComPDFKit.Tool
                                         stampRect.Width, stampRect.Height)
                                         );
                                     CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
-                                    annotation.SetRect(cStampRect);
+                                    if (SaveStampImageData(annotation,cStampRect) == false)
+                                    {
+                                        annotation.SetRect(cStampRect);
+                                    }
                                     annotation.UpdateAp();
                                     e.IsCreate = true;
                                     e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;

+ 1 - 1
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.DataMethod.cs

@@ -564,7 +564,7 @@ namespace ComPDFKit.Tool
 
                         if (imageData != null && imageWidth > 0 && imageHeight > 0)
                         {
-                            strikeoutAnnotation.SetRect(new CRect(0, imageHeight, imageWidth, 0));
+                           // strikeoutAnnotation.SetRect(new CRect(0, imageHeight, imageWidth, 0));
                             strikeoutAnnotation.SetImageStamp(
                                 imageData,
                                 imageWidth,