|
@@ -1,5 +1,6 @@
|
|
|
using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
+using Microsoft.Win32;
|
|
|
using PDF_Office.Model;
|
|
|
using PDF_Office.Model.PropertyPanel.AnnotPanel;
|
|
|
using Prism.Commands;
|
|
@@ -22,6 +23,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
#region 属性
|
|
|
|
|
|
#region 编辑PDF全局
|
|
|
+
|
|
|
private bool _isTextEdit = true;
|
|
|
public bool IsTextEdit
|
|
|
{
|
|
@@ -33,13 +35,24 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 文本属性
|
|
|
|
|
|
+ private double _angle;
|
|
|
+ public double Angle
|
|
|
+ {
|
|
|
+ get { return _angle; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref _angle, value);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Brush selectColor = new SolidColorBrush(Colors.Black);
|
|
|
public Brush SelectColor
|
|
|
{
|
|
@@ -172,6 +185,9 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
#region Command
|
|
|
|
|
|
#region 文本Command
|
|
|
+ public DelegateCommand AddTextCommand { get; set; }
|
|
|
+ public DelegateCommand AddImgCommand { get; set; }
|
|
|
+
|
|
|
public DelegateCommand<object> SelectedColorCommand { get; set; }
|
|
|
public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
|
|
|
public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
|
|
@@ -179,10 +195,16 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
public DelegateCommand<object> FontSizeChangedCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
|
|
|
-
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 图像Command
|
|
|
+ public DelegateCommand ReplaceImgCommand { get; set; }
|
|
|
+ public DelegateCommand ExportImgCommand { get; set; }
|
|
|
+ public DelegateCommand CropImgCommand { get; set; }
|
|
|
+ public DelegateCommand ImgAlignCheckedCommand { get; set; }
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 逆时针旋转
|
|
|
/// </summary>
|
|
@@ -191,7 +213,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
/// 顺时针旋转
|
|
|
/// </summary>
|
|
|
public DelegateCommand ClockwiseCommand { get; set; }
|
|
|
- public DelegateCommand CropCommand { get; set; }
|
|
|
+ public DelegateCommand CropModeCommand { get; set; }
|
|
|
public DelegateCommand CancelCropCommand { get; set; }
|
|
|
|
|
|
#endregion
|
|
@@ -217,6 +239,13 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
private void InitCommand()
|
|
|
{
|
|
|
+ AddTextCommand = new DelegateCommand(AddText);
|
|
|
+ AddImgCommand = new DelegateCommand(AddImg);
|
|
|
+ ReplaceImgCommand = new DelegateCommand(ReplaceImg);
|
|
|
+ ExportImgCommand = new DelegateCommand(ExportImg);
|
|
|
+ CropImgCommand = new DelegateCommand(CropImg);
|
|
|
+ ImgAlignCheckedCommand = new DelegateCommand(ImgAlignChecked);
|
|
|
+
|
|
|
SelectedColorCommand = new DelegateCommand<object>(SelectedColor);
|
|
|
SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
|
|
|
FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged);
|
|
@@ -226,8 +255,104 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
AntiClockwiseCommand = new DelegateCommand(AntiClockwise);
|
|
|
ClockwiseCommand = new DelegateCommand(Clockwise);
|
|
|
- CropCommand = new DelegateCommand(CropMode);
|
|
|
- CancelCropCommand = new DelegateCommand(CancelCrop);
|
|
|
+ CropModeCommand = new DelegateCommand(CropMode);
|
|
|
+ CancelCropCommand = new DelegateCommand(CancelCropImg);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ImgAlignChecked()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CancelCropImg()
|
|
|
+ {
|
|
|
+ if (TextEditEvent != null)
|
|
|
+ {
|
|
|
+ TextEditEvent.ClipImage = false;
|
|
|
+ TextEditEvent.CancelClip();
|
|
|
+
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ IsCrop = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CropImg()
|
|
|
+ {
|
|
|
+ if(TextEditEvent != null)
|
|
|
+ {
|
|
|
+ TextEditEvent.SaveClip();
|
|
|
+ TextEditEvent.ClipImage = false;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ IsCrop = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExportImg()
|
|
|
+ {
|
|
|
+ if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
|
|
|
+
|
|
|
+ //SaveFileDialog saveFileDialog = new SaveFileDialog();
|
|
|
+ //saveFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
|
|
|
+ //saveFileDialog.FileName = "编辑PDF导出图片";
|
|
|
+
|
|
|
+ System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
+ folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
|
|
+
|
|
|
+ if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(folder.SelectedPath))
|
|
|
+ return;
|
|
|
+
|
|
|
+ var keyValueList = PDFViewer.GetSelectedImages();
|
|
|
+ int i = 0;
|
|
|
+ foreach (var bitmap in keyValueList)
|
|
|
+ {
|
|
|
+ foreach(var bitmapItem in bitmap.Value)
|
|
|
+ {
|
|
|
+ bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AddImg()
|
|
|
+ {
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+ openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
|
|
|
+ openFileDialog.Multiselect = true;
|
|
|
+ if ((bool)openFileDialog.ShowDialog())
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
|
|
|
+ {
|
|
|
+ PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
|
|
|
+ PDFViewer.AddPDFEditImage(openFileDialog.FileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReplaceImg()
|
|
|
+ {
|
|
|
+ OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
+ openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
|
|
|
+ openFileDialog.Multiselect = true;
|
|
|
+ if ((bool)openFileDialog.ShowDialog())
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
|
|
|
+ {
|
|
|
+ PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
|
|
|
+ TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AddText()
|
|
|
+ {
|
|
|
+ PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
|
|
|
}
|
|
|
|
|
|
private void TextAlignChecked(object obj)
|
|
@@ -258,24 +383,25 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
private void Clockwise()
|
|
|
{
|
|
|
- TextEditEvent.Rotate = TextEditEvent.Rotate + 90;
|
|
|
+ Angle = TextEditEvent.Rotate = TextEditEvent.Rotate + 90;
|
|
|
TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
}
|
|
|
|
|
|
private void AntiClockwise()
|
|
|
{
|
|
|
- TextEditEvent.Rotate = TextEditEvent.Rotate - 90;
|
|
|
+ Angle = TextEditEvent.Rotate = TextEditEvent.Rotate - 90;
|
|
|
TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
}
|
|
|
|
|
|
- private void CancelCrop()
|
|
|
- {
|
|
|
- IsCrop = false;
|
|
|
- }
|
|
|
|
|
|
private void CropMode()
|
|
|
{
|
|
|
IsCrop = true;
|
|
|
+ if(TextEditEvent != null)
|
|
|
+ {
|
|
|
+ TextEditEvent.ClipImage = true;
|
|
|
+ TextEditEvent.UpdatePDFEditByEventArgs();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void SelectedColor(object obj)
|
|
@@ -407,7 +533,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
if(PDFViewer != null)
|
|
|
{
|
|
|
PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
|
|
|
- PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
|
|
|
+ PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
|
|
|
|
|
|
PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
|
|
|
PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
|
|
@@ -417,56 +543,88 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
|
|
|
private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
|
|
|
{
|
|
|
- ContextMenu popMenu = new ContextMenu();
|
|
|
- var menu = new MenuItem();
|
|
|
- menu.Header = "Cut";
|
|
|
- popMenu.Items.Add(menu);
|
|
|
- menu = new MenuItem();
|
|
|
- menu.Header = "Copy";
|
|
|
- popMenu.Items.Add(menu);
|
|
|
- menu = new MenuItem();
|
|
|
- menu.Header = "Paste";
|
|
|
- popMenu.Items.Add(menu);
|
|
|
- menu = new MenuItem();
|
|
|
- menu.Header = "Delete";
|
|
|
- popMenu.Items.Add(menu);
|
|
|
- menu = new MenuItem();
|
|
|
- menu.Header = "SelectAll";
|
|
|
- popMenu.Items.Add(menu);
|
|
|
-
|
|
|
+
|
|
|
+ ContextMenu popMenu = null;
|
|
|
|
|
|
switch (e.CommandType)
|
|
|
{
|
|
|
case CommandType.Context:
|
|
|
- if (popMenu.Items.Count == 5)
|
|
|
+
|
|
|
+ if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
|
|
|
{
|
|
|
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Cut;
|
|
|
-
|
|
|
- menuItem = popMenu.Items[1] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Copy;
|
|
|
-
|
|
|
- menuItem = popMenu.Items[2] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Paste;
|
|
|
-
|
|
|
- menuItem = popMenu.Items[3] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.Delete;
|
|
|
-
|
|
|
- menuItem = popMenu.Items[4] as MenuItem;
|
|
|
- menuItem.CommandTarget = (UIElement)sender;
|
|
|
- menuItem.Command = ApplicationCommands.SelectAll;
|
|
|
-
|
|
|
- e.PopupMenu = popMenu;
|
|
|
- if (e.PopupMenu != null)
|
|
|
+ popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
|
|
|
+ if(popMenu != null && popMenu.Items.Count == 4)
|
|
|
+ {
|
|
|
+ //复制
|
|
|
+ MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Copy;
|
|
|
+ //添加文本
|
|
|
+ menuItem = popMenu.Items[1] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = AddTextCommand;
|
|
|
+ //添加图像
|
|
|
+ menuItem = popMenu.Items[2] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = AddImgCommand;
|
|
|
+ //删除
|
|
|
+ menuItem = popMenu.Items[3] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Delete;
|
|
|
+
|
|
|
+ e.PopupMenu = popMenu;
|
|
|
+ if (e.PopupMenu != null)
|
|
|
+ {
|
|
|
+ e.Handle = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
|
|
|
+ {
|
|
|
+ popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
|
|
|
+ if (popMenu != null && popMenu.Items.Count == 8)
|
|
|
{
|
|
|
- e.Handle = true;
|
|
|
+ //复制
|
|
|
+ MenuItem menuItem = popMenu.Items[0] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Copy;
|
|
|
+ //剪切
|
|
|
+ menuItem = popMenu.Items[1] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Cut;
|
|
|
+ //粘贴
|
|
|
+ menuItem = popMenu.Items[2] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Paste;
|
|
|
+ //删除
|
|
|
+ menuItem = popMenu.Items[3] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Delete;
|
|
|
+ //裁剪
|
|
|
+ menuItem = popMenu.Items[4] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = CropModeCommand;
|
|
|
+ //替换
|
|
|
+ menuItem = popMenu.Items[5] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ReplaceImgCommand;
|
|
|
+ //导出
|
|
|
+ menuItem = popMenu.Items[6] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ExportImgCommand;
|
|
|
+ //排列
|
|
|
+ menuItem = popMenu.Items[7] as MenuItem;
|
|
|
+ menuItem.CommandTarget = (UIElement)sender;
|
|
|
+ menuItem.Command = ApplicationCommands.Cut;
|
|
|
+ e.PopupMenu = popMenu;
|
|
|
+ if (e.PopupMenu != null)
|
|
|
+ {
|
|
|
+ e.Handle = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- break;
|
|
|
+
|
|
|
+ break;
|
|
|
|
|
|
default:
|
|
|
e.DoCommand();
|
|
@@ -481,7 +639,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
|
|
|
{
|
|
|
IsTextEdit = (e[0].EditType == ComPDFKit.PDFPage.CPDFEditType.EditText);
|
|
|
TextEditEvent = e[0];
|
|
|
-
|
|
|
+
|
|
|
if (IsTextEdit == false)
|
|
|
{
|
|
|
|