|
@@ -21,6 +21,14 @@ using ComPDFKit.DigitalSign;
|
|
|
using ComPDFKit.PDFAnnotation.Form;
|
|
|
using Point = System.Windows.Point;
|
|
|
using Size = System.Windows.Size;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using Brush = System.Windows.Media.Brush;
|
|
|
+using Color = System.Windows.Media.Color;
|
|
|
+using System.Drawing.Drawing2D;
|
|
|
+using Matrix = System.Windows.Media.Matrix;
|
|
|
+using System.Drawing.Imaging;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
+using ComPDFKit.NativeMethod;
|
|
|
|
|
|
namespace Compdfkit_Tools.Helper
|
|
|
{
|
|
@@ -51,6 +59,65 @@ namespace Compdfkit_Tools.Helper
|
|
|
|
|
|
public static class CommonHelper
|
|
|
{
|
|
|
+ public static bool IsImageCorrupted(string imagePath)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (Bitmap bitmap = new Bitmap(imagePath))
|
|
|
+ {
|
|
|
+ int width = bitmap.Width;
|
|
|
+ int height = bitmap.Height;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ MessageBox.Show(LanguageHelper.CommonManager.GetString("Text_ImageCorrupted"), LanguageHelper.CommonManager.GetString("Button_OK"), MessageBoxButton.OK);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Bitmap ConvertTo32bppArgb(Bitmap source)
|
|
|
+ {
|
|
|
+ // Create a new Bitmap with 32bppArgb pixel format
|
|
|
+ Bitmap newBitmap = new Bitmap(source.Width, source.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
|
+
|
|
|
+ // Create a Graphics object to draw the source image on the new Bitmap
|
|
|
+ using (Graphics g = Graphics.FromImage(newBitmap))
|
|
|
+ {
|
|
|
+ // Set the interpolation mode and pixel offset mode for high-quality rendering
|
|
|
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
|
+ g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
|
|
+ g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
+
|
|
|
+ // Draw the source image on the new Bitmap
|
|
|
+ g.DrawImage(source, new System.Drawing.Rectangle(0, 0, source.Width, source.Height));
|
|
|
+ }
|
|
|
+ return newBitmap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] ConvertBrushToByteArray(Brush brush)
|
|
|
+ {
|
|
|
+ if (brush is SolidColorBrush solidColorBrush)
|
|
|
+ {
|
|
|
+ Color color = solidColorBrush.Color;
|
|
|
+
|
|
|
+ byte[] colorBytes = new byte[3];
|
|
|
+ colorBytes[0] = color.R;
|
|
|
+ colorBytes[1] = color.G;
|
|
|
+ colorBytes[2] = color.B;
|
|
|
+
|
|
|
+ return colorBytes;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ throw new ArgumentException("The provided brush is not a SolidColorBrush.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static int GetBitmapPointer(Bitmap bitmap)
|
|
|
{
|
|
|
IntPtr hBitmap = bitmap.GetHbitmap();
|
|
@@ -93,7 +160,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
string second = date.Substring(12, 2);
|
|
|
return new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), int.Parse(second));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Returns the file size based on the specified file path, with the smallest unit being bytes (B).
|
|
|
/// </summary>
|
|
@@ -122,7 +189,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
return "0B";
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static string GetExistedPathOrEmpty(string filter = "PDF files (*.pdf)|*.pdf")
|
|
|
{
|
|
|
string selectedFilePath = string.Empty;
|
|
@@ -146,7 +213,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return selectedFilePath;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static string GetGeneratePathOrEmpty(string filter, string defaultFileName = "")
|
|
|
{
|
|
|
string selectedFilePath = string.Empty;
|
|
@@ -162,75 +229,145 @@ namespace Compdfkit_Tools.Helper
|
|
|
return selectedFilePath;
|
|
|
}
|
|
|
|
|
|
+ public static string GetPageParmFromList(List<int> pagesList)
|
|
|
+ {
|
|
|
+ string pageParam = "";
|
|
|
+ if (pagesList.Count != 0)
|
|
|
+ {
|
|
|
+ pagesList.Sort();
|
|
|
+
|
|
|
+ for (int i = 0; i < pagesList.Count; i++)
|
|
|
+ {
|
|
|
+ if (i == 0)
|
|
|
+ {
|
|
|
+ pageParam += pagesList[0].ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (pagesList[i] == pagesList[i - 1] + 1)
|
|
|
+ {
|
|
|
+ if (i >= 2)
|
|
|
+ {
|
|
|
+ if (pagesList[i - 1] != pagesList[i - 2] + 1)
|
|
|
+ pageParam += "-";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ pageParam += "-";
|
|
|
+
|
|
|
+ if (i == pagesList.Count - 1)
|
|
|
+ {
|
|
|
+ pageParam += pagesList[i].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (i >= 2)
|
|
|
+ {
|
|
|
+ if (pagesList[i - 1] == pagesList[i - 2] + 1)
|
|
|
+ pageParam += pagesList[i - 1].ToString();
|
|
|
+ }
|
|
|
+ pageParam += "," + pagesList[i].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pageParam;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<int> GetDefaultPageList(CPDFDocument document)
|
|
|
+ {
|
|
|
+ List<int> pageRangeList = new List<int>();
|
|
|
+ for (int i = 0; i < document.PageCount; i++)
|
|
|
+ {
|
|
|
+ pageRangeList.Add(i + 1);
|
|
|
+ }
|
|
|
+ return pageRangeList;
|
|
|
+ }
|
|
|
+
|
|
|
public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
|
|
|
{
|
|
|
- string[] rangeSplit = pageRange.Split(enumerationSeparator);
|
|
|
+ if (pageRange == null || pageList == null)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
pageList.Clear();
|
|
|
+ int starttag = inittag ? 0 : 1;
|
|
|
+
|
|
|
+ string[] rangeSplit = pageRange.Split(enumerationSeparator);
|
|
|
|
|
|
foreach (string range in rangeSplit)
|
|
|
{
|
|
|
- int starttag = 1;
|
|
|
- if (inittag)
|
|
|
- {
|
|
|
- starttag = 0;
|
|
|
- }
|
|
|
- if (range.Contains("-"))
|
|
|
+ if (range.Contains("-"))
|
|
|
{
|
|
|
- try
|
|
|
+ string[] limits = range.Split(rangeSeparator);
|
|
|
+ if (limits.Length == 2 && int.TryParse(limits[0], out int start) && int.TryParse(limits[1], out int end))
|
|
|
{
|
|
|
- string[] limits = range.Split(rangeSeparator);
|
|
|
- if (limits.Length >= 2 && !string.IsNullOrWhiteSpace(limits[0]) && !string.IsNullOrWhiteSpace(limits[1]))
|
|
|
+ if (start < starttag || end > count || start > end)
|
|
|
{
|
|
|
- int start = int.Parse(limits[0]);
|
|
|
- int end = int.Parse(limits[1]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if ((start < starttag) || (end > count) || (start > end))
|
|
|
- {
|
|
|
+ for (int i = start; i <= end; i++)
|
|
|
+ {
|
|
|
+ if (pageList.Contains(i - 1))
|
|
|
+ {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- for (int i = start; i <= end; ++i)
|
|
|
- {
|
|
|
- if (pageList.Contains(i))
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- pageList.Add(i - 1);
|
|
|
- }
|
|
|
- continue;
|
|
|
+ pageList.Add(i - 1);
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
+ else
|
|
|
+ {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- int pageNr;
|
|
|
- try
|
|
|
- {
|
|
|
- pageNr = int.Parse(range);
|
|
|
- }
|
|
|
- catch (Exception)
|
|
|
+ else if (int.TryParse(range, out int pageNr))
|
|
|
{
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (pageNr < starttag || pageNr > count)
|
|
|
- {
|
|
|
- return false;
|
|
|
+ if (pageNr < starttag || pageNr > count)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageList.Contains(pageNr - 1))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ pageList.Add(pageNr - 1);
|
|
|
}
|
|
|
- if (pageList.Contains(pageNr))
|
|
|
+ else
|
|
|
{
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
- pageList.Add(pageNr - 1);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ internal static byte[] ConvertBitmapToByteArray(Bitmap bitmap)
|
|
|
+ {
|
|
|
+ BitmapData bmpdata = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ bmpdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
|
|
+ int numbytes = bmpdata.Stride * bitmap.Height;
|
|
|
+ byte[] bytedata = new byte[numbytes];
|
|
|
+ IntPtr ptr = bmpdata.Scan0;
|
|
|
+
|
|
|
+ Marshal.Copy(ptr, bytedata, 0, numbytes);
|
|
|
+
|
|
|
+ return bytedata;
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (bmpdata != null)
|
|
|
+ bitmap.UnlockBits(bmpdata);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
internal static class PageEditHelper
|
|
|
- {
|
|
|
+ {
|
|
|
public static T FindVisualParent<T>(DependencyObject obj) where T : class
|
|
|
{
|
|
|
while (obj != null)
|
|
@@ -311,7 +448,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
|
|
|
public class ArrowHelper
|
|
|
- {
|
|
|
+ {
|
|
|
public bool HasStartArrow
|
|
|
{
|
|
|
get
|
|
@@ -322,7 +459,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public bool IsStartClosed
|
|
|
{
|
|
@@ -334,7 +471,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public bool HasEndArrow
|
|
|
{
|
|
@@ -346,7 +483,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public bool IsEndClosed
|
|
|
{
|
|
@@ -358,15 +495,15 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- public uint ArrowAngle { get; set; }
|
|
|
- public uint ArrowLength { get; set; }
|
|
|
- public Point? LineStart { get; set; }
|
|
|
- public Point? LineEnd { get; set; }
|
|
|
- public PathGeometry Body { get; set; }
|
|
|
- public C_LINE_TYPE StartSharp { get; set; }
|
|
|
- public C_LINE_TYPE EndSharp { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public uint ArrowAngle { get; set; }
|
|
|
+ public uint ArrowLength { get; set; }
|
|
|
+ public Point? LineStart { get; set; }
|
|
|
+ public Point? LineEnd { get; set; }
|
|
|
+ public PathGeometry Body { get; set; }
|
|
|
+ public C_LINE_TYPE StartSharp { get; set; }
|
|
|
+ public C_LINE_TYPE EndSharp { get; set; }
|
|
|
public ArrowHelper()
|
|
|
{
|
|
|
Body = new PathGeometry();
|
|
@@ -377,10 +514,10 @@ namespace Compdfkit_Tools.Helper
|
|
|
{
|
|
|
if (LineStart != null && LineEnd != null)
|
|
|
{
|
|
|
- PathFigure lineFigure = new PathFigure();
|
|
|
+ PathFigure lineFigure = new PathFigure();
|
|
|
lineFigure.StartPoint = (Point)LineStart;
|
|
|
LineSegment linePath = new LineSegment();
|
|
|
- linePath.Point = (Point)LineEnd;
|
|
|
+ linePath.Point = (Point)LineEnd;
|
|
|
lineFigure.Segments.Add(linePath);
|
|
|
return lineFigure;
|
|
|
}
|
|
@@ -441,7 +578,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
break;
|
|
|
}
|
|
|
return null;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public PathGeometry BuildArrowBody()
|
|
|
{
|
|
@@ -463,7 +600,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
return Body;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private PathFigure CreateStartOpenArrow()
|
|
|
{
|
|
|
if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
|
|
@@ -485,7 +622,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsClosed = IsStartClosed;
|
|
|
arrowFigure.IsFilled = IsStartClosed;
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndOpenArrow()
|
|
|
{
|
|
@@ -508,7 +645,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsClosed = IsEndClosed;
|
|
|
arrowFigure.IsFilled = IsEndClosed;
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateStartReverseArrow()
|
|
|
{
|
|
@@ -531,7 +668,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsClosed = IsStartClosed;
|
|
|
arrowFigure.IsFilled = IsStartClosed;
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndReverseArrow()
|
|
|
{
|
|
@@ -555,7 +692,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsFilled = IsEndClosed;
|
|
|
return arrowFigure;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private PathFigure CreateStartButtArrow()
|
|
|
{
|
|
|
if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
|
|
@@ -574,7 +711,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
|
|
|
arrowFigure.Segments.Add(buttSegment);
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndButtArrow()
|
|
|
{
|
|
@@ -595,7 +732,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.Segments.Add(buttSegment);
|
|
|
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateStartDiamondArrow()
|
|
|
{
|
|
@@ -634,7 +771,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsClosed = IsStartClosed;
|
|
|
arrowFigure.IsFilled = IsStartClosed;
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndDiamondArrow()
|
|
|
{
|
|
@@ -674,7 +811,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.IsClosed = IsEndClosed;
|
|
|
arrowFigure.IsFilled = IsEndClosed;
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateStartRoundArrow()
|
|
|
{
|
|
@@ -701,7 +838,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.Segments.Add(circleSegment);
|
|
|
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndRoundArrow()
|
|
|
{
|
|
@@ -728,7 +865,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.Segments.Add(circleSegment);
|
|
|
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateStartSquareArrow()
|
|
|
{
|
|
@@ -762,7 +899,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.Segments.Add(squreSegment);
|
|
|
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndSquareArrow()
|
|
|
{
|
|
@@ -797,7 +934,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
arrowFigure.Segments.Add(squreSegment);
|
|
|
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateStartSlashArrow()
|
|
|
{
|
|
@@ -817,7 +954,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
|
|
|
arrowFigure.Segments.Add(buttSegment);
|
|
|
return arrowFigure;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
private PathFigure CreateEndSlashArrow()
|
|
|
{
|
|
@@ -956,7 +1093,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void ExtraImage_Click(Dictionary<int,List<Bitmap>> imageDict)
|
|
|
+ public static void ExtraImage_Click(Dictionary<int, List<Bitmap>> imageDict)
|
|
|
{
|
|
|
System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
@@ -986,7 +1123,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static double CheckZoomLevel(double[] zoomLevelList, double zoom, bool IsGrowth)
|
|
|
{
|
|
|
double standardZoom = 100;
|
|
@@ -1020,11 +1157,11 @@ namespace Compdfkit_Tools.Helper
|
|
|
public class SignatureHelper
|
|
|
{
|
|
|
public static List<CPDFSignature> SignatureList;
|
|
|
-
|
|
|
+
|
|
|
public static void InitEffectiveSignatureList(CPDFDocument document)
|
|
|
{
|
|
|
SignatureList = document.GetSignatureList();
|
|
|
- for(int index = SignatureList.Count - 1; index >= 0; index--)
|
|
|
+ for (int index = SignatureList.Count - 1; index >= 0; index--)
|
|
|
{
|
|
|
if (SignatureList[index].SignerList.Count <= 0)
|
|
|
{
|
|
@@ -1039,7 +1176,7 @@ namespace Compdfkit_Tools.Helper
|
|
|
{
|
|
|
sig.VerifySignatureWithDocument(document);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|