Jelajahi Sumber

ComPDFKit.Demo(win) - 调整创建注释示例代码

TangJinZhou 1 hari lalu
induk
melakukan
edd3ff942d
1 mengubah file dengan 15 tambahan dan 19 penghapusan
  1. 15 19
      Demo/Examples/Samples/AnnotationTest/CS/AnnotationTest.cs

+ 15 - 19
Demo/Examples/Samples/AnnotationTest/CS/AnnotationTest.cs

@@ -6,9 +6,7 @@ using System;
 using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Imaging;
-using System.Drawing.Printing;
 using System.IO;
-using System.Linq;
 using System.Runtime.InteropServices;
 
 namespace AnnotationTest
@@ -101,7 +99,7 @@ namespace AnnotationTest
                 new CPoint(100,10),
             });
             ink.SetInkPath(points);
-            ink.SetRect(new CRect(10, 10, 200, 200));
+            ink.SetRect(new CRect(10, 200, 200, 20));
 
             ink.UpdateAp();
         }
@@ -135,7 +133,7 @@ namespace AnnotationTest
 
             // Circle
             CPDFCircleAnnotation circle = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE) as CPDFCircleAnnotation;
-            circle.SetRect(new CRect(10, 300, 110, 410));
+            circle.SetRect(new CRect(10, 410, 110, 300));
             circle.SetLineColor(lineColor);
             circle.SetBgColor(bgColor);
             circle.SetTransparency(120);
@@ -167,7 +165,7 @@ namespace AnnotationTest
             textAnnotation.SetColor(new byte[] { 255, 0, 0 });
             textAnnotation.SetTransparency(255);
             textAnnotation.SetContent("ComPDFKit");
-            textAnnotation.SetRect(new CRect(300, 600, 350, 650));
+            textAnnotation.SetRect(new CRect(300, 650, 350, 600));
             textAnnotation.UpdateAp();
         }
 
@@ -179,7 +177,7 @@ namespace AnnotationTest
         {
             CPDFPage page = document.PageAtIndex(0);
             CPDFSoundAnnotation sound = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_SOUND) as CPDFSoundAnnotation;
-            sound.SetRect(new CRect(400, 700, 450, 750));
+            sound.SetRect(new CRect(400, 750, 450, 700));
             sound.SetSoundPath("", "Bird.wav");
             sound.UpdateAp();
         }
@@ -191,7 +189,7 @@ namespace AnnotationTest
         static private void CreateMarkupAnnotation(CPDFDocument document)
         {
             List<CRect> cRectList = new List<CRect>();
-            CRect rect = new CRect(300, 240, 400, 300);
+            CRect rect = new CRect(300, 300, 400, 240);
             cRectList.Add(rect);
             byte[] color = { 255, 0, 0 };
 
@@ -235,9 +233,7 @@ namespace AnnotationTest
 
         public static byte[] BitmapToByteArray(Bitmap bitmap)
         {
-
             BitmapData bmpdata = null;
-
             try
             {
                 bmpdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
@@ -267,7 +263,7 @@ namespace AnnotationTest
             CPDFStampAnnotation standard = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
             standard.SetStandardStamp("Approved");
              
-            standard.SetSourceRect(new CRect(100, 100, 250, 150));
+            standard.SetSourceRect(new CRect(100, 150, 250, 100));
             standard.AnnotationRotator.SetRotation(45);
 
             standard.UpdateAp();
@@ -275,14 +271,14 @@ namespace AnnotationTest
             // Text
             CPDFStampAnnotation text = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
             text.SetTextStamp("test", "detail text", C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE, C_TEXTSTAMP_COLOR.TEXTSTAMP_RED);
-            text.SetRect(new CRect(300, 220, 450, 300));
+            text.SetRect(new CRect(300, 300, 450, 220));
             text.UpdateAp();
 
             // Image
             Bitmap bitmap = new Bitmap("logo.png");
             CPDFStampAnnotation image = page.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP) as CPDFStampAnnotation;
             image.SetImageStamp(BitmapToByteArray(bitmap), bitmap.Width, bitmap.Height);
-            image.SetRect(new CRect(300, 320, 380, 400));
+            image.SetRect(new CRect(300, 400, 380, 320));
             image.SetTransparency(255);
             standard.AnnotationRotator.SetRotation(45);
             image.UpdateAp();
@@ -306,15 +302,15 @@ namespace AnnotationTest
         /// <returns></returns>
         static private bool CreateAnnots(CPDFDocument document)
         {
-            //CreateFreetextAnnotation(document);
-            //CreateFreehandAnnotation(document);
+            CreateFreetextAnnotation(document);
+            CreateFreehandAnnotation(document);
+            CreateShapeAnnotation(document);
+            CreateNoteAnnotation(document);
             CreateShapeAnnotation(document);
-            //CreateNoteAnnotation(document);
-            //CreateShapeAnnotation(document);
-            //CreateSoundAnnotation(document);
-            //CreateMarkupAnnotation(document);
+            CreateSoundAnnotation(document);
+            CreateMarkupAnnotation(document);
             CreateStampAnnotation(document);
-            //CreateLinkAnnotation(document);
+            CreateLinkAnnotation(document);
             string path = Path.Combine(outputPath, "CreateAnnotsTest.pdf");
             if (!document.WriteToFilePath(path))
             {