12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Office.Core;
- using Microsoft.Win32;
- using PDF_Office.CustomControl;
- using PDF_Office.Helper;
- using PDF_Office.Model.BOTA;
- using PDF_Office.Properties;
- using PDF_Office.ViewModels.BOTA;
- using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
- using PDF_Office.Views.BOTA;
- using PDF_Office.Views.PropertyPanel.AnnotPanel;
- using PDFSettings;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
- using ContextMenu = System.Windows.Controls.ContextMenu;
- using HorizontalAlignment = System.Windows.HorizontalAlignment;
- using MenuItem = System.Windows.Controls.MenuItem;
- using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
- namespace PDF_Office.ViewModels.Tools
- {
- //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 初始化
- #region 初始化数据
- //初始化注释的属性值,并存在本地缓存数据集里
- private void InitDefaultValue()
- {
- InitAnnotHighlight();
- InitAnnotUnderline();
- InitAnnotSquiggly();
- InitAnnotStrikeout();
- }
- private void InitAnnotHighlight()
- {
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
- if (annotProperty == null)
- {
- annotProperty = new DefaultAnnotProperty();
- annotProperty.AnnotToolType = AnnotArgsType.AnnotHighlight;
- annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.Opacity = 0.5;
- SettingHelper.SetAnnotDefaultProperty(annotProperty);
- }
- else
- {
- HighLightColor = new SolidColorBrush(annotProperty.BackgroundColor);
- HighLightOpacity = annotProperty.Opacity;
- }
- }
- private void InitAnnotUnderline()
- {
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
- if (annotProperty == null)
- {
- annotProperty = new DefaultAnnotProperty();
- annotProperty.AnnotToolType = AnnotArgsType.AnnotUnderline;
- annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.Opacity = 0.5;
- SettingHelper.SetAnnotDefaultProperty(annotProperty);
- }
- else
- {
- UnderLineColor = new SolidColorBrush(annotProperty.BackgroundColor);
- UnderLineOpacity = annotProperty.Opacity;
- }
- }
- private void InitAnnotSquiggly()
- {
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
- if (annotProperty == null)
- {
- annotProperty = new DefaultAnnotProperty();
- annotProperty.AnnotToolType = AnnotArgsType.AnnotSquiggly;
- annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.Opacity = 0.5;
- SettingHelper.SetAnnotDefaultProperty(annotProperty);
- }
- else
- {
- SquigglyColor = new SolidColorBrush(annotProperty.BackgroundColor);
- SquigglyOpacity = annotProperty.Opacity;
- }
- }
- private void InitAnnotStrikeout()
- {
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
- if (annotProperty == null)
- {
- annotProperty = new DefaultAnnotProperty();
- annotProperty.AnnotToolType = AnnotArgsType.AnnotStrikeout;
- annotProperty.BackgroundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.ForgoundColor = Color.FromRgb(0xFF, 0xBB, 0x00);
- annotProperty.Opacity = 0.5;
- SettingHelper.SetAnnotDefaultProperty(annotProperty);
- }
- else
- {
- StrikeoutColor = new SolidColorBrush(annotProperty.BackgroundColor);
- StrikeoutOpacity = annotProperty.Opacity;
- }
- }
- //用来记录选中和创建注释的标识
- private void InitToolDict()
- {
- ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
- ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
- ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
- ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
- ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
- ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
- ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
- ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
- ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
- ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
- ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
- ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
- ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
- }
- #endregion 初始化数据
- #endregion 初始化
- #region 注释工具
- //注释工具
- private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
- {
- switch (tag)
- {
- case "SnapshotEdit"://内容选择
- annotArgs = GetSnapshotEdit();
- break;
- case "HighLight"://字体高亮
- annotArgs = GetHighLight();
- break;
- case "UnderLine"://下划线
- annotArgs = GetUnderLine();
- break;
- case "Squiggly"://波浪线
- annotArgs = GetSquiggly();
- break;
- case "Strikeout"://删除线
- annotArgs = GetStrikeout();
- break;
- case "Freehand"://手绘
- annotArgs = GetFreehand();
- break;
- case "Freetext"://文本
- annotArgs = GetFreetext();
- break;
- case "StickyNote"://便签
- annotArgs = GetStickyNote();
- break;
- case "Rect"://矩形
- annotArgs = GetRect();
- break;
- case "Circle"://圆
- annotArgs = GetCircle();
- break;
- case "Arrow"://箭头
- case "Line"://线
- annotArgs = GetArrowLine(tag);
- break;
- case "Stamp"://图章
- annotArgs = GetStamp();
- break;
- case "Image":
- annotArgs = GetImage();
- break;
- case "Signature"://签名
- annotArgs = GetSignature();
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "Link"://链接
- viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
- annotArgs = GetLink();
- break;
- }
- }
- /// <summary>
- /// 高亮注释
- /// </summary>
- private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- TextHighlightAnnotArgs highlightArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- highlightArgs = new TextHighlightAnnotArgs();
- highlightArgs.Color = Color.FromRgb(0xFF, 0xBB, 0x00);
- highlightArgs.Transparency = 0.5;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotHighlight);
- if (annotProperty != null)
- {
- highlightArgs.Color = annotProperty.ForgoundColor;
- highlightArgs.Transparency = annotProperty.Opacity;
- highlightArgs.Content = annotProperty.NoteText;
- }
- if (highlightArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(highlightArgs);
- }
- }
- else
- {
- highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
- annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = highlightArgs.Content;
- AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs, annotAttribsList);
- return highlightArgs;
- }
- /// <summary>
- /// 链接
- /// </summary>
- /// <param name="selectedArgs">所选中的注释</param>
- /// <param name="annotAttribEvent">注释属性列表</param>
- public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLink);
- if (annotProperty != null)
- {
- }
- if (selectedArgs != null && selectedArgs.Count > 1)
- {
- linkArgs = selectedArgs[0] as LinkAnnotArgs;
- }
- else
- {
- linkArgs.URI = string.Empty;
- linkArgs.LinkType = LINK_TYPE.GOTO;
- linkArgs.DestIndex = -1;
- if (linkArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(linkArgs);
- }
- }
- annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
- annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
- annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
- AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribsList, annotAttribEvent);
- return linkArgs;
- }
- /// <summary>
- /// 下划线
- /// </summary>
- /// <param name="selectedArgs"></param>
- private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- TextUnderlineAnnotArgs underlineArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- underlineArgs = new TextUnderlineAnnotArgs();
- underlineArgs.Color = Color.FromRgb(0x12, 0xFD, 0xFF);
- underlineArgs.Transparency = 1;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotUnderline);
- if (annotProperty != null)
- {
- underlineArgs.Color = annotProperty.ForgoundColor;
- underlineArgs.Transparency = annotProperty.Opacity;
- underlineArgs.Content = annotProperty.NoteText;
- }
- if (underlineArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(underlineArgs);
- }
- }
- else
- {
- underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
- annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = underlineArgs.Content;
- AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs, annotAttribsList);
- return underlineArgs;
- }
- /// <summary>
- /// 波浪线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- TextSquigglyAnnotArgs squigglyArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squigglyArgs = new TextSquigglyAnnotArgs();
- squigglyArgs.Color = Color.FromRgb(0xFF, 0x87, 0x16);
- squigglyArgs.Transparency = 1;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquiggly);
- if (annotProperty != null)
- {
- squigglyArgs.Color = annotProperty.ForgoundColor;
- squigglyArgs.Transparency = annotProperty.Opacity;
- squigglyArgs.Content = annotProperty.NoteText;
- }
- if (squigglyArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squigglyArgs);
- }
- }
- else
- {
- squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
- annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = squigglyArgs.Content;
- AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs, annotAttribsList);
- return squigglyArgs;
- }
- /// <summary>
- /// 删除线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- TextStrikeoutAnnotArgs strikeoutArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- strikeoutArgs = new TextStrikeoutAnnotArgs();
- strikeoutArgs.Color = Color.FromRgb(0xFF, 0x3B, 0x30);
- strikeoutArgs.Transparency = 1;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStrikeout);
- if (annotProperty != null)
- {
- strikeoutArgs.Color = annotProperty.ForgoundColor;
- strikeoutArgs.Transparency = annotProperty.Opacity;
- strikeoutArgs.Content = annotProperty.NoteText;
- }
- if (strikeoutArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(strikeoutArgs);
- }
- }
- else
- {
- strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
- annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = strikeoutArgs.Content;
- AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs, annotAttribsList);
- return strikeoutArgs;
- }
- /// <summary>
- /// 手绘
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- FreehandAnnotArgs freehandArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freehandArgs = new FreehandAnnotArgs();
- freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
- freehandArgs.Transparency = 1;
- freehandArgs.LineWidth = 2;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreehand);
- if (annotProperty != null)
- {
- freehandArgs.InkColor = annotProperty.ForgoundColor;
- freehandArgs.Transparency = annotProperty.Opacity;
- freehandArgs.LineWidth = annotProperty.Thickness;
- freehandArgs.Content = annotProperty.NoteText;
- }
- if (freehandArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freehandArgs);
- }
- }
- else
- {
- freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
- annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
- annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
- annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs, annotAttribsList);
- return freehandArgs;
- }
- /// <summary>
- /// 文本
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- FreeTextAnnotArgs freetextArgs = null;
- TextAlignment textAlignment;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freetextArgs = new FreeTextAnnotArgs();
- freetextArgs.Align = TextAlignment.Left;
- freetextArgs.BgColor = Colors.Transparent;
- freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
- freetextArgs.FontColor = Colors.Black;
- freetextArgs.FontSize = 14;
- freetextArgs.Transparency = 1;
- freetextArgs.LineColor = Colors.Black;
- freetextArgs.LineWidth = 0;
- freetextArgs.TextContent = string.Empty;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
- if (annotProperty != null)
- {
- freetextArgs.Align = annotProperty.TextAlign;
- freetextArgs.BgColor = annotProperty.BackgroundColor;
- freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
- freetextArgs.FontColor = annotProperty.ForgoundColor;
- freetextArgs.FontSize = annotProperty.FontSize;
- freetextArgs.Transparency = annotProperty.Opacity;
- freetextArgs.LineColor = annotProperty.BorderColor;
- freetextArgs.LineWidth = annotProperty.Thickness;
- freetextArgs.TextContent = annotProperty.NoteText;
- freetextArgs.FontWeight = annotProperty.FontWeight;
- freetextArgs.FontStyle = annotProperty.FontStyle;
- }
- int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
- if (align == 0)
- textAlignment = TextAlignment.Left;
- else if (align == 1)
- textAlignment = TextAlignment.Center;
- else
- textAlignment = TextAlignment.Right;
- if (freetextArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freetextArgs);
- }
- }
- else
- {
- freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
- textAlignment = freetextArgs.Align;
- }
- annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
- annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
- annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
- annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
- annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
- annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
- annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
- annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
- annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
- annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
- AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
- return freetextArgs;
- }
- /// <summary>
- /// 便签
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
- stickyAnnotArgs.StickyNote = string.Empty;
- stickyAnnotArgs.Transparency = 1;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSticky);
- if (annotProperty != null)
- {
- stickyAnnotArgs.Color = annotProperty.ForgoundColor;
- stickyAnnotArgs.StickyNote = annotProperty.NoteText;
- stickyAnnotArgs.Transparency = annotProperty.Opacity;
- }
- if (stickyAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(stickyAnnotArgs);
- }
- }
- else
- {
- stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
- annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
- annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
- List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stickyAnnotArgs != null)
- stickyAnnotArgsList.Add(stickyAnnotArgs);
- AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs, annotAttribsList);
- return stickyAnnotArgs;
- }
- /// <summary>
- /// 矩形
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- SquareAnnotArgs squareArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squareArgs = new SquareAnnotArgs();
- squareArgs.LineColor = Colors.Red;
- squareArgs.BgColor = Colors.Transparent;
- squareArgs.LineWidth = 1;
- squareArgs.Transparency = 1;
- squareArgs.LineDash = DashStyles.Solid;
- squareArgs.Content = string.Empty;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotSquare);
- if (annotProperty != null)
- {
- squareArgs.LineColor = annotProperty.BorderColor;
- squareArgs.BgColor = annotProperty.BackgroundColor;
- if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
- {
- squareArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- DashStyle dash = new DashStyle();
- foreach (var offset in annotProperty.DashArray)
- {
- dash.Dashes.Add(offset);
- }
- squareArgs.LineDash = dash;
- }
- squareArgs.LineWidth = annotProperty.Thickness;
- squareArgs.Transparency = annotProperty.Opacity;
- squareArgs.Content = annotProperty.NoteText;
- }
- if (squareArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squareArgs);
- }
- }
- else
- {
- squareArgs = selectedArgs[0] as SquareAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
- annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
- annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
- annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
- AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs, annotAttribsList);
- return squareArgs;
- }
- /// <summary>
- /// 圆
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- CircleAnnotArgs circleAnnotArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- circleAnnotArgs = new CircleAnnotArgs();
- circleAnnotArgs.LineColor = Colors.Red;
- circleAnnotArgs.BgColor = Colors.Transparent;
- circleAnnotArgs.LineWidth = 1;
- circleAnnotArgs.Transparency = 1;
- circleAnnotArgs.LineDash = DashStyles.Solid;
- circleAnnotArgs.Content = string.Empty;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotCircle);
- if (annotProperty != null)
- {
- circleAnnotArgs.LineColor = annotProperty.BorderColor;
- circleAnnotArgs.BgColor = annotProperty.BackgroundColor;
- if (annotProperty.DashArray == null || annotProperty.DashArray.Count == 0)
- {
- circleAnnotArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- DashStyle dash = new DashStyle();
- foreach (var offset in annotProperty.DashArray)
- {
- dash.Dashes.Add(offset);
- }
- circleAnnotArgs.LineDash = dash;
- }
- circleAnnotArgs.LineWidth = annotProperty.Thickness;
- circleAnnotArgs.Transparency = annotProperty.Opacity;
- circleAnnotArgs.Content = annotProperty.NoteText;
- }
- if (circleAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(circleAnnotArgs);
- }
- }
- else
- {
- circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
- }
- annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
- annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
- annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
- annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
- AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs, annotAttribsList);
- return circleAnnotArgs;
- }
- /// <summary>
- /// 箭头 线
- /// </summary>
- /// <param name="TagStr"></param>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- LineAnnotArgs lineArgs = new LineAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- lineArgs.LineColor = Colors.Red;
- lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
- if (TagStr == "Line")
- {
- lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
- }
- else
- {
- lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
- }
- lineArgs.LineDash = DashStyles.Solid;
- lineArgs.LineWidth = 1;
- lineArgs.Transparency = 1;
- lineArgs.Content = string.Empty;
- if (lineArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(lineArgs);
- }
- }
- else
- {
- lineArgs = selectedArgs[0] as LineAnnotArgs;
- }
- DefaultAnnotProperty annotProperty = null;
- if (TagStr == "Line")
- {
- annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Line");
- if (annotProperty != null)
- {
- annotProperty.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
- annotProperty.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
- }
- }
- else
- {
- annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotLine, "Arrow");
- }
- if (annotProperty != null)
- {
- lineArgs.LineColor = annotProperty.BorderColor;
- lineArgs.HeadLineType = annotProperty.HeadLineType;
- lineArgs.TailLineType = annotProperty.TailLineType;
- DashStyle dash = new DashStyle();
- foreach (var offset in annotProperty.DashArray)
- {
- dash.Dashes.Add(offset);
- }
- lineArgs.LineDash = dash;
- lineArgs.LineWidth = annotProperty.Thickness;
- lineArgs.Transparency = annotProperty.Opacity;
- lineArgs.Content = annotProperty.NoteText;
- }
- annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
- annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
- annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
- annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
- annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
- annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
- annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
- AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs, annotAttribsList);
- return lineArgs;
- }
- /// <summary>
- /// 图章
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStamp()
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.Opacity = 1;
- stampAnnotArgs.StampText = "APPROVED";
- stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList, annotAttribsList);
- return stampAnnotArgs;
- }
- /// <summary>
- /// 签名
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSignature()
- {
- AddToPropertyPanel("SignatureAnnotProperty");
- return null;
- }
- private AnnotHandlerEventArgs GetImage()
- {
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- StampAnnotArgs stampArgs = new StampAnnotArgs();
- stampArgs.Opacity = 1;
- stampArgs.Type = StampType.IMAGE_STAMP;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- stampArgs.ImagePath = openFileDialog.FileName;
- }
- List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
- if (stampArgs != null)
- stampArgsList.Add(stampArgs);
- AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList, annotAttribsList);
- return stampArgs;
- }
- /// <summary>
- /// 内容选择
- /// </summary>
- /// <param name="annotBtn"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSnapshotEdit()
- {
- SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
- //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
- snapshotArgs.ControlPointColor = Colors.White;
- snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
- snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
- SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
- SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
- SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
- SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
- #region to do
- //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
- //snapshotArgs.ToolPanel = snapMenu;
- //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
- //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
- //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
- //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
- //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
- //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
- #endregion to do
- return snapshotArgs;
- }
- #endregion 注释工具
- #region 菜单
- private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
- {
- if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
- {
- AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
- switch (clickMenu.Tag.ToString())
- {
- case "HighLight"://字体高亮
- TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
- highlightArgs.ClientRect = annotCommand.TextRect;
- highlightArgs.Content = annotCommand.Text;
- highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(highlightArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "UnderLine"://下划线
- TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
- underlineArgs.ClientRect = annotCommand.TextRect;
- underlineArgs.Content = annotCommand.Text;
- underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(underlineArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "Strikeout"://删除线
- TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
- strikeoutArgs.ClientRect = annotCommand.TextRect;
- strikeoutArgs.Content = annotCommand.Text;
- strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(strikeoutArgs);
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- break;
- case "Freetext"://文本
- FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
- textArgs.ClientRect = annotCommand.TextRect;
- //textArgs.Transparency = 1;
- //textArgs.BgColor = Colors.Transparent;
- //textArgs.LineColor = Colors.Red;
- //textArgs.LineWidth = 2;
- textArgs.TextContent = annotCommand.Text;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
- break;
- case "StickyNote"://便签
- StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
- stickyAnnotArgs.ClientRect = annotCommand.TextRect;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
- break;
- case "Rect"://矩形
- SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
- squareAnnotArgs.ClientRect = annotCommand.TextRect;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
- break;
- case "Circle"://圆
- CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
- circleAnnotArgs.ClientRect = annotCommand.TextRect;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
- break;
- case "Line"://线
- LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
- lineAnnotArgs.ClientRect = annotCommand.TextRect;
- lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
- lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
- break;
- case "Link"://链接
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- linkArgs.ClientRect = annotCommand.TextRect;
- linkArgs.URI = string.Empty;
- linkArgs.LinkType = LINK_TYPE.GOTO;
- linkArgs.DestIndex = annotCommand.PageIndex;
- PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
- BtnLinkIsChecked = true;
- List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
- lists.Add(linkArgs);
- AnnotHandlerEventArgs annotArgs = GetLink(lists);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- viewContentViewModel.IsPropertyOpen = true;
- break;
- case "OutLine":
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
- if (isTabItemAnnotation == false)
- {
- bOTAContent.TabItemOutLine.IsSelected = true;
- }
- OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
- if (outLineControlViewModel != null && outLineControl != null)
- {
- string str = null;
- if (string.IsNullOrEmpty(annotCommand.Text))
- {
- str = (annotCommand.PageIndex + 1).ToString();
- }
- else
- {
- str = annotCommand.Text;
- }
- OutlineNode outline = outLineControl.AddOutlineNode(str);
- CPDFOutline result = outline.Outline;
- if (result != null)
- {
- outLineControlViewModel.SetTitle(result, str);
- outLineControlViewModel.Updata(false);
- //outLineControl.IsReName = true;
- //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
- //{
- // outLineControl.ReNameOutlineNode = outline;
- //}
- }
- }
- break;
- case "ExportPicture":
- ExportPicture_MenuItemClick();
- break;
- }
- //ShowPropertyPanel(false);
- }
- }
- private void ExportPicture_MenuItemClick()
- {
- //图片提取
- try
- {
- List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
- Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
- foreach (int pageIndex in imageDict.Keys)
- {
- imageList = imageDict[pageIndex];
- }
- string path = PDFViewer.Document.FileName;
- System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
- if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- int i = 1;
- int pagenum = 1;
- string choosePath = folderDialog.SelectedPath;
- string sPath = choosePath + "\\" + path + "_Extract Image";
- sPath = GetExportPathName(sPath);
- if (!Directory.Exists(sPath))
- {
- Directory.CreateDirectory(sPath);
- }
- if (Directory.Exists(sPath))
- {
- foreach (System.Drawing.Bitmap image in imageList)
- {
- foreach (var item in imageDict.Keys)
- {
- pagenum = item;
- }
- string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
- string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
- i++;
- }
- System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
- }
- }
- }
- catch (Exception ex) { }
- }
- public string GetExportPathName(string path)
- {
- int i = 1;
- string outpath = path;
- while (Directory.Exists(outpath))
- {
- outpath = path + $"({i.ToString()})";
- i++;
- }
- return outpath;
- }
- private string GetNum(int num)
- {
- if (num % 10 < 1)
- {
- return "00" + num.ToString();
- }
- if (num % 10 >= 1 && num % 10 < 10)
- {
- return "0" + num.ToString();
- }
- else
- {
- return num.ToString();
- }
- }
- #endregion 菜单
- }
- }
|