|
@@ -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();
|