|
@@ -1,4 +1,5 @@
|
|
|
-using ComPDFKitViewer.AnnotEvent;
|
|
|
+using ComPDFKit.PDFAnnotation;
|
|
|
+using ComPDFKitViewer.AnnotEvent;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using PDF_Office.Model;
|
|
|
using PDF_Office.Model.AnnotPanel;
|
|
@@ -11,13 +12,14 @@ using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
{
|
|
|
internal class StampAnnotPropertyViewModel : BindableBase, INavigationAware
|
|
|
{
|
|
|
- #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的)
|
|
|
+ #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的,如果要支持多语,Path则需要替换成SDK获取图片的方法,并修改对应参数与实现代码)
|
|
|
|
|
|
List<string> Path = new List<string>
|
|
|
{
|
|
@@ -60,6 +62,49 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ #region 动态图章相关配置(需要支持多语则修改DynamicStampText的内容)
|
|
|
+
|
|
|
+ List<string> DynamicStampText = new List<string>
|
|
|
+ {
|
|
|
+ "REVISED","REVIEWED","Completed","RECEIVED","APPROVED","CONFIDENTIAL"
|
|
|
+ };
|
|
|
+ List<C_TEXTSTAMP_COLOR> DynamicColor = new List<C_TEXTSTAMP_COLOR>
|
|
|
+ {
|
|
|
+ C_TEXTSTAMP_COLOR.TEXTSTAMP_RED, C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
|
|
|
+ C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
|
|
|
+ C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_RED,
|
|
|
+ };
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ private string author = "12312";
|
|
|
+
|
|
|
+ public string Author
|
|
|
+ {
|
|
|
+ get { return author; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref author, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool isSetAuthor = false;
|
|
|
+
|
|
|
+ public bool IsSetAuthor
|
|
|
+ {
|
|
|
+ get { return isSetAuthor; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref isSetAuthor, value);
|
|
|
+ if (PDFViewer!=null)
|
|
|
+ {
|
|
|
+ UpDataDynamicStampList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private CPDFViewer PDFViewer;
|
|
|
public ObservableCollection<Stamp> StandardStampList { get; set; }
|
|
|
public ObservableCollection<Stamp> DynamicStampList { get; set; }
|
|
@@ -71,6 +116,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
DynamicStampList = new ObservableCollection<Stamp>();
|
|
|
CustomStampList = new ObservableCollection<Stamp>();
|
|
|
InitStandardStamp();
|
|
|
+ UpDataDynamicStampList();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -117,14 +163,94 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
|
|
|
Args.Opacity = stamp.Opacity;
|
|
|
Args.MaxWidth = stamp.MaxWidth;
|
|
|
Args.MaxHeight = stamp.MaxHeight;
|
|
|
- BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
|
|
|
- Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
|
|
|
- image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
|
|
|
- Args.ImageHeight = image.PixelHeight;
|
|
|
- Args.ImageWidth = image.PixelWidth;
|
|
|
+ Args.StampTextDate = stamp.StampTextDate;
|
|
|
+ Args.TextColor = stamp.TextColor;
|
|
|
+ if (!string.IsNullOrEmpty(stamp.SourcePath))
|
|
|
+ {
|
|
|
+ BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
|
|
|
+ Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
|
|
|
+ image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
|
|
|
+ Args.ImageHeight = image.PixelHeight;
|
|
|
+ Args.ImageWidth = image.PixelWidth;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
|
|
|
+ stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
|
|
|
+ Args.ImageHeight = stamp.ImageSource.PixelHeight;
|
|
|
+ Args.ImageWidth = stamp.ImageSource.PixelWidth;
|
|
|
+ }
|
|
|
Args.Type = stamp.Type;
|
|
|
PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
|
|
|
PDFViewer.SetToolParam(Args);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新动态图章对象相关属性
|
|
|
+ /// </summary>
|
|
|
+ public void UpDataDynamicStampList()
|
|
|
+ {
|
|
|
+ DynamicStampList.Clear();
|
|
|
+ for (int i = 0; i < DynamicStampText.Count; i++)
|
|
|
+ {
|
|
|
+ string date = "";
|
|
|
+ //区分机密(CONFIDENTIAL)和其他动态图章的区别
|
|
|
+ if (i < DynamicStampText.Count - 1)
|
|
|
+ {
|
|
|
+ date = System.DateTime.Now.ToString("F");
|
|
|
+ }
|
|
|
+
|
|
|
+ Stamp standardStamp = new Stamp();
|
|
|
+ if (IsSetAuthor && !string.IsNullOrEmpty(Author))
|
|
|
+ {
|
|
|
+ standardStamp.Author = Author;
|
|
|
+ if (i < DynamicStampText.Count - 1)
|
|
|
+ {
|
|
|
+ standardStamp.StampTextDate = "By " + Author + " at " + date;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ standardStamp.StampTextDate = Author;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ standardStamp.StampTextDate = date;
|
|
|
+ standardStamp.Author = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
|
|
|
+ C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
|
|
|
+ PixelFormat fmt = PixelFormats.Bgra32;
|
|
|
+ BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ standardStamp.Opacity = 1;
|
|
|
+ standardStamp.SourcePath = "";
|
|
|
+ standardStamp.StampText = DynamicStampText[i];
|
|
|
+ standardStamp.MaxWidth = stampWidth;
|
|
|
+ standardStamp.MaxHeight = stampHeight;
|
|
|
+ standardStamp.Type = StampType.TEXT_STAMP;
|
|
|
+ standardStamp.ImageSource = bps;
|
|
|
+ switch (DynamicColor[i])
|
|
|
+ {
|
|
|
+ case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
|
|
|
+ break;
|
|
|
+ case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
|
|
|
+ standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
|
|
|
+ break;
|
|
|
+ case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
|
|
|
+ standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
|
|
|
+ break;
|
|
|
+ case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ DynamicStampList.Add(standardStamp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|