12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using Dropbox.Api.TeamLog;
- using Microsoft.Office.Core;
- using Microsoft.Win32;
- using PDF_Office.CustomControl;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- 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 Prism.Services.Dialogs;
- 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.Documents;
- using System.Windows.Forms;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- 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()
- {
- InitToolBtnUI();
- }
- //注释工具按钮初始化时的属性值
- private void InitToolBtnUI()
- {
- InitAnnotHighlight();
- InitAnnotUnderline();
- InitAnnotSquiggly();
- InitAnnotStrikeout();
- }
- private void InitAnnotHighlight()
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.HighLightColor != Colors.Transparent)
- {
- HighLightColor = new SolidColorBrush(annotate.HighLightColor);
- HighLightOpacity = 1;
- }
- else
- {
- HighLightColor = new SolidColorBrush(Colors.Red);
- HighLightOpacity = 1;
- }
- }
- private void InitAnnotUnderline()
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- //避免默认值为透明度
- if (annotate != null && annotate.UnderLineColor != Colors.Transparent)
- {
- UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
- HighLightOpacity = 1;
- }
- else
- {
- UnderLineColor = new SolidColorBrush(Colors.Red);
- UnderLineOpacity = 1;
- }
- }
- private void InitAnnotSquiggly()
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
- {
- SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
- SquigglyOpacity = 1;
- }
- else
- {
- SquigglyColor = new SolidColorBrush(Colors.Red);
- SquigglyOpacity = 1;
- }
- }
- private void InitAnnotStrikeout()
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null && annotate.StrikethroughColor != Colors.Transparent)
- {
- StrikeoutColor = new SolidColorBrush(annotate.StrikethroughColor);
- StrikeoutOpacity = 1;
- }
- else
- {
- StrikeoutColor = new SolidColorBrush(Colors.Red);
- StrikeoutOpacity = 1;
- }
- }
- //在xaml里引用
- public Dictionary<string, string> GetToolTipDict
- { get { return ToolTipDict; } }
- //用来记录选中、创建注释的标识
- 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);
- }
- //注释工具按钮悬浮文案
- private void InitToolTipDict()
- {
- ToolTipDict.Add("Hand", "滚动工具");
- ToolTipDict.Add("BtnSelecttool", "内容选择工具");
- ToolTipDict.Add("SnapshotEdit", "内容选择工具");
- ToolTipDict.Add("HighLight", "高亮" + " | Ctrl+Alt+H");
- ToolTipDict.Add("UnderLine", "高亮" + " | Ctrl+Alt+U");
- ToolTipDict.Add("Squiggly", "波浪线" + " | Ctrl+Alt+Q");
- ToolTipDict.Add("Strikeout", "删除线" + " | Ctrl+Alt+S");
- ToolTipDict.Add("Freehand", "手绘");
- ToolTipDict.Add("Freetext", "文字");
- ToolTipDict.Add("StickyNote", "便签");
- ToolTipDict.Add("Rect", "矩形");
- ToolTipDict.Add("Circle", "圆");
- ToolTipDict.Add("Arrow", "箭头");
- ToolTipDict.Add("Line", "线条");
- ToolTipDict.Add("Link", "超链接");
- ToolTipDict.Add("Stamp", "图章");
- ToolTipDict.Add("Image", "图片");
- ToolTipDict.Add("Signature", "签名");
- ToolTipDict.Add("ShowAnnot", "显示/隐藏注释");
- }
- //便签批注弹窗
- private void LoaedStickyNotePopup()
- {
- if (PDFViewer == null) return;
- if (customStickyPopup == null)
- {
- customStickyPopup = new StickyNotePopup();
- PDFViewer.SetStickyNotePop(customStickyPopup);
- }
- }
- #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"://图章
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- annotArgs = GetStamp();
- break;
- case "Image":
- annotArgs = GetImage();
- break;
- case "Signature"://签名
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- annotArgs = GetSignature();
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "Link"://链接
- //付费锁
- if (!App.IsLogin)
- {
- dialogs.ShowDialog(DialogNames.IAPCompareDialog);
- return;
- }
- propertyPanel.IsAddLink = true;
- viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
- annotArgs = GetLink();
- break;
- }
- if (annotArgs != null)
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- }
- /// <summary>
- /// 高亮注释
- /// </summary>
- private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextHighlightAnnotArgs highlightArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- highlightArgs = new TextHighlightAnnotArgs();
- highlightArgs.Transparency = highLightOpacity;
- highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(highlightArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = highlightArgs.EventType;
- defaultAnnot.ForgoundColor = (highLightColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- highLightOpacity = highlightArgs.Transparency = defaultAnnot.Opacity;
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(highlightArgs);
- }
- else
- {
- highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs);
- return highlightArgs;
- }
- /// <summary>
- /// 链接
- /// </summary>
- /// <param name="selectedArgs">所选中的注释</param>
- /// <param name="annotAttribEvent">注释属性列表</param>
- public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
- {
- LinkAnnotArgs linkArgs = new LinkAnnotArgs();
- if (selectedArgs != null && selectedArgs.Count > 0)
- {
- 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);
- }
- }
- AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribEvent);
- return linkArgs;
- }
- /// <summary>
- /// 下划线
- /// </summary>
- /// <param name="selectedArgs"></param>
- private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextUnderlineAnnotArgs underlineArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- underlineArgs = new TextUnderlineAnnotArgs();
- underlineArgs.Transparency = UnderLineOpacity;
- underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(underlineArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = underlineArgs.EventType;
- defaultAnnot.ForgoundColor = (UnderLineColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- UnderLineOpacity = underlineArgs.Transparency = defaultAnnot.Opacity;
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(underlineArgs);
- }
- else
- {
- underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs);
- return underlineArgs;
- }
- /// <summary>
- /// 波浪线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextSquigglyAnnotArgs squigglyArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squigglyArgs = new TextSquigglyAnnotArgs();
- squigglyArgs.Transparency = SquigglyOpacity;
- squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squigglyArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = squigglyArgs.EventType;
- defaultAnnot.ForgoundColor = (squigglyColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- SquigglyOpacity = squigglyArgs.Transparency = defaultAnnot.Opacity;
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squigglyArgs);
- }
- else
- {
- squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs);
- return squigglyArgs;
- }
- /// <summary>
- /// 删除线
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- TextStrikeoutAnnotArgs strikeoutArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- strikeoutArgs = new TextStrikeoutAnnotArgs();
- strikeoutArgs.Transparency = strikeoutOpacity;
- strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(strikeoutArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = strikeoutArgs.EventType;
- defaultAnnot.ForgoundColor = (strikeoutColor as SolidColorBrush).Color;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- strikeoutArgs.Transparency = defaultAnnot.Opacity;
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(strikeoutArgs);
- }
- else
- {
- strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
- }
- AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs);
- return strikeoutArgs;
- }
- /// <summary>
- /// 手绘
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- FreehandAnnotArgs freehandArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freehandArgs = new FreehandAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- freehandArgs.InkColor = annotate.FreeHandColor;
- }
- else
- {
- freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freehandArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = freehandArgs.EventType;
- defaultAnnot.ForgoundColor = annotate.FreeHandColor;
- defaultAnnot.Opacity = 1;
- defaultAnnot.Thickness = 2;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- freehandArgs.Transparency = defaultAnnot.Opacity;
- freehandArgs.LineWidth = defaultAnnot.Thickness;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- freehandArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (freehandArgs.LineDash == null)
- freehandArgs.LineDash = new DashStyle();
- freehandArgs.LineDash.Dashes = collect;
- }
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freehandArgs);
- }
- else
- {
- freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
- if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
- {
- return freehandArgs;
- }
- }
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
- return freehandArgs;
- }
- /// <summary>
- /// 文本
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- FreeTextAnnotArgs freetextArgs = null;
- TextAlignment textAlignment;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- freetextArgs = new FreeTextAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- freetextArgs.FontColor = annotate.TextAnnoteColor;
- }
- else
- {
- freetextArgs.FontColor = Colors.Black;
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = freetextArgs.EventType;
- defaultAnnot.ForgoundColor = freetextArgs.FontColor;
- defaultAnnot.BorderColor = Colors.Transparent;
- defaultAnnot.BackgroundColor = Colors.Transparent;
- defaultAnnot.Opacity = 1;
- defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
- defaultAnnot.FontSize = 14;
- defaultAnnot.TextAlign = TextAlignment.Left;
- defaultAnnot.Thickness = 0;
- defaultAnnot.NoteText = string.Empty;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- freetextArgs.FontColor = defaultAnnot.ForgoundColor;
- freetextArgs.LineColor = defaultAnnot.BorderColor;
- freetextArgs.BgColor = defaultAnnot.BackgroundColor;
- freetextArgs.Transparency = defaultAnnot.Opacity;
- freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
- freetextArgs.FontSize = defaultAnnot.FontSize;
- freetextArgs.FontWeight = defaultAnnot.FontWeight;
- freetextArgs.FontStyle = defaultAnnot.FontStyle;
- freetextArgs.LineWidth = defaultAnnot.Thickness;
- 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;
- freetextArgs.Align = textAlignment;
- if (freetextArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(freetextArgs);
- }
- }
- else
- {
- freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
- textAlignment = freetextArgs.Align;
- if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
- {
- return freetextArgs;
- }
- }
- AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
- return freetextArgs;
- }
- //Event导航到填写与签名的属性面板
- private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
- {
- if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
- {
- var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.Item1 == annots[0].PageIndex && temp.Item2 == annots[0].AnnotIndex);
- if (annotFillAndSign != null)
- {
- this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Unicode = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
- return true;
- }
- }
- return false;
- }
- private void FromFillAndSign(FillAndSigntEventArgs obj)
- {
- if (obj != null)
- {
- if (string.IsNullOrEmpty(obj.Unicode) == false)
- {
- if (obj.Unicode == "Clear")
- {
- AnnotSignatures.Clear();
- }
- }
- }
- }
- /// <summary>
- /// 便签
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
- }
- else
- {
- stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
- if (stickyAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(stickyAnnotArgs);
- }
- }
- else
- {
- stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
- }
- List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stickyAnnotArgs != null)
- stickyAnnotArgsList.Add(stickyAnnotArgs);
- AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
- return stickyAnnotArgs;
- }
- /// <summary>
- /// 矩形
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- SquareAnnotArgs squareArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- squareArgs = new SquareAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- squareArgs.BgColor = annotate.RectangleFillColor;
- squareArgs.LineColor = annotate.RectangleBorderColor;
- }
- else
- {
- squareArgs.LineColor = Colors.Red;
- squareArgs.BgColor = Colors.Red;
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = squareArgs.EventType;
- defaultAnnot.Thickness = 1;
- defaultAnnot.Opacity = 1;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- squareArgs.LineWidth = defaultAnnot.Thickness;
- squareArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- squareArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (squareArgs.LineDash == null)
- squareArgs.LineDash = new DashStyle();
- squareArgs.LineDash.Dashes = collect;
- }
- if (squareArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(squareArgs);
- }
- }
- else
- {
- squareArgs = selectedArgs[0] as SquareAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
- return squareArgs;
- }
- /// <summary>
- /// 圆
- /// </summary>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- CircleAnnotArgs circleAnnotArgs = null;
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- circleAnnotArgs = new CircleAnnotArgs();
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- circleAnnotArgs.LineColor = annotate.CircleBorderColor;
- circleAnnotArgs.BgColor = annotate.CircleFillColor;
- }
- else
- {
- circleAnnotArgs.LineColor = Colors.Red;
- circleAnnotArgs.BgColor = Colors.Red;
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
- defaultAnnot.Thickness = 1;
- defaultAnnot.Opacity = 1;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.DashArray = null;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
- circleAnnotArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- circleAnnotArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (circleAnnotArgs.LineDash == null)
- circleAnnotArgs.LineDash = new DashStyle();
- circleAnnotArgs.LineDash.Dashes = collect;
- }
- if (circleAnnotArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(circleAnnotArgs);
- }
- }
- else
- {
- circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
- return circleAnnotArgs;
- }
- /// <summary>
- /// 箭头 线
- /// </summary>
- /// <param name="TagStr"></param>
- /// <param name="selectedArgs"></param>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
- {
- LineAnnotArgs lineArgs = new LineAnnotArgs();
- if (selectedArgs == null || selectedArgs.Count == 0)
- {
- var annotate = Settings.Default.AppProperties.Annotate;
- if (annotate != null)
- {
- lineArgs.LineColor = annotate.LineColor;
- }
- else
- {
- lineArgs.LineColor = Colors.Red;
- }
- 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;
- }
- var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
- if (defaultAnnot == null)
- {
- defaultAnnot = new DefaultAnnotProperty();
- defaultAnnot.AnnotToolType = lineArgs.EventType;
- defaultAnnot.Thickness = 1;
- defaultAnnot.Opacity = 1;
- defaultAnnot.NoteText = string.Empty;
- defaultAnnot.DashArray = null;
- SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
- Settings.Default.Save();
- }
- lineArgs.LineDash = DashStyles.Solid;
- lineArgs.LineWidth = defaultAnnot.Thickness;
- lineArgs.Transparency = defaultAnnot.Opacity;
- if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
- {
- lineArgs.LineDash = DashStyles.Solid;
- }
- else
- {
- var collect = new DoubleCollection();
- foreach (var item in defaultAnnot.DashArray)
- {
- collect.Add(item);
- }
- if (lineArgs.LineDash == null)
- lineArgs.LineDash = new DashStyle();
- lineArgs.LineDash.Dashes = collect;
- }
- if (lineArgs != null)
- {
- selectedArgs = new List<AnnotHandlerEventArgs>();
- selectedArgs.Add(lineArgs);
- }
- }
- else
- {
- lineArgs = selectedArgs[0] as LineAnnotArgs;
- }
- AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
- return lineArgs;
- }
- /// <summary>
- /// 图章
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetStamp()
- {
- StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
- stampAnnotArgs.Opacity = 1;
- stampAnnotArgs.StampText = "APPROVED";
- stampAnnotArgs.Type = StampType.STANDARD_STAMP;
- List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
- if (stampAnnotArgs != null)
- stampAnnotArgsList.Add(stampAnnotArgs);
- AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
- return stampAnnotArgs;
- }
- /// <summary>
- /// 签名
- /// </summary>
- /// <returns></returns>
- private AnnotHandlerEventArgs GetSignature()
- {
- AddToPropertyPanel("SignatureAnnotProperty");
- return null;
- }
- private AnnotHandlerEventArgs GetImage()
- {
- 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);
- 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 菜单
- /// <summary>
- /// 空白处-右键菜单-添加注释
- /// </summary>
- /// <param name="sender"></param>
- private void AddAnnotation_Click(object sender)
- {
- if (sender is MenuItem menuItem)
- {
- AnnotHandlerEventArgs annotHandler = null;
- string str = menuItem.Tag.ToString();
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- propertyPanel.IsAddLink = false;
- propertyPanel.IsLocationLink = false;
- if (str == AddAnnotType.AnnotFreehand.ToString())
- {
- annotHandler = GetFreehand();
- }
- if (str == AddAnnotType.AnnotFreeText.ToString())
- {
- annotHandler = GetFreetext();
- }
- if (str == AddAnnotType.AnnotSticky.ToString())
- {
- annotHandler = GetStickyNote();
- }
- if (str == AddAnnotType.AnnotSquare.ToString())
- {
- annotHandler = GetRect();
- }
- if (str == AddAnnotType.AnnotCircle.ToString())
- {
- annotHandler = GetCircle();
- }
- if (str == AddAnnotType.AnnotArrow.ToString())
- {
- annotHandler = GetArrowLine("Arrow");
- }
- if (str == AddAnnotType.AnnotLine.ToString())
- {
- annotHandler = GetArrowLine("Line");
- }
- if (str == AddAnnotType.AnnotLink.ToString())
- {
- propertyPanel.IsAddLink = true;
- annotHandler = GetLink();
- }
- if (str == AddAnnotType.AnnotStamp.ToString())
- {
- annotHandler = GetStamp();
- }
- if (str == AddAnnotType.AnnotAutograph.ToString())
- {
- annotHandler = GetSignature();
- }
- if (annotHandler != null)
- {
- annotHandler.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotHandler);
- //是否展开右侧面板 =>否(链接、图章、签名除外)
- ShowPropertyPanel(false);
- if (str == AddAnnotType.AnnotLink.ToString()
- || str == AddAnnotType.AnnotStamp.ToString()
- || str == AddAnnotType.AnnotAutograph.ToString()
- )
- {
- ShowPropertyPanel(true);
- }
- IsNoSelectMenu = true;
- }
- }
- }
- private bool InBookModeSetIsEnabled(MenuItem menuItem)
- {
- if (viewContentViewModel.mainViewModel.IsBookMode)
- {
- menuItem.IsEnabled = false;
- return true;
- }
- else
- {
- menuItem.IsEnabled = true;
- return false;
- }
- }
- /// <summary>
- /// 选择文本、图片,右键菜单
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- List<TextSelectNode> textSelectNodes = PDFViewer.GetSelectTextInfo();
- //stickyAnnotArgs.ClientRect = new Rect(textSelectNodes[0].StartPoint.X, annotCommand.TextRect.Y - annotCommand.TextRect.Height, annotCommand.TextRect.Width, annotCommand.TextRect.Height);
- Rect rect = annotCommand.TextRectList[0];
- #region to do 转dpi
- //int dpi = DpiHelpers.Dpi;
- //double x = rect.X / 72D * dpi;
- //double y = (rect.Y - rect.Height) / 72D * dpi;
- //double width = rect.Width / 72D * dpi;
- //double height = rect.Height / 72D * dpi;
- #endregion to do 转dpi
- //stickyAnnotArgs.ClientRect = new Rect(x, y, width, height);
- //stickyAnnotArgs.ClientRect = new Rect(rect.X, rect.Y - rect.Height, rect.Width, rect.Height);
- stickyAnnotArgs.ClientRect = rect;
- //PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
- NavigationParameters param = new NavigationParameters();
- param.Add(ParameterNames.PDFViewer, PDFViewer);
- param.Add(ParameterNames.StickyAnnotArgs, stickyAnnotArgs);
- param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
- param.Add(ParameterNames.AnnotCommandArgs, annotCommand);
- ContentControl window = null;
- if (PDFViewer.Parent as ContentControl != null)
- {
- window = PDFViewer.Parent as ContentControl;
- }
- else
- {
- window = App.Current.MainWindow;
- }
- var point = Mouse.GetPosition(window);
- viewContentViewModel.NotePopupVisible = Visibility.Visible;
- viewContentViewModel.CanvasNoteLeft = point.X;
- viewContentViewModel.CanvasNoteBottom = point.Y;
- if (point.Y > window.ActualHeight / 2)
- {
- viewContentViewModel.CanvasNoteBottom = point.Y - window.ActualHeight / 2;
- }
- viewContentViewModel.IsNoteAdd = true;
- region.RequestNavigate(viewContentViewModel.NotePopupRegionName, "StickyNotePopup", param);
- //stickyAnnotArgs.Author = Settings.Default.AppProperties.Description.Author;
- //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- //PDFViewer.SetToolParam(stickyAnnotArgs);
- //PDFViewer.SetMouseMode(MouseModes.PanTool);
- 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);
- propertyPanel.IsAddLink = true;
- 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;
- }
- outLineControl.AddOutlineNode(str);
- }
- 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();
- }
- }
- #region 注释右键菜单事件
- //高亮、下划线、删除
- private void HightAnnotCopyText_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- System.Windows.Clipboard.SetText(annot.Content);
- }
- }
- }
- //更改为当前注释属性默认值
- private void AnnotDefaultValues_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- if (annot is TextHighlightAnnotArgs)
- {
- var color = (annot as TextHighlightAnnotArgs).Color;
- HighLightColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.HighLightColor = color;
- var hightlight = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
- hightlight.ForgoundColor = color;
- hightlight.Opacity = (annot as TextHighlightAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(hightlight);
- }
- else if (annot is TextUnderlineAnnotArgs)
- {
- var color = (annot as TextUnderlineAnnotArgs).Color;
- UnderLineColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.UnderLineColor = color;
- var Underline = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
- Underline.ForgoundColor = color;
- Underline.Opacity = (annot as TextUnderlineAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(Underline);
- }
- else if (annot is TextStrikeoutAnnotArgs)
- {
- var color = (annot as TextStrikeoutAnnotArgs).Color;
- StrikeoutColor = new SolidColorBrush(color);
- Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
- var Strikeout = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
- Strikeout.ForgoundColor = color;
- Strikeout.Opacity = (annot as TextStrikeoutAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(Strikeout);
- }
- else if (annot is FreehandAnnotArgs)
- {
- var freeHand = annot as FreehandAnnotArgs;
- var color = freeHand.InkColor;
- Settings.Default.AppProperties.Annotate.FreeHandColor = color;
- var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
- FreehandDefault.ForgoundColor = color;
- FreehandDefault.Opacity = freeHand.Transparency;
- FreehandDefault.Thickness = freeHand.LineWidth;
- var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
- if (isSolid)
- {
- FreehandDefault.DashArray = null;
- }
- else
- {
- FreehandDefault.DashArray = new List<double>();
- foreach (var item in freeHand.LineDash.Dashes)
- {
- FreehandDefault.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
- }
- else if (annot is FreeTextAnnotArgs)
- {
- var freeText = annot as FreeTextAnnotArgs;
- Settings.Default.AppProperties.Annotate.TextAnnoteColor = freeText.FontColor;
- Settings.Default.AppProperties.Annotate.TextFontFamaily = freeText.FontFamily.ToString();
- Settings.Default.AppProperties.Annotate.TextAlign = freeText.Align;
- var FreeTextDefalut = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
- FreeTextDefalut.ForgoundColor = freeText.FontColor;
- FreeTextDefalut.FontFamily = freeText.FontFamily.ToString();
- FreeTextDefalut.TextAlign = freeText.Align;
- FreeTextDefalut.FontSize = freeText.FontSize;
- FreeTextDefalut.FontWeight = freeText.FontWeight;
- FreeTextDefalut.FontStyle = freeText.FontStyle;
- FreeTextDefalut.BackgroundColor = freeText.BgColor;
- FreeTextDefalut.Opacity = (annot as FreeTextAnnotArgs).Transparency;
- SettingHelper.SetAnnotDefaultProperty(FreeTextDefalut);
- }
- else if (annot is StickyAnnotArgs)
- {
- var color = (annot as StickyAnnotArgs).Color;
- Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
- var StickyDefalut = GetAnnotDefault(AnnotArgsType.AnnotSticky);
- StickyDefalut.ForgoundColor = color;
- SettingHelper.SetAnnotDefaultProperty(StickyDefalut);
- }
- else if (annot is SquareAnnotArgs)
- {
- var square = annot as SquareAnnotArgs;
- var bgColor = square.BgColor;
- Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
- var borderColor = square.LineColor;
- Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
- var SquareDefalut = GetAnnotDefault(AnnotArgsType.AnnotSquare);
- SquareDefalut.BorderColor = borderColor;
- SquareDefalut.BackgroundColor = bgColor;
- SquareDefalut.Opacity = square.Transparency;
- SquareDefalut.Thickness = square.LineWidth;
- var isSolid = AnnotPropertyPanel.IsSolidStyle(square.LineDash);
- if (isSolid)
- {
- SquareDefalut.DashArray = null;
- }
- else
- {
- SquareDefalut.DashArray = new List<double>();
- foreach (var item in square.LineDash.Dashes)
- {
- SquareDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(SquareDefalut);
- }
- else if (annot is CircleAnnotArgs)
- {
- var circle = annot as CircleAnnotArgs;
- var bgColor = circle.BgColor;
- Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
- var borderColor = circle.LineColor;
- Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
- var CircleDefalut = GetAnnotDefault(AnnotArgsType.AnnotCircle);
- CircleDefalut.BorderColor = borderColor;
- CircleDefalut.BackgroundColor = bgColor;
- CircleDefalut.Opacity = circle.Transparency;
- CircleDefalut.Thickness = circle.LineWidth;
- var isSolid = AnnotPropertyPanel.IsSolidStyle(circle.LineDash);
- if (isSolid)
- {
- CircleDefalut.DashArray = null;
- }
- else
- {
- CircleDefalut.DashArray = new List<double>();
- foreach (var item in circle.LineDash.Dashes)
- {
- CircleDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(CircleDefalut);
- }
- else if (annot is LineAnnotArgs)
- {
- var line = (annot as LineAnnotArgs);
- var color = (annot as LineAnnotArgs).LineColor;
- Settings.Default.AppProperties.Annotate.LineColor = color;
- var lineDefalut = GetAnnotDefault(AnnotArgsType.AnnotLine);
- lineDefalut.BorderColor = color;
- lineDefalut.Opacity = (annot as LineAnnotArgs).Transparency;
- lineDefalut.Thickness = (annot as LineAnnotArgs).LineWidth;
- var isSolid = AnnotPropertyPanel.IsSolidStyle(line.LineDash);
- if (isSolid)
- {
- lineDefalut.DashArray = null;
- }
- else
- {
- lineDefalut.DashArray = new List<double>();
- foreach (var item in line.LineDash.Dashes)
- {
- lineDefalut.DashArray.Add(item);
- }
- }
- SettingHelper.SetAnnotDefaultProperty(lineDefalut);
- }
- Settings.Default.Save();
- }
- }
- }
- private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
- {
- var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
- if (Annot == null)
- {
- Annot = new DefaultAnnotProperty();
- Annot.AnnotToolType = annotArgsType;
- }
- return Annot;
- }
- private System.Windows.Controls.Primitives.Popup popup = null;
- //更改颜色
- private async void AnnotColorPalette_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var item = new ColorDropBoxPop();
- item.DataContext = menu;
- item.ColorSelected -= AnnotMenu_ColorSelected;
- item.ColorSelected += AnnotMenu_ColorSelected;
- if (popup == null)
- popup = new System.Windows.Controls.Primitives.Popup();
- ContentControl window = null;
- if (PDFViewer.Parent as ContentControl != null)
- window = PDFViewer.Parent as ContentControl;
- else
- window = App.Current.MainWindow;
- popup.Child = item;
- popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
- popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
- popup.PlacementTarget = window;
- popup.IsOpen = true;
- Window parentWnd = Window.GetWindow(App.Current.MainWindow);
- if (parentWnd != null)
- {
- parentWnd.MouseDown -= parentWnd_MouseDown;
- parentWnd.MouseDown += parentWnd_MouseDown;
- }
- while (popup.IsOpen)
- await Task.Delay(20);
- parentWnd.MouseDown -= parentWnd_MouseDown;
- popup = null;
- }
- }
- }
- private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
- {
- var ui = Mouse.DirectlyOver as FrameworkElement;
- if (ui != null)
- {
- if (popup != null)
- {
- popup.IsOpen = false;
- }
- }
- }
- private void AnnotMenu_ColorSelected(object sender, Color e)
- {
- if (sender != null)
- {
- var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
- if (menu == null) return;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is FreeTextAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "FontColor")
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
- else
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "FillColor")
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
- else
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- }
- //添加笔记
- private void AnnotAddNoteText_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- PopAnnotNoteText(annot);
- }
- }
- private void PopAnnotNoteText(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
- args.ClientRect = annot.ClientRect;
- args.AnnotHandlerEventArgs = annot;
- args.PageIndex = annot.PageIndex;
- args.AnnotIndex = annot.AnnotIndex;
- args.EventType = annot.EventType;
- args.CreateTime = annot.CreateTime;
- args.UpdateTime = annot.UpdateTime;
- args.Content = annot.Content;
- args.MarkupContent = annot.MarkupContent;
- args.Author = annot.Author;
- args.Locked = annot.Locked;
- args.ReadOnly = annot.ReadOnly;
- args.FormField = annot.FormField;
- args.Document = PDFViewer.Document;
- DialogParameters value = new DialogParameters();
- value.Add(ParameterNames.Annotation, args);
- dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
- {
- if (e.Result == ButtonResult.OK && e.Parameters != null)
- {
- PDFViewer.UndoManager.CanSave = true;
- if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
- {
- }
- }
- });
- }
- }
- //手绘
- private void FreeHandLineStyle_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as FreehandAnnotArgs;
- if (annot != null)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (menu.tag.ToString() == "Solid")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(true));
- }
- else
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotPropertyPanel.GetLineDashStyle(false));
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- //文本
- private void FreeTextFontFamily_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void FreeTextAglin_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Left")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
- }
- else if (strTag == "Center")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
- }
- else if (strTag == "Right")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
- }
- else if (strTag == "Justify")
- {
- AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- //便签
- private void StrikeNoteEditStrike_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- if (annot != null)
- {
- var sticky = annot as StickyAnnotArgs;
- sticky.PopupEditWnd();
- #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- //isRightMenuAddAnnot = false;
- #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- }
- }
- }
- //形状
- private void ShapeLineStyle_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as AnnotHandlerEventArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Solid")
- {
- var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
- }
- else
- {
- var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
- AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
- }
- AnnotEvent?.UpdateAnnot();
- }
- }
- }
- private void ShapeLineDirect_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as LineAnnotArgs;
- var tag = menu.control.Tag;
- if (annot != null && tag != null)
- {
- var strTag = tag.ToString();
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- if (strTag == "Ver")
- {
- annot.SetLineVertical();
- }
- else
- {
- annot.SetLineHorizontal();
- }
- }
- }
- }
- private void Link_Menu(object obj)
- {
- if (obj is CusMenuItem menuItem)
- {
- if (menuItem.Parameter is LinkAnnotArgs linkAnnotArgs)
- {
- var result = PDFViewer.RemovePageAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex);
- if (result)
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- viewModel.UpdateModifiedAnnot(linkAnnotArgs.PageIndex, linkAnnotArgs.AnnotIndex, true);
- }
- }
- }
- }
- }
- }
- //图章
- private void StampExportPicture_Menu(object obj)
- {
- if (obj as CusMenuItem != null)
- {
- var menu = obj as CusMenuItem;
- var annot = menu.Parameter as StampAnnotArgs;
- if (annot != null)
- {
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- var format = menu.tag.ToString();
- if (format == "PDF")
- dlg.Filter = "PDF|*.pdf";
- else
- dlg.Filter = format + "|*." + format.ToLower();
- dlg.DefaultExt = "." + menu.tag.ToString().ToLower();
- dlg.FileName = PDFViewer.Document.FileName;
- if (dlg.ShowDialog() == true)
- {
- var stampPicture = dlg.FileName;
- if (menu.tag.ToString() == "PDF")
- {
- var writeStamp = annot.GetStampDrawing();
- var tempDoc = new CPDFViewer();
- tempDoc.CreateDocument();
- if (tempDoc.Document == null)
- {
- AlertsMessage alertsMessage = new AlertsMessage();
- alertsMessage.ShowDialog("", "创建文件失败.", "OK");
- return;
- }
- byte[] buffer;
- var encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(writeStamp));
- using (var memoryStream = new MemoryStream())
- {
- encoder.Save(memoryStream);
- buffer = memoryStream.ToArray();
- }
- tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
- var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
- if (result)
- {
- }
- }
- else
- {
- var writeStamp = annot.GetStampDrawing();
- using (FileStream stream5 = new FileStream(stampPicture, FileMode.Create))
- {
- PngBitmapEncoder encoder5 = new PngBitmapEncoder();
- encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
- encoder5.Save(stream5);
- }
- }
- }
- }
- }
- }
- #endregion 注释右键菜单事件
- #endregion 菜单
- }
- }
|