Browse Source

compdfkit(win) - samples部分注释

liuaoran 1 year ago
parent
commit
3df1fc63d1

+ 1 - 2
Demo/Examples/Compdfkit_Tools/Common/PropertyControl/ColorPickerControl.xaml.cs

@@ -105,8 +105,7 @@ namespace Compdfkit_Tools.Common
             {
                 return false;
             }
-        }
-
+        }  
 
         public void SetCheckedForColor(Color color)
         {

+ 6 - 2
Demo/Examples/Samples/TextExtractTest/TextExtractTest.cs

@@ -14,6 +14,7 @@ namespace TextExtractTest
 
         static void Main(string[] args)
         {
+            #region Perparation work
             Console.WriteLine("Running PDFPage test sample…\r\n");
 
             SDKLicenseHelper.LicenseVerify();
@@ -23,8 +24,9 @@ namespace TextExtractTest
             {
                 Directory.CreateDirectory(outputPath);
             }
+            #endregion
 
-           if(PDFToText(document))
+            if (PDFToText(document))
             {
                 Console.WriteLine("PDF to text done.");
             }
@@ -38,10 +40,12 @@ namespace TextExtractTest
             Console.ReadLine();
         }
 
+        //
         static private bool PDFToText(CPDFDocument document)
         {
             string path = outputPath + "//PDFToText.txt";
-            if (!document.PdfToText("1-" + document.PageCount.ToString(), path)){
+            if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
+            {
                 return false;
             }
             Console.WriteLine("Browse the generated file in " + path);

+ 33 - 5
Demo/Examples/Samples/TextSearchTest/TextSearch.cs

@@ -17,24 +17,35 @@ namespace TextSearchTest
         static private string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\TextSearch";
         static void Main(string[] args)
         {
+            #region Perparation work
             Console.WriteLine("Running text search test sample…\r\n");
-                        if (!Directory.Exists(outputPath))
+            if (!Directory.Exists(outputPath))
             {
                 Directory.CreateDirectory(outputPath);
             }
             SDKLicenseHelper.LicenseVerify();
+
+            #endregion
+
+            #region Sample 1: Search text
+
             CPDFDocument document = CPDFDocument.InitWithFilePath("Text.pdf");
 
             SearchText(document);
-
+            document.Release();
             Console.WriteLine("--------------------");
+
+            #endregion
+            
             Console.WriteLine("Done");
             Console.WriteLine("--------------------");
-
             Console.ReadLine();
         }
 
-        static void SearchForPage(CPDFPage page, string searchKeywords, C_Search_Options option, ref List<Rect> rects, ref List<string> strings)
+        /// <summary>
+        /// Search for keywords in the current page and record the search results.
+        /// </summary> 
+        static private void SearchForPage(CPDFPage page, string searchKeywords, C_Search_Options option, ref List<Rect> rects, ref List<string> strings)
         {
             rects = new List<Rect>();
             strings = new List<string>();
@@ -55,6 +66,9 @@ namespace TextSearchTest
             }
         }
 
+        /// <summary>
+        ///  Highlight the first result
+        /// </summary> 
         static private bool HighlightTheFirstResult(CPDFPage page, Rect rect)
         {
             List<CRect> cRectList = new List<CRect>();
@@ -69,16 +83,30 @@ namespace TextSearchTest
             return true;
         }
 
+        /// <summary>
+        /// Search PDF keywords on the first page of the article, 
+        /// after the search is completed, 
+        /// highlight the first searched keyword and save it
+        /// </summary>
+        /// <param name="document">PDF with text</param> 
         static private bool SearchText(CPDFDocument document)
         {
             CPDFPage page = document.PageAtIndex(0);
+            //rects: The collection of locales where keywords are located.
             List<Rect> rects = new List<Rect>();
+            //strings: The full text of the keyword's area
             List<string> strings = new List<string>();
+
+            //Search for single page
             SearchForPage(page, "PDF", C_Search_Options.Search_Case_Insensitive, ref rects, ref strings);
-            Console.WriteLine("the key PDF have {0} results", rects.Count);
+
+            Console.WriteLine("The pdf have {0} results", rects.Count);
 
             Console.WriteLine("Search finished, now highlight the first result. ");
+
+            //Highlight the first result
             HighlightTheFirstResult(page, rects[0]);
+
             string path = outputPath + "\\HighlightFirstTest.pdf";
             if (!document.WriteToFilePath(path))
             {

+ 46 - 2
Demo/Examples/Samples/WatermarkTest/WatermarkTest.cs

@@ -18,6 +18,8 @@ namespace WatermarkTest
         static private string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\Watermark";
         static void Main(string[] args)
         {
+
+            #region Perparation work
             Console.WriteLine("Running Watermark test sample…\r\n");
             SDKLicenseHelper.LicenseVerify();
             CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
@@ -26,6 +28,9 @@ namespace WatermarkTest
             {
                 Directory.CreateDirectory(outputPath);
             }
+            #endregion
+
+            #region Sample 1: Add text watermark.
 
             if (AddTextWatermark(document))
             {
@@ -36,9 +41,16 @@ namespace WatermarkTest
                 Console.WriteLine("Add text watermark failed.");
             }
 
-            Console.WriteLine("--------------------"); 
             document.Release();
+
+            Console.WriteLine("--------------------");
+
+            #endregion
+
+            #region Sample 2: Add image watermark
+
             document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
+
             if (AddImageWatermark(document))
             {
                 Console.WriteLine("Add image watermark done.");
@@ -47,7 +59,15 @@ namespace WatermarkTest
             {
                 Console.WriteLine("Add image watermark failed.");
             }
+
+            document.Release();
+
             Console.WriteLine("--------------------");
+
+            #endregion
+
+            #region Sample 3: Delete watermark
+             
             CPDFDocument textWatermarkDocument = CPDFDocument.InitWithFilePath("Watermark.pdf");
 
             if (DeleteWatermark(textWatermarkDocument))
@@ -58,11 +78,22 @@ namespace WatermarkTest
             {
                 Console.WriteLine("Delete watermark failed.");
             }
+
+            textWatermarkDocument.Release();
+
             Console.WriteLine("--------------------");
+
+            #endregion
+
             Console.WriteLine("Done!");
             Console.WriteLine("--------------------");
             Console.ReadLine();
         }
+
+        /// <summary>
+        /// Add text watermark
+        /// </summary>
+        /// <param name="document">Regular document without watermark.</param> 
         static private bool AddTextWatermark(CPDFDocument document)
         {
             CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
@@ -93,6 +124,11 @@ namespace WatermarkTest
             return true;
         }
 
+        /// <summary>
+        ///  Convert the bitmap to an array that can be set as an image watermark
+        /// </summary>
+        /// <param name="bitmap">Image source to be used as a image watermark.</param>
+        /// <returns>An array for setting image watermarks</returns>
         public static byte[] BitmapToByteArray(Bitmap bitmap)
         {
 
@@ -114,8 +150,12 @@ namespace WatermarkTest
                 if (bmpdata != null)
                     bitmap.UnlockBits(bmpdata);
             }
-
         }
+
+        /// <summary>
+        /// Add image watermark
+        /// </summary>
+        /// <param name="document">Image source to be used as a image watermark.</param> 
         static private bool AddImageWatermark(CPDFDocument document)
         {
             CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
@@ -145,6 +185,10 @@ namespace WatermarkTest
             return true; 
         }
 
+        /// <summary>
+        /// Delete watermark
+        /// </summary>
+        /// <param name="watermarkDocument">Documents with text watermarks</param> 
         static private bool DeleteWatermark(CPDFDocument watermarkDocument)
         {
             watermarkDocument.DeleteWatermarks();