ViewContentViewModel.cs 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583
  1. using Microsoft.Win32;
  2. using Prism.Commands;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Threading.Tasks;
  7. using ComPDFKitViewer.PdfViewer;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using PDF_Master.CustomControl;
  11. using PDF_Master.Model;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.IO;
  15. using ComPDFKitViewer.AnnotEvent;
  16. using PDF_Master.ViewModels.Tools;
  17. using Prism.Events;
  18. using PDF_Master.EventAggregators;
  19. using PDF_Master.Helper;
  20. using ComPDFKit.PDFDocument;
  21. using PDFSettings;
  22. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  23. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.SetPasswordDialogModel;
  24. using PDF_Master.Model.Dialog.ToolsDialogs;
  25. using DryIoc;
  26. using PDF_Master.Model.Dialog.ConverterDialogs;
  27. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  28. using PDF_Master.Views.PropertyPanel.AnnotPanel;
  29. using System.Linq;
  30. using System.Text;
  31. using PDF_Master.Views.Tools;
  32. using System.Windows.Input;
  33. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  34. using ImTools;
  35. using PDF_Master.Properties;
  36. using PDF_Master.ViewModels.BOTA;
  37. using PDF_Master.Views.BOTA;
  38. using System.Drawing;
  39. using PDF_Master.ViewModels.Tools.AnnotManager;
  40. using PDF_Master.Model.FillAndSign;
  41. using PDF_Master.Views.PropertyPanel.ViewModular;
  42. using PDF_Master.Views.PropertyPanel;
  43. using System.Windows.Threading;
  44. using Dropbox.Api.Files;
  45. using System.Windows.Media;
  46. using Color = System.Windows.Media.Color;
  47. using PDFSettings;
  48. using PDF_Master.Views;
  49. using System.Windows.Documents;
  50. using ComPDFKit.PDFPage;
  51. using ComPDFKitViewer;
  52. using SplitMode = PDF_Master.EventAggregators.SplitMode;
  53. using System.Windows.Resources;
  54. using System.Windows.Media.Imaging;
  55. using ComPDFKit.PDFWatermark;
  56. using PDF_Master.ViewModels.PageEdit;
  57. using System.Windows.Annotations;
  58. namespace PDF_Master.ViewModels
  59. {
  60. public class ViewContentViewModel : BindableBase, INavigationAware
  61. {
  62. #region 文案
  63. private string T_file;
  64. public string T_File
  65. {
  66. get { return T_file; }
  67. set
  68. {
  69. SetProperty(ref T_file, value);
  70. }
  71. }
  72. private string T_save;
  73. public string T_Save
  74. {
  75. get { return T_save; }
  76. set
  77. {
  78. SetProperty(ref T_save, value);
  79. }
  80. }
  81. private string T_undo;
  82. public string T_Undo
  83. {
  84. get { return T_undo; }
  85. set
  86. {
  87. SetProperty(ref T_undo, value);
  88. }
  89. }
  90. private string T_redo;
  91. public string T_Redo
  92. {
  93. get { return T_redo; }
  94. set
  95. {
  96. SetProperty(ref T_redo, value);
  97. }
  98. }
  99. private string T_annotation;
  100. public string T_Annotation
  101. {
  102. get { return T_annotation; }
  103. set
  104. {
  105. SetProperty(ref T_annotation, value);
  106. }
  107. }
  108. private string T_pageEdit;
  109. public string T_PageEdit
  110. {
  111. get { return T_pageEdit; }
  112. set
  113. {
  114. SetProperty(ref T_pageEdit, value);
  115. }
  116. }
  117. private string T_converter;
  118. public string T_Converter
  119. {
  120. get { return T_converter; }
  121. set
  122. {
  123. SetProperty(ref T_converter, value);
  124. }
  125. }
  126. private string T_fillSign;
  127. public string T_FillSign
  128. {
  129. get { return T_fillSign; }
  130. set
  131. {
  132. SetProperty(ref T_fillSign, value);
  133. }
  134. }
  135. private string T_tools;
  136. public string T_Tools
  137. {
  138. get { return T_tools; }
  139. set
  140. {
  141. SetProperty(ref T_tools, value);
  142. }
  143. }
  144. private string T_print;
  145. public string T_Print
  146. {
  147. get { return T_print; }
  148. set
  149. {
  150. SetProperty(ref T_print, value);
  151. }
  152. }
  153. private string T_share;
  154. public string T_Share
  155. {
  156. get { return T_share; }
  157. set
  158. {
  159. SetProperty(ref T_share, value);
  160. }
  161. }
  162. private string T_properties;
  163. public string T_Properties
  164. {
  165. get { return T_properties; }
  166. set
  167. {
  168. SetProperty(ref T_properties, value);
  169. }
  170. }
  171. private string _T_EditPDF;
  172. public string T_EditPDF
  173. {
  174. get { return _T_EditPDF; }
  175. set
  176. {
  177. SetProperty(ref _T_EditPDF, value);
  178. }
  179. }
  180. private void InitStirng()
  181. {
  182. T_File = App.MainPageLoader.GetString("ViewTopToolbar_File");
  183. T_Save = App.MainPageLoader.GetString("ViewTopToolbar_Save");
  184. T_Undo = App.MainPageLoader.GetString("ViewTopToolbar_Undo");
  185. T_Redo = App.MainPageLoader.GetString("ViewTopToolbar_Redo");
  186. T_Annotation = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
  187. T_PageEdit = App.MainPageLoader.GetString("ViewTopToolbar_PageEdit");
  188. T_EditPDF = App.MainPageLoader.GetString("ViewTopToolbar_T_EditPDF");
  189. T_Converter = App.MainPageLoader.GetString("ViewTopToolbar_Converter");
  190. T_FillSign = App.MainPageLoader.GetString("ViewTopToolbar_Fill&Sign");
  191. T_Tools = App.MainPageLoader.GetString("ViewTopToolbar_Tools");
  192. T_Print = App.MainPageLoader.GetString("ViewTopToolbar_Print");
  193. T_Share = App.MainPageLoader.GetString("ViewTopToolbar_Share");
  194. T_Properties = App.MainPageLoader.GetString("ViewTopToolbar_Properties");
  195. }
  196. #endregion 文案
  197. #region 属性、变量
  198. /// <summary>
  199. /// 显示 隐藏注释
  200. /// </summary>
  201. public bool IsHiddenAnnot = false;
  202. public bool IsMultiSelected { get; set; } = false;
  203. public OpenFileInfo OpenFileInfo = null;
  204. public CPDFViewer PDFViewer { get; set; }
  205. public bool ReadModeIsShowProperty { get; set; } = false;
  206. public MainContentViewModel mainViewModel { get; set; }
  207. public BottomToolContentViewModel bottom { get; set; }
  208. public BOTAContentViewModel botaViewModel { get; set; }
  209. private CPDFWatermark watermark;
  210. public bool IsSettingOut = false;
  211. public IRegionManager region;
  212. public IDialogService dialogs;
  213. public IEventAggregator events;
  214. public bool IsRightMenuCreateLink { get => isCreateLink; set => isCreateLink = value; }
  215. public string ViwerRegionName { get; set; }
  216. /// <summary>
  217. /// 分屏视图的region名称
  218. /// </summary>
  219. public string SplitViewerRegionName { get; set; }
  220. /// <summary>
  221. /// OCR视图名称
  222. /// </summary>
  223. public string OCRViewerRegionName { get; set; }
  224. public string BOTARegionName { get; set; }
  225. public string PropertyRegionName { get; set; }
  226. public string ToolContentRegionName { get; set; }
  227. public string ToolsBarContentRegionName { get; set; }
  228. /// <summary>
  229. /// 顶部提示的Content
  230. /// </summary>
  231. public string TipContentRegionName { get; set; }
  232. public string LeftTipContentRegionName { get; set; }
  233. //便签弹窗
  234. public string NotePopupRegionName { get; set; }
  235. public string ReadModeRegionName { get; set; }
  236. public string TextEditContentRegionName { get; set; }
  237. public string BackgroundContentRegionName { get; set; }
  238. public PasswordInfo PasswordInfo = new PasswordInfo();
  239. //若point不赋值或从列表中找不到point,系统会提供默认值为(0,0)的新point,所以改用Tuple<int,int>
  240. public List<FillAndSignIsShape> FillAndSign = new List<FillAndSignIsShape>();
  241. /// <summary>
  242. /// 签名列表
  243. /// </summary>
  244. public List<Tuple<int, int>> AnnotSignatures = new List<Tuple<int, int>>();
  245. /// <summary>
  246. /// 文档的密码
  247. /// </summary>
  248. public string PassWord { get; set; }
  249. public PasswordInfo passwordInfo = new PasswordInfo();
  250. private Visibility tipVisible = Visibility.Collapsed;
  251. /// <summary>
  252. /// 顶部提示栏的显示状态
  253. /// </summary>
  254. public bool IsFileLocked = false;
  255. public Visibility TipVisible
  256. {
  257. get { return tipVisible; }
  258. set
  259. {
  260. SetProperty(ref tipVisible, value);
  261. }
  262. }
  263. private Visibility leftTipVisible = Visibility.Collapsed;
  264. public Visibility LeftTipVisible
  265. {
  266. get { return leftTipVisible; }
  267. set
  268. {
  269. SetProperty(ref leftTipVisible, value);
  270. }
  271. }
  272. private Visibility notePopupVisible = Visibility.Collapsed;
  273. public Visibility NotePopupVisible
  274. {
  275. get { return notePopupVisible; }
  276. set
  277. {
  278. SetProperty(ref notePopupVisible, value);
  279. }
  280. }
  281. public bool IsNoteAdd = false;
  282. private double canvasNoteLeft;
  283. public double CanvasNoteLeft
  284. {
  285. get { return canvasNoteLeft; }
  286. set
  287. {
  288. SetProperty(ref canvasNoteLeft, value);
  289. }
  290. }
  291. private double canvasNoteBottom;
  292. public double CanvasNoteBottom
  293. {
  294. get { return canvasNoteBottom; }
  295. set
  296. {
  297. SetProperty(ref canvasNoteBottom, value);
  298. }
  299. }
  300. /// <summary>
  301. /// 底部工具栏 RegionName
  302. /// </summary>
  303. public string BottomToolRegionName { get; set; }
  304. private bool _isInPageEdit = false;
  305. /// <summary>
  306. /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
  307. /// </summary>
  308. public bool isInPageEdit
  309. {
  310. get { return _isInPageEdit; }
  311. set
  312. {
  313. SetProperty(ref _isInPageEdit, value);
  314. }
  315. }
  316. public Action PageEditUndo { get; set; }
  317. public Action PageEditRedo { get; set; }
  318. /// <summary>
  319. ///工具条
  320. ///0:收起
  321. ///40:显示
  322. /// </summary>
  323. private int toolRowHeight = 40;
  324. public int ToolRowHeight
  325. {
  326. get { return toolRowHeight; }
  327. set
  328. {
  329. SetProperty(ref toolRowHeight, value);
  330. }
  331. }
  332. private GridLength _ToolTooRow = new GridLength(40);
  333. public GridLength ToolTooRow
  334. {
  335. get { return _ToolTooRow; }
  336. set
  337. {
  338. SetProperty(ref _ToolTooRow, value);
  339. }
  340. }
  341. /// <summary>
  342. /// 水印,背景侧边栏宽度
  343. /// 0:收起
  344. /// 260:显示
  345. /// </summary>
  346. private int propertyColumnWidth = 0;
  347. public int PropertyColumnWidth
  348. {
  349. get { return propertyColumnWidth; }
  350. set
  351. {
  352. SetProperty(ref propertyColumnWidth, value);
  353. }
  354. }
  355. private int gridToolRow = 1;
  356. /// <summary>
  357. /// 控制ToolContent的Row
  358. /// </summary>
  359. public int GridToolRow
  360. {
  361. get { return gridToolRow; }
  362. set
  363. {
  364. SetProperty(ref gridToolRow, value);
  365. }
  366. }
  367. private int gridToolRowSpan = 3;
  368. /// <summary>
  369. /// 控制ToolContent的RowSpan
  370. /// </summary>
  371. public int GridToolRowSpan
  372. {
  373. get { return gridToolRowSpan; }
  374. set
  375. {
  376. SetProperty(ref gridToolRowSpan, value);
  377. }
  378. }
  379. private Visibility toolContentVisible = Visibility.Collapsed;
  380. /// <summary>
  381. /// 控制Content的显示 用于显示水印、贝茨码、密文等功能模块
  382. /// 留意:显示前需要先注入内容、设置好行和跨行数
  383. /// </summary>
  384. public Visibility ToolContentVisible
  385. {
  386. get { return toolContentVisible; }
  387. set
  388. {
  389. SetProperty(ref toolContentVisible, value);
  390. }
  391. }
  392. private Visibility gridVisibility = Visibility.Visible;
  393. /// <summary>
  394. /// 是否正在加载中
  395. /// </summary>
  396. public Visibility GridVisibility
  397. {
  398. get { return gridVisibility; }
  399. set
  400. {
  401. SetProperty(ref gridVisibility, value);
  402. }
  403. }
  404. private Visibility isLoading = Visibility.Collapsed;
  405. private Visibility ocrContentVisible = Visibility.Collapsed;
  406. public Visibility OCRContentVisible
  407. {
  408. get { return ocrContentVisible; }
  409. set
  410. {
  411. SetProperty(ref ocrContentVisible, value);
  412. }
  413. }
  414. /// <summary>
  415. /// 是否正在加载中
  416. /// </summary>
  417. public Visibility IsLoading
  418. {
  419. get { return isLoading; }
  420. set
  421. {
  422. SetProperty(ref isLoading, value);
  423. }
  424. }
  425. private Visibility converterBarContentVisible = Visibility.Collapsed;
  426. private Visibility toolsbarContentVisible = Visibility.Collapsed;
  427. ///// <summary>
  428. ///// 控制ToolsBarContent的显示
  429. ///// 留意:显示前需要先注入内容、设置好行和跨行数
  430. ///// </summary>
  431. //public Visibility ConverterBarContentVisible
  432. //{
  433. // get { return converterBarContentVisible; }
  434. // set
  435. // {
  436. // SetProperty(ref converterBarContentVisible, value);
  437. // }
  438. //}
  439. private Visibility toolsBarContentVisible = Visibility.Collapsed;
  440. /// <summary>
  441. /// 控制ToolsBarContent的显示
  442. /// 留意:显示前需要先注入内容、设置好行和跨行数
  443. /// </summary>
  444. public Visibility ToolsBarContentVisible
  445. {
  446. get { return toolsBarContentVisible; }
  447. set
  448. {
  449. SetProperty(ref toolsBarContentVisible, value);
  450. }
  451. }
  452. private Visibility textEditToolContentVisible = Visibility.Collapsed;
  453. /// <summary>
  454. /// 控制ToolsBarContent的显示
  455. /// 留意:显示前需要先注入内容、设置好行和跨行数
  456. /// </summary>
  457. public Visibility TextEditToolContentVisible
  458. {
  459. get { return textEditToolContentVisible; }
  460. set
  461. {
  462. SetProperty(ref textEditToolContentVisible, value);
  463. }
  464. }
  465. private bool isPorpertyOpen = false;
  466. /// <summary>
  467. /// 属性栏是否展开
  468. /// </summary>
  469. public bool IsPropertyOpen
  470. {
  471. get { return isPorpertyOpen; }
  472. set
  473. {
  474. //如果设置为手动展开属性面板时,则不响应代码控制的展开
  475. //或者手动点击按钮时 也展开
  476. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty || FromClick)
  477. {
  478. //阅读模式 不显示属性面板
  479. //if (mainViewModel.IsBookMode)
  480. //{
  481. // this.events.GetEvent<ReadModePropertyOpenEvent>().Publish(new ReadModePropertyOpenArgs() { Unicode = unicode });
  482. //}
  483. SetProperty(ref isPorpertyOpen, value);
  484. }
  485. }
  486. }
  487. /// <summary>
  488. /// 是否是点击属性面板按钮
  489. /// </summary>
  490. private bool FromClick = false;
  491. private Visibility isReadMode = Visibility.Visible;
  492. /// <summary>
  493. ///是否为阅读模式
  494. /// </summary>
  495. public Visibility IsReadMode
  496. {
  497. get { return isReadMode; }
  498. set
  499. {
  500. SetProperty(ref isReadMode, value);
  501. }
  502. }
  503. private bool canSave;
  504. /// <summary>
  505. /// 是否可以保存
  506. /// </summary>
  507. public bool CanSave
  508. {
  509. get { return canSave; }
  510. set
  511. {
  512. if (events != null && canSave == false)
  513. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = "Clear", AppUnicode = unicode });
  514. SetProperty(ref canSave, value);
  515. }
  516. }
  517. private bool canUndo;
  518. /// <summary>
  519. /// 是否可以进行Undo
  520. /// </summary>
  521. public bool CanUndo
  522. {
  523. get { return canUndo; }
  524. set
  525. {
  526. SetProperty(ref canUndo, value);
  527. }
  528. }
  529. private bool canRedo;
  530. /// <summary>
  531. /// 是否可以进行Redo
  532. /// </summary>
  533. public bool CanRedo
  534. {
  535. get { return canRedo; }
  536. set
  537. {
  538. SetProperty(ref canRedo, value);
  539. }
  540. }
  541. /// <summary>
  542. /// 定义BOTA展开后的最小宽度,小于等于该宽度时无法再缩小宽度,再往左边拖动便是收起BOTA
  543. /// </summary>
  544. public double BOTAMiniWidth = 260;
  545. private GridLength botaWidth = new GridLength(48);
  546. /// <summary>
  547. /// BOTA栏的宽度
  548. /// </summary>
  549. public GridLength BOTAWidth
  550. {
  551. get { return botaWidth; }
  552. set
  553. {
  554. SetProperty(ref botaWidth, value);
  555. if (botaWidth.Value <= 48)
  556. {
  557. OpenBOTA = false;
  558. }
  559. }
  560. }
  561. private int selectedIndex;
  562. /// <summary>
  563. /// 工具栏选中项的索引
  564. /// </summary>
  565. public int TabSelectedIndex
  566. {
  567. get { return selectedIndex; }
  568. set
  569. {
  570. SetProperty(ref selectedIndex, value);
  571. }
  572. }
  573. private bool openBOTA = false;
  574. /// <summary>
  575. /// 是否展开BOTA
  576. /// </summary>
  577. public bool OpenBOTA
  578. {
  579. get { return openBOTA; }
  580. set
  581. {
  582. SetProperty(ref openBOTA, value);
  583. if (openBOTA && BOTAWidth.Value <= 48)
  584. {
  585. BOTAWidth = new GridLength(BOTAMiniWidth);
  586. }
  587. Settings.Default.AppProperties.InitialVIew.RememberBOTA = openBOTA;
  588. //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
  589. }
  590. }
  591. public SecurityInfo SecurityInfo = new SecurityInfo();
  592. private Dictionary<string, string> regionNameByTabItem;
  593. private Dictionary<string, string> barContentByTabItem;
  594. private string previousBar = "";
  595. public string CurrentBar = "";
  596. public string unicode = null;
  597. /// <summary>
  598. /// 自动保存的定时器
  599. /// </summary>
  600. private DispatcherTimer autoSaveTimer = new DispatcherTimer();
  601. /// <summary>
  602. /// 用来避免重复触发导航事件的标志符
  603. /// </summary>
  604. private bool isOpenFile = false;
  605. /// <summary>
  606. /// 鼠标滚轮缩放的缩放值
  607. /// </summary>
  608. private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000, 2000, 4000, 10000 };
  609. /// <summary>
  610. /// 注释-链接,提示语
  611. /// </summary>
  612. private Visibility linkAnnotTipVisibility = Visibility.Collapsed;
  613. public Visibility LinkAnnotTipVisibility
  614. {
  615. get { return linkAnnotTipVisibility; }
  616. set
  617. {
  618. SetProperty(ref linkAnnotTipVisibility, value);
  619. }
  620. }
  621. private string linkAnnotTipText = "Turn to the target page, then click or box area on the page to select the target page where the link will jump.";
  622. private bool isCreateLink = false;
  623. internal bool IsRightMenuSelectedTextAddLink = false;
  624. internal bool IsSelectedTextAddLink = false;
  625. /// <summary>
  626. /// 上下左右滑动的距离
  627. /// </summary>
  628. private double scrolloffset = 50;
  629. public string LinkAnnotTipText
  630. {
  631. get { return linkAnnotTipText; }
  632. set
  633. {
  634. SetProperty(ref linkAnnotTipText, value);
  635. }
  636. }
  637. private bool botaState = false;
  638. private bool propertyOpenState = false;
  639. public bool _IsCrop = false;
  640. public bool IsCrop
  641. {
  642. get { return _IsCrop; }
  643. set
  644. {
  645. SetProperty(ref _IsCrop, value);
  646. }
  647. }
  648. #endregion 属性、变量
  649. #region 命令
  650. public DelegateCommand Load { get; set; }
  651. public DelegateCommand MouseDown { get; set; }
  652. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  653. public DelegateCommand SaveFile { get; set; }
  654. public DelegateCommand SaveAsFile { get; set; }
  655. public DelegateCommand SaveAsFlattenCommand { get; set; }
  656. public DelegateCommand UndoCommand { get; set; }
  657. public DelegateCommand RedoCommand { get; set; }
  658. public DelegateCommand<object> MenuEnterReadMode { get; set; }
  659. public DelegateCommand AITranslationCommand { get; set; }
  660. public DelegateCommand PrintCommand { get; set; }
  661. public DelegateCommand SelectCommand { get; set; }
  662. public DelegateCommand SettingsCommand { get; set; }
  663. public DelegateCommand AboutDialogCommmand { get; set; }
  664. public DelegateCommand ShareCommand { get; set; }
  665. public DelegateCommand<object> CreateLinkCommand { get; set; }
  666. public DelegateCommand PropertyCommand { get; set; }
  667. public DelegateCommand ShowInFolderCommand { get; set; }
  668. public DelegateCommand CompressCommand { get; set; }
  669. public DelegateCommand MergeFileCommand { get; set; }
  670. public DelegateCommand EncryptCommand { get; set; }
  671. public DelegateCommand DecryptCommand { get; set; }
  672. public DelegateCommand<string> ConvertCommand { get; set; }
  673. public DelegateCommand CloseWindowCommand { get; set; }
  674. public DelegateCommand OpenFileCommand { get; set; }
  675. public DelegateCommand<string> HelpCommand { get; set; }
  676. public DelegateCommand CreateBlankFileCommand { get; set; }
  677. public DelegateCommand CreateFromFile { get; set; }
  678. public DelegateCommand ClosePropertyCommand { get; set; }
  679. public DelegateCommand<object> OpenPropertyCommand { get; set; }
  680. public DelegateCommand LostFoucsCommand { get; set; }
  681. /// <summary>
  682. /// 用于底部工具栏的部分Bug
  683. /// </summary>
  684. public DelegateCommand RealSizeCommand { get; set; }
  685. public DelegateCommand OpenFullCommand { get; set; }
  686. public DelegateCommand SinglePageCommand { get; set; }
  687. public DelegateCommand DoublePageCommand { get; set; }
  688. public DelegateCommand FirstPageCommand { get; set; }
  689. public DelegateCommand LastPageCommand { get; set; }
  690. public DelegateCommand UpCommand { get; set; }
  691. public DelegateCommand DownCommand { get; set; }
  692. public DelegateCommand RightCommand { get; set; }
  693. public DelegateCommand LeftCommand { get; set; }
  694. public DelegateCommand PrePageCommand { get; set; }
  695. public DelegateCommand NextPageCommmand { get; set; }
  696. public DelegateCommand PreViewCommand { get; set; }
  697. public DelegateCommand NextViewCommand { get; set; }
  698. public DelegateCommand ZoomInCommand { get; set; }
  699. public DelegateCommand ZoomOutCommand { get; set; }
  700. //是否显示视图面板
  701. public bool IsReadModeShow { get; internal set; } = false;
  702. #endregion 命令
  703. public ViewContentViewModel(IRegionManager regionManager, IDialogService dialogService, IEventAggregator eventAggregator)
  704. {
  705. InitStirng();
  706. region = regionManager;
  707. dialogs = dialogService;
  708. events = eventAggregator;
  709. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  710. Load = new DelegateCommand(LoadControl);
  711. MouseDown = new DelegateCommand(MouseDownEvent);
  712. SaveFile = new DelegateCommand(() => { saveFile(); }, CanSaveExcute).ObservesProperty(() => CanSave);
  713. SaveAsFlattenCommand = new DelegateCommand(saveAsFlatten);
  714. SaveAsFile = new DelegateCommand(() => { saveAsFile(); });
  715. UndoCommand = new DelegateCommand(Undo);
  716. RedoCommand = new DelegateCommand(Redo);
  717. ShareCommand = new DelegateCommand(share);
  718. PropertyCommand = new DelegateCommand(property);
  719. ShowInFolderCommand = new DelegateCommand(ShowInFolder);
  720. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectonChangedEvent);
  721. CompressCommand = new DelegateCommand(compress);
  722. MergeFileCommand = new DelegateCommand(mergeFile);
  723. EncryptCommand = new DelegateCommand(encrypt);
  724. DecryptCommand = new DelegateCommand(decrypt);
  725. ConvertCommand = new DelegateCommand<string>(convert);
  726. CloseWindowCommand = new DelegateCommand(closeWindow);
  727. OpenFileCommand = new DelegateCommand(openfile);
  728. HelpCommand = new DelegateCommand<string>(help);
  729. CreateBlankFileCommand = new DelegateCommand(createBlankFile);
  730. CreateFromFile = new DelegateCommand(createfromFile);
  731. OpenPropertyCommand = new DelegateCommand<object>(openProperty);
  732. AboutDialogCommmand = new DelegateCommand(about);
  733. ViwerRegionName = RegionNames.ViwerRegionName;
  734. SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
  735. BOTARegionName = RegionNames.BOTARegionName;
  736. PropertyRegionName = RegionNames.PropertyRegionName;
  737. BottomToolRegionName = RegionNames.BottomToolRegionName;
  738. ReadModeRegionName = RegionNames.ReadModeRegionName;
  739. MenuEnterReadMode = new DelegateCommand<object>(MenuEnterReadModeEvent);
  740. AITranslationCommand = new DelegateCommand(ShowAITranslationDialog);
  741. PrintCommand = new DelegateCommand(ShowPrintDialog);
  742. SelectCommand = new DelegateCommand(SelectClick);
  743. SettingsCommand = new DelegateCommand(SettingsEvent);
  744. CreateLinkCommand = new DelegateCommand<object>(CreateLinkEvent);
  745. ClosePropertyCommand = new DelegateCommand(CloseProperty);
  746. //底部工具栏相关的命令 绑在这一层响应更快
  747. RealSizeCommand = new DelegateCommand(realsize);
  748. OpenFullCommand = new DelegateCommand(OpenFullWindow);
  749. FirstPageCommand = new DelegateCommand(firstpage);
  750. LastPageCommand = new DelegateCommand(lastpage);
  751. PreViewCommand = new DelegateCommand(preview);
  752. NextViewCommand = new DelegateCommand(nextview);
  753. PrePageCommand = new DelegateCommand(prepage);
  754. NextPageCommmand = new DelegateCommand(nextpage);
  755. ZoomInCommand = new DelegateCommand(zoomin);
  756. ZoomOutCommand = new DelegateCommand(zoomout);
  757. UpCommand = new DelegateCommand(up);
  758. DownCommand = new DelegateCommand(down);
  759. SinglePageCommand = new DelegateCommand(singlepage);
  760. DoublePageCommand = new DelegateCommand(doublepage);
  761. LeftCommand = new DelegateCommand(left);
  762. RightCommand = new DelegateCommand(right);
  763. //未显示时无法注册上Region名称
  764. ToolContentVisible = Visibility.Visible;
  765. ToolsBarContentVisible = Visibility.Visible;
  766. OCRContentVisible = Visibility.Visible;
  767. TipVisible = Visibility.Visible;
  768. TipContentRegionName = RegionNames.TipContentRegionName;
  769. LeftTipContentRegionName = RegionNames.LeftTipContentRegionName;
  770. NotePopupRegionName = RegionNames.NotePopupRegionName;
  771. OCRViewerRegionName = RegionNames.OCRViewerRegionName;
  772. ToolContentRegionName = Guid.NewGuid().ToString();
  773. ToolsBarContentRegionName = Guid.NewGuid().ToString();
  774. TextEditContentRegionName = Guid.NewGuid().ToString();
  775. ToolContentVisible = Visibility.Collapsed;
  776. ToolsBarContentVisible = Visibility.Collapsed;
  777. OCRContentVisible = Visibility.Collapsed;
  778. TipVisible = Visibility.Collapsed;
  779. regionNameByTabItem = new Dictionary<string, string>();
  780. barContentByTabItem = new Dictionary<string, string>();
  781. InitialregionNameByTabItem(ref regionNameByTabItem);
  782. InitialbarContentByTabItem(ref barContentByTabItem);
  783. eventAggregator.GetEvent<EnterSelectedEditToolEvent>().Subscribe(EnterEditTools, e => e.Unicode == unicode);
  784. eventAggregator.GetEvent<CloseEditToolEvent>().Subscribe(CloseEditTool, e => e.Unicode == unicode);
  785. eventAggregator.GetEvent<ShowTipEvent>().Subscribe(ShowSelectedTipAsync, e => e.Unicode == unicode);
  786. //TODO:根据缓存 选择用户上次选择的菜单
  787. CurrentBar = "TabItemAnnotation";
  788. EnterSelectedBar("TabItemAnnotation");
  789. StartAutoSave();
  790. }
  791. private void about()
  792. {
  793. dialogs.ShowDialog(DialogNames.AboutDialog);
  794. }
  795. private void doublepage()
  796. {
  797. bottom?.DoublePageCommand.Execute();
  798. }
  799. private void singlepage()
  800. {
  801. bottom?.SinglePageCommand.Execute();
  802. }
  803. private void down()
  804. {
  805. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() + scrolloffset);
  806. }
  807. private void up()
  808. {
  809. PDFViewer.ScrollToVerticalOffset(PDFViewer.GetVerticalOffset() - scrolloffset);
  810. }
  811. /// <summary>
  812. /// 右键逻辑
  813. /// </summary>
  814. private void right()
  815. {
  816. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  817. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  818. {
  819. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() + 50);
  820. }
  821. else
  822. {
  823. bottom?.NextPageCommand.Execute();
  824. }
  825. }
  826. /// <summary>
  827. /// 左键逻辑
  828. /// </summary>
  829. private void left()
  830. {
  831. //当延申宽度大于实际显示的宽度时,说明可以左右滚动,此时左右键不能进行翻页,而是左右滑动
  832. if (PDFViewer.GetExtendWidth() > PDFViewer.ActualWidth)
  833. {
  834. PDFViewer.ScrollToHorizontalOffset(PDFViewer.GetHorizontalOffset() - 50);
  835. }
  836. else
  837. {
  838. bottom?.PrePageCommand.Execute();
  839. }
  840. }
  841. private void zoomin()
  842. {
  843. bottom?.ZoomInCommand.Execute();
  844. }
  845. private void zoomout()
  846. {
  847. bottom?.ZoomOutCommand.Execute();
  848. }
  849. private void nextpage()
  850. {
  851. bottom?.NextPageCommand.Execute();
  852. }
  853. private void prepage()
  854. {
  855. bottom?.PrePageCommand.Execute();
  856. }
  857. private void nextview()
  858. {
  859. bottom?.NextViewCommnad.Execute();
  860. }
  861. private void preview()
  862. {
  863. bottom?.PreViewCommand.Execute();
  864. }
  865. private void lastpage()
  866. {
  867. bottom?.LastPageCommand.Execute();
  868. }
  869. private void firstpage()
  870. {
  871. bottom?.FirstPageCommand.Execute();
  872. }
  873. /// <summary>
  874. /// 底部工具栏的缩放至实际大小
  875. /// </summary>
  876. private void realsize()
  877. {
  878. bottom?.RealSizeCommand.Execute();
  879. }
  880. /// <summary>
  881. /// 进入全屏模式
  882. /// </summary>
  883. private void OpenFullWindow()
  884. {
  885. DialogParameters parameters = new DialogParameters();
  886. //因为全屏模式可能需要设置特定的页面模式,所以只传文件路径,新建一个PDFview对象
  887. parameters.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
  888. parameters.Add(ParameterNames.PassWord, PDFViewer.Tag == null ? "" : PDFViewer.Tag.ToString());
  889. dialogs.ShowDialog(DialogNames.FullScreenDialog, parameters, e =>
  890. {
  891. if (e.Result == ButtonResult.Cancel)
  892. {
  893. //TODO:弹窗提示打开全屏模式失败
  894. AlertsMessage alertsMessage = new AlertsMessage();
  895. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("OperationFailWarning"), App.ServiceLoader.GetString("Text_ok"));
  896. return;
  897. }
  898. });
  899. }
  900. /// <summary>
  901. /// 点击展开折叠属性面板
  902. /// </summary>
  903. /// <param name="obj"></param>
  904. private void openProperty(object obj)
  905. {
  906. FromClick = true;
  907. IsPropertyOpen = (bool)obj;
  908. FromClick = false;
  909. }
  910. /// <summary>
  911. /// 复制、剪切操作前校验是否有文档操作权限,没有则弹出权限解密弹窗
  912. /// </summary>
  913. /// <returns></returns>
  914. public bool CheckPermissionBeforeOption()
  915. {
  916. VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
  917. if (verifyResult.IsDiscryptied)
  918. {
  919. if (verifyResult.Password != null)
  920. {
  921. PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
  922. }
  923. ShowLeftTip(false);
  924. return true;
  925. }
  926. else
  927. {
  928. return false;
  929. }
  930. }
  931. /// <summary>
  932. /// 开始自动保存
  933. /// </summary>
  934. public void StartAutoSave()
  935. {
  936. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  937. if (autoSave)
  938. {
  939. var interval = Settings.Default.AppProperties.Description.AutoSaveInterval;
  940. if (autoSaveTimer == null)
  941. {
  942. autoSaveTimer = new DispatcherTimer();
  943. }
  944. autoSaveTimer.Stop();
  945. autoSaveTimer.Interval = TimeSpan.FromMinutes(interval);
  946. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  947. autoSaveTimer.Tick += AutoSaveTimer_Tick;
  948. autoSaveTimer.Start();
  949. }
  950. }
  951. /// <summary>
  952. /// 释放定时器
  953. /// 不释放定时器可能会一直运行并占用内存,导致内存泄露
  954. /// </summary>
  955. public void CloseAutoSave()
  956. {
  957. if (autoSaveTimer != null)
  958. {
  959. autoSaveTimer.Stop();
  960. autoSaveTimer.Tick -= AutoSaveTimer_Tick;
  961. autoSaveTimer = null;
  962. }
  963. }
  964. private void AutoSaveTimer_Tick(object sender, EventArgs e)
  965. {
  966. //未付费的用户不进行自动保存
  967. if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
  968. {
  969. return;
  970. }
  971. var autoSave = Settings.Default.AppProperties.Description.AutoSave;
  972. if (autoSave && !mainViewModel.NewFile && PDFViewer.UndoManager.CanSave)
  973. {
  974. //自动保存仅针对已经有文件路径的文档
  975. saveFile();
  976. }
  977. }
  978. private void MouseDownEvent()
  979. {
  980. if (NotePopupVisible == Visibility.Visible && IsNoteAdd == false)
  981. {
  982. NotePopupVisible = Visibility.Collapsed;
  983. if (region.Regions.ContainsRegionWithName(NotePopupRegionName))
  984. {
  985. var views = region.Regions[NotePopupRegionName].Views;
  986. foreach (var item in views)
  987. {
  988. if (item is StickyNotePopup sticky)
  989. {
  990. var contentRegion = region.Regions[NotePopupRegionName];
  991. contentRegion.Remove(sticky);
  992. break;
  993. }
  994. }
  995. }
  996. }
  997. }
  998. private async void createfromFile()
  999. {
  1000. string txt = Properties.Resources.txtex;
  1001. string word = Properties.Resources.wordex;
  1002. string ppt = Properties.Resources.pptex;
  1003. string excel = Properties.Resources.excelex;
  1004. string html = Properties.Resources.htmlex;
  1005. string image = Properties.Resources.imageex;
  1006. string allfiles = txt + word + excel + ppt + image + html;
  1007. OpenFileDialog dialog = new OpenFileDialog();
  1008. dialog.Multiselect = true;
  1009. dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
  1010. $"Microsoft Office Word({word})|{word}|" +
  1011. $"Microsoft Office Excel({excel})|{excel}|" +
  1012. $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
  1013. $"Txt({txt})|{txt}|" +
  1014. $"Picture({image})|{image}|" +
  1015. $"Html({html})|{html}");
  1016. if ((bool)dialog.ShowDialog())
  1017. {
  1018. for (int i = 0; i < dialog.FileNames.Length; i++)
  1019. {
  1020. if (App.OpenedFileList.Contains(dialog.FileNames[i]))
  1021. {
  1022. App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
  1023. }
  1024. else
  1025. {
  1026. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  1027. {
  1028. App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
  1029. }));
  1030. await Task.Delay(20);
  1031. ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
  1032. }
  1033. }
  1034. }
  1035. }
  1036. /// <summary>
  1037. ///创建空白文档
  1038. /// </summary>
  1039. private async void createBlankFile()
  1040. {
  1041. App.mainWindowViewModel.AddTab.Execute();
  1042. await Task.Delay(30);
  1043. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).CreateFile();
  1044. }
  1045. private void help(string args)
  1046. {
  1047. string url = "";
  1048. switch (args)
  1049. {
  1050. case "Guid":
  1051. //打开内嵌文档
  1052. if (App.OpenedFileList.Contains(App.GuidPDFPath))
  1053. {
  1054. //如果已经打开时,则选中内嵌文档
  1055. App.mainWindowViewModel.SelectItem(App.GuidPDFPath);
  1056. return;
  1057. }
  1058. if (File.Exists(App.GuidPDFPath))
  1059. {
  1060. App.mainWindowViewModel.AddTabItem(App.GuidPDFPath);
  1061. }
  1062. else
  1063. {
  1064. //因为文件被占用等情况,复制内嵌文档到新路径失败时,先打开项目内的文档
  1065. string tempfile = Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf");
  1066. if (File.Exists(tempfile))
  1067. {
  1068. App.mainWindowViewModel.AddTabItem(tempfile);
  1069. }
  1070. }
  1071. break;
  1072. case "Online":
  1073. url = @"https://www.pdfreaderpro.com/windows/help";
  1074. break;
  1075. case "More":
  1076. url = @"https://www.pdfreaderpro.com/product?utm_source=MacApp&utm_campaign=ProductLink&utm_medium=PdfProduct";
  1077. break;
  1078. case "Template":
  1079. url = @"https://www.pdfreaderpro.com/templates?utm_source=MacApp&utm_campaign=TemplatesLink&utm_medium=PdfTemplates";
  1080. break;
  1081. case "Blog":
  1082. //TODO:显示订阅电子报弹窗
  1083. break;
  1084. case "ComPDF":
  1085. url = @"https://www.compdf.com/?utm_source=macapp&utm_medium=pdfmac&utm_campaign=compdfkit-promp";
  1086. break;
  1087. case "FeedBack":
  1088. //调用邮箱 发送邮件
  1089. StringBuilder sr = new StringBuilder();
  1090. sr.AppendFormat("{0} - {1};{2};{3} - {4}", App.Name, App.Version, "Propose a New Feature", ServiceHelper.ComputerInfo, ServiceHelper.SystemInfo);
  1091. System.Diagnostics.Process.Start(string.Format("mailto:support@pdfreaderpro.com?subject={0}", sr));
  1092. break;
  1093. default:
  1094. break;
  1095. }
  1096. if (!string.IsNullOrEmpty(url))
  1097. {
  1098. //需要跳转网页的情况
  1099. System.Diagnostics.Process.Start(url);
  1100. }
  1101. }
  1102. /// <summary>
  1103. /// 打开文件,跟首页的打开文件有区别,需要新开一个页签
  1104. /// </summary>
  1105. private void openfile()
  1106. {
  1107. OpenFileDialog openFileDialog = new OpenFileDialog();
  1108. openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
  1109. openFileDialog.Multiselect = true;
  1110. if ((bool)openFileDialog.ShowDialog())
  1111. {
  1112. if (openFileDialog.FileNames.Count() == 1)
  1113. {
  1114. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  1115. {
  1116. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1117. }
  1118. else
  1119. {
  1120. App.mainWindowViewModel.AddTabItem(openFileDialog.FileName);
  1121. }
  1122. ToolMethod.SetFileThumbImg(openFileDialog.FileName);
  1123. }
  1124. else
  1125. {
  1126. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  1127. if (fileList.Count <= 0)
  1128. {
  1129. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  1130. return;
  1131. }
  1132. mainViewModel.OpenFile(fileList[0]);
  1133. for (int i = 1; i < fileList.Count(); i++)
  1134. {
  1135. if (!App.OpenedFileList.Contains(fileList[i]))
  1136. {
  1137. App.mainWindowViewModel.AddTabItem(fileList[i]);
  1138. }
  1139. ToolMethod.SetFileThumbImg(fileList[i]);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. /// <summary>
  1145. /// 打开文件Translation
  1146. /// </summary>
  1147. public void OpenFile(string[] newfile)
  1148. {
  1149. if (App.OpenedFileList.Contains(newfile[0]))
  1150. {
  1151. App.mainWindowViewModel.SelectItem(newfile[0]);
  1152. }
  1153. else
  1154. {
  1155. App.mainWindowViewModel.AddTabItem(newfile[0]);
  1156. }
  1157. ToolMethod.SetFileThumbImg(newfile[0]);
  1158. }
  1159. /// <summary>
  1160. /// 关闭当前窗体
  1161. /// </summary>
  1162. private void closeWindow()
  1163. {
  1164. App.Current.MainWindow.Close();
  1165. }
  1166. /// <summary>
  1167. /// 转档
  1168. /// </summary>
  1169. /// <param name="obj"></param>
  1170. private void convert(string obj)
  1171. {
  1172. if (!string.IsNullOrEmpty(obj))
  1173. {
  1174. DialogParameters value = new DialogParameters();
  1175. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1176. switch (obj)
  1177. {
  1178. case "Word":
  1179. dialogs.ShowDialog(DialogNames.ConverterWordDialog, value, e =>
  1180. {
  1181. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1182. converterDialogsModel.OnOpened((DialogResult)e);
  1183. });
  1184. break;
  1185. case "Excel":
  1186. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, value, e =>
  1187. {
  1188. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1189. converterDialogsModel.OnOpened((DialogResult)e);
  1190. });
  1191. break;
  1192. case "PPT":
  1193. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, value, e =>
  1194. {
  1195. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1196. converterDialogsModel.OnOpened((DialogResult)e);
  1197. });
  1198. break;
  1199. case "RTF":
  1200. dialogs.ShowDialog(DialogNames.ConverterRTFDialog, value, e =>
  1201. {
  1202. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1203. converterDialogsModel.OnOpened((DialogResult)e);
  1204. });
  1205. break;
  1206. case "CSV":
  1207. dialogs.ShowDialog(DialogNames.ConverterCSVDialog, value, e =>
  1208. {
  1209. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1210. converterDialogsModel.OnOpened((DialogResult)e);
  1211. });
  1212. break;
  1213. case "HTML":
  1214. dialogs.ShowDialog(DialogNames.ConverterHTMLDialog, value, e =>
  1215. {
  1216. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1217. converterDialogsModel.OnOpened((DialogResult)e);
  1218. });
  1219. break;
  1220. case "Text":
  1221. dialogs.ShowDialog(DialogNames.ConverterTextDialog, value, e =>
  1222. {
  1223. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1224. converterDialogsModel.OnOpened((DialogResult)e);
  1225. });
  1226. break;
  1227. case "Image":
  1228. dialogs.ShowDialog(DialogNames.ConverterImgDialog, value, e =>
  1229. {
  1230. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  1231. converterDialogsModel.OnOpened((DialogResult)e);
  1232. });
  1233. break;
  1234. default:
  1235. break;
  1236. }
  1237. }
  1238. }
  1239. /// <summary>
  1240. /// 解密
  1241. /// </summary>
  1242. private void decrypt()
  1243. {
  1244. ///无可用安全性设置的原因:
  1245. ///文件本身无安全性设置,且没有设置过密码
  1246. ///文件安全性已经被重置
  1247. ///
  1248. if ((!PDFViewer.Document.IsEncrypted && !SecurityInfo.IsPasswordChanged) || (SecurityInfo.IsPasswordRemoved))
  1249. {
  1250. AlertsMessage alertsMessage = new AlertsMessage();
  1251. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("NoPasswrod_Waring"), App.ServiceLoader.GetString("Text_ok"));
  1252. }
  1253. else
  1254. {
  1255. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1256. if (result.IsDiscryptied)
  1257. {
  1258. if (result.Password != null)
  1259. {
  1260. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1261. }
  1262. ShowLeftTip(false);
  1263. DialogParameters value = new DialogParameters();
  1264. value.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1265. value.Add(ParameterNames.ViewContentViewModel, this);
  1266. dialogs.ShowDialog(DialogNames.DeleteSafetySettingsDialog, value, e =>
  1267. {
  1268. if (e.Result == ButtonResult.OK)
  1269. {
  1270. if (SecurityInfo.IsPasswordRemoved)
  1271. {
  1272. PDFViewer.UndoManager.CanSave = true;
  1273. }
  1274. ShowLeftTip(false);
  1275. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1276. }
  1277. });
  1278. }
  1279. }
  1280. }
  1281. /// <summary>
  1282. /// 加密
  1283. /// </summary>
  1284. private void encrypt()
  1285. {
  1286. if (!this.SecurityInfo.IsPasswordChanged)
  1287. {
  1288. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  1289. if (result.IsDiscryptied)
  1290. {
  1291. if (result.Password != null)
  1292. {
  1293. if (PDFViewer.Document.UnlockWithPassword(result.Password))
  1294. {
  1295. PDFViewer.Document.CheckOwnerPassword(result.Password);
  1296. }
  1297. }
  1298. }
  1299. }
  1300. DialogParameters value = new DialogParameters();
  1301. value.Add(ParameterNames.PDFViewer, this.PDFViewer);
  1302. value.Add(ParameterNames.ViewContentViewModel, this);
  1303. dialogs.ShowDialog(DialogNames.SetPasswordDialog, value, e =>
  1304. {
  1305. if (e.Result == ButtonResult.OK)
  1306. {
  1307. SecurityHelper.IsPasswordChanged = true;
  1308. if (this.SecurityInfo.IsPasswordChanged)
  1309. {
  1310. this.PDFViewer.UndoManager.CanSave = true;
  1311. }
  1312. this.events.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
  1313. }
  1314. });
  1315. }
  1316. /// <summary>
  1317. /// 合并
  1318. /// </summary>
  1319. private void mergeFile()
  1320. {
  1321. DialogParameters value = new DialogParameters();
  1322. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1323. dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
  1324. }
  1325. /// <summary>
  1326. /// 压缩
  1327. /// </summary>
  1328. private void compress()
  1329. {
  1330. DialogParameters value = new DialogParameters();
  1331. value.Add(ParameterNames.PDFViewer, PDFViewer);
  1332. dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
  1333. {
  1334. CompressDialogModel compressDialogModel = new CompressDialogModel();
  1335. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  1336. });
  1337. }
  1338. /// <summary>
  1339. /// 设置Tip状态栏的显示状态
  1340. /// </summary>
  1341. /// <param name="show">是否显示</param>
  1342. public void ShowTip(bool show)
  1343. {
  1344. if (show)
  1345. {
  1346. TipVisible = Visibility.Visible;
  1347. }
  1348. else
  1349. {
  1350. TipVisible = Visibility.Collapsed;
  1351. }
  1352. }
  1353. /// <summary>
  1354. /// 设置LeftTip状态栏的显示状态
  1355. /// </summary>
  1356. /// <param name="show">是否显示</param>
  1357. public void ShowLeftTip(bool show)
  1358. {
  1359. if (show)
  1360. {
  1361. LeftTipVisible = Visibility.Visible;
  1362. }
  1363. else
  1364. {
  1365. LeftTipVisible = Visibility.Collapsed;
  1366. }
  1367. }
  1368. public void CheckHaveAllPermission()
  1369. {
  1370. if (!SecurityHelper.CheckHaveAllPermissions(PDFViewer.Document))
  1371. {
  1372. ShowLeftTip(true);
  1373. NavigationParameters param = new NavigationParameters();
  1374. param.Add(ParameterNames.PDFViewer, PDFViewer);
  1375. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  1376. }
  1377. }
  1378. public async void ShowSelectedTipAsync(ShowTipEventArgs showTipEventArgs)
  1379. {
  1380. switch (showTipEventArgs.enumTipKind)
  1381. {
  1382. case EnumTipKind.StatusNone:
  1383. ShowLeftTip(false);
  1384. break;
  1385. case EnumTipKind.StatusSetPasswordSuccessfully:
  1386. ShowLeftTip(true);
  1387. region.RequestNavigate(LeftTipContentRegionName, "SetPasswordSuccessfullyTip");
  1388. break;
  1389. case EnumTipKind.StatusRemoveSecuritySuccessfully:
  1390. ShowLeftTip(false);
  1391. region.RequestNavigate(TipContentRegionName, "RemoveSecuritySuccessTip");
  1392. IsLoading = Visibility.Collapsed;
  1393. ShowTip(true);
  1394. await Task.Delay(3000);
  1395. //ReadModelTip = Visibility.Collapsed;
  1396. TipVisible = Visibility.Collapsed;
  1397. break;
  1398. default: break;
  1399. }
  1400. }
  1401. /// <summary>
  1402. /// 右键菜单创建链接
  1403. /// </summary>
  1404. /// <param name="obj"></param>
  1405. private void CreateLinkEvent(object obj)
  1406. {
  1407. if (obj is object[] objArry)
  1408. {
  1409. if (objArry[0] is AnnotToolContentViewModel toolContentViewModel && objArry[1] is AnnotCommandArgs annotCommand)
  1410. {
  1411. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  1412. linkArgs.URI = string.Empty;
  1413. linkArgs.LinkType = LINK_TYPE.GOTO;
  1414. linkArgs.PageIndex = annotCommand.PageIndex;
  1415. //linkArgs.InvokeLinkSaveCalled(this, EventArgs.Empty);
  1416. this.IsRightMenuCreateLink = true;
  1417. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  1418. lists.Add(linkArgs);
  1419. AnnotHandlerEventArgs annotArgs = toolContentViewModel.GetLink(lists);
  1420. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1421. PDFViewer.SetToolParam(annotArgs);
  1422. this.IsPropertyOpen = true;
  1423. }
  1424. }
  1425. }
  1426. private void CloseProperty()
  1427. {
  1428. FromClick = true;
  1429. IsPropertyOpen = false;
  1430. FromClick = false;
  1431. }
  1432. /// <summary>
  1433. /// 在文件资源管理器中显示
  1434. /// </summary>
  1435. private void ShowInFolder()
  1436. {
  1437. CommonHelper.ShowFileBrowser(PDFViewer.Document.FilePath);
  1438. }
  1439. private void property()
  1440. {
  1441. DialogParameters valuePairs = new DialogParameters();
  1442. valuePairs.Add(ParameterNames.PDFDocument, PDFViewer.Document);
  1443. dialogs.ShowDialog(DialogNames.PropertyDialog, valuePairs, null);
  1444. }
  1445. private async void share()
  1446. {
  1447. try
  1448. {
  1449. //分享前自动保存
  1450. if (!await SaveBeforeOption())
  1451. {
  1452. return;
  1453. }
  1454. var path = PDFViewer.Document.FilePath;
  1455. string subject = "Share With" + " " + PDFViewer.Document.FileName;
  1456. System.Diagnostics.Process.Start("outlook", "/a,\"" + path + "\"" + "/m \"" + "&subject=" + subject + "\"");
  1457. }
  1458. catch
  1459. {
  1460. AlertsMessage alertsMessage = new AlertsMessage();
  1461. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Share_NoOutLookWarning"), App.ServiceLoader.GetString("Text_ok"));
  1462. }
  1463. }
  1464. private void SettingsEvent()
  1465. {
  1466. DialogParameters value = new DialogParameters();
  1467. value.Add(ParameterNames.ViewContentViewModel, this);
  1468. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM(); ;
  1469. dialogs.ShowDialog(DialogNames.SettingsDialog, null, e =>
  1470. {
  1471. var annotate = Settings.Default.AppProperties.Annotate;
  1472. if (annotToolContent != null)
  1473. {
  1474. IsSettingOut = true;
  1475. //与注释联动修改颜色
  1476. UpdateFreeHand(annotate, annotToolContent);
  1477. UpdateTextHighlight(annotate, annotToolContent);
  1478. UpdateUnderLine(annotate, annotToolContent);
  1479. UpdateStrikethrough(annotate, annotToolContent);
  1480. UpdateLine(annotate, annotToolContent);
  1481. UpdateArrow(annotate, annotToolContent);
  1482. //IsSettingOut =false;
  1483. }
  1484. });
  1485. if (PDFViewer != null)
  1486. {
  1487. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1488. }
  1489. if (Settings.Default.AppProperties.Description.AutoSave)
  1490. {
  1491. StartAutoSave();
  1492. }
  1493. else
  1494. {
  1495. CloseAutoSave();
  1496. }
  1497. }
  1498. private AnnotToolContentViewModel GetAnnotToolContentVM()
  1499. {
  1500. AnnotToolContentViewModel annotToolContent = null;
  1501. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  1502. {
  1503. var views = region.Regions[ToolsBarContentRegionName].Views;
  1504. var isHas = views.FindFirst(q => q is AnnotToolContent);
  1505. if (isHas is AnnotToolContent annotTool)
  1506. {
  1507. annotToolContent = (AnnotToolContentViewModel)annotTool.DataContext;
  1508. }
  1509. }
  1510. return annotToolContent;
  1511. }
  1512. private void UpdateArrow(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1513. {
  1514. Color color2 = annotate.ArrowColor;
  1515. Color color1 = (annotToolContent.ArrowColor as SolidColorBrush).Color;
  1516. bool flag = ColorComparison(color2, color1);
  1517. if (flag)
  1518. {
  1519. annotToolContent.ArrowColor = new SolidColorBrush(color2);
  1520. if (annotToolContent.PropertyPanel.LastArrowAnnot != null)
  1521. {
  1522. if (annotToolContent.PropertyPanel.LastArrowAnnot is LineAnnotArgs annotArgs)
  1523. {
  1524. annotArgs.LineColor = color2;
  1525. }
  1526. }
  1527. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1528. {
  1529. CreateRefreshComment(annotToolContent);
  1530. }
  1531. }
  1532. }
  1533. private void UpdateLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1534. {
  1535. Color color2 = annotate.LineColor;
  1536. Color color1 = (annotToolContent.LineColor as SolidColorBrush).Color;
  1537. bool flag = ColorComparison(color2, color1);
  1538. if (flag)
  1539. {
  1540. annotToolContent.LineColor = new SolidColorBrush(color2);
  1541. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null)
  1542. {
  1543. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] is LineAnnotArgs annotArgs)
  1544. {
  1545. annotArgs.LineColor = color2;
  1546. }
  1547. }
  1548. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1549. {
  1550. CreateRefreshComment(annotToolContent);
  1551. }
  1552. }
  1553. }
  1554. private void UpdateStrikethrough(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1555. {
  1556. Color color2 = annotate.StrikethroughColor;
  1557. Color color1 = (annotToolContent.StrikeoutColor as SolidColorBrush).Color;
  1558. bool flag = ColorComparison(color2, color1);
  1559. if (flag)
  1560. {
  1561. annotToolContent.StrikeoutColor = new SolidColorBrush(color2);
  1562. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1563. {
  1564. CreateRefreshComment(annotToolContent);
  1565. }
  1566. }
  1567. }
  1568. private void UpdateUnderLine(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1569. {
  1570. Color color2 = annotate.UnderLineColor;
  1571. Color color1 = (annotToolContent.UnderLineColor as SolidColorBrush).Color;
  1572. bool flag = ColorComparison(color2, color1);
  1573. if (flag)
  1574. {
  1575. annotToolContent.UnderLineColor = new SolidColorBrush(color2);
  1576. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1577. {
  1578. CreateRefreshComment(annotToolContent);
  1579. }
  1580. }
  1581. }
  1582. private void UpdateTextHighlight(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1583. {
  1584. Color color2 = annotate.HighLightColor;
  1585. Color color1 = (annotToolContent.HighLightColor as SolidColorBrush).Color;
  1586. bool flag = ColorComparison(color2, color1);
  1587. if (flag)
  1588. {
  1589. annotToolContent.HighLightColor = new SolidColorBrush(color2);
  1590. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1591. {
  1592. CreateRefreshComment(annotToolContent);
  1593. }
  1594. }
  1595. }
  1596. private void UpdateFreeHand(AnnotatePropertyClass annotate, AnnotToolContentViewModel annotToolContent)
  1597. {
  1598. Color color2 = annotate.FreeHandColor;
  1599. Color color1 = (annotToolContent.FreeHandColor as SolidColorBrush).Color;
  1600. bool flag = ColorComparison(color2, color1);
  1601. if (flag)
  1602. {
  1603. annotToolContent.FreeHandColor = new SolidColorBrush(color2);
  1604. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] != null)
  1605. {
  1606. if (annotToolContent.PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] is FreehandAnnotArgs freehandAnnotArgs)
  1607. {
  1608. freehandAnnotArgs.InkColor = color2;
  1609. }
  1610. }
  1611. if (string.IsNullOrEmpty(annotToolContent.StrAnnotToolChecked) == false)
  1612. {
  1613. CreateRefreshComment(annotToolContent);
  1614. }
  1615. }
  1616. }
  1617. private void CreateRefreshComment(AnnotToolContentViewModel annotToolContent)
  1618. {
  1619. AnnotHandlerEventArgs annotArgs = null;
  1620. string tag = annotToolContent.StrAnnotToolChecked;
  1621. annotToolContent.FindAnnotTypeKey(tag, ref annotArgs);
  1622. if (annotArgs != null)
  1623. {
  1624. //设置点击页面会创建对应选中注释工具的注释
  1625. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1626. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1627. PDFViewer.SetToolParam(annotArgs);
  1628. }
  1629. }
  1630. private bool ColorComparison(Color color2, Color color1)
  1631. {
  1632. if (color1.R == color2.R && color1.G == color2.G && color1.B == color2.B
  1633. && color1.A == color2.A)
  1634. {
  1635. return false;
  1636. }
  1637. else
  1638. {
  1639. return true;
  1640. }
  1641. }
  1642. private bool CanSaveExcute()
  1643. {
  1644. return CanSave;
  1645. }
  1646. private void MenuEnterReadModeEvent(object obj)
  1647. {
  1648. }
  1649. public void ShowAITranslationDialog()
  1650. {
  1651. DialogParameters printValue = new DialogParameters();
  1652. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1653. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1654. printValue.Add(ParameterNames.ViewContentViewModel, this);
  1655. printValue.Add(ParameterNames.Unicode, unicode);
  1656. dialogs.ShowDialog(DialogNames.DocumentaryTranslation, printValue, e => { });
  1657. }
  1658. public void ShowPrintDialog()
  1659. {
  1660. DialogParameters printValue = new DialogParameters();
  1661. printValue.Add(ParameterNames.PDFViewer, PDFViewer);
  1662. printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
  1663. printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
  1664. printValue.Add(ParameterNames.Unicode, unicode);
  1665. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printValue, e => { });
  1666. }
  1667. public void SelectClick()
  1668. {
  1669. if (OpenBOTA == false)
  1670. {
  1671. OpenBOTA = true;
  1672. }
  1673. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1674. if (isBook == false)
  1675. {
  1676. bOTAContent.TabItemSearch.IsSelected = true;
  1677. }
  1678. }
  1679. public bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1680. {
  1681. bool isTabItem = false;
  1682. bOTAContentViewModel = null;
  1683. bOTAContent = null;
  1684. if (region.Regions.ContainsRegionWithName(this.BOTARegionName))
  1685. {
  1686. var views = region.Regions[this.BOTARegionName].Views;
  1687. var model = views.FirstOrDefault(q => q is BOTAContent);
  1688. if (model is BOTAContent bOTAContent1)
  1689. {
  1690. bOTAContent = bOTAContent1;
  1691. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1692. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1693. {
  1694. isTabItem = true;
  1695. }
  1696. }
  1697. }
  1698. return isTabItem;
  1699. }
  1700. private void InitialregionNameByTabItem(ref Dictionary<string, string> dictionary)
  1701. {
  1702. dictionary.Add("TabItemPageEdit", ToolContentRegionName);
  1703. dictionary.Add("TabItemTool", ToolsBarContentRegionName);
  1704. //其他工具菜单栏共用一个ToolsBarContentRegionName
  1705. dictionary.Add("TabItemAnnotation", ToolsBarContentRegionName);
  1706. dictionary.Add("TabItemConvert", ToolsBarContentRegionName);
  1707. dictionary.Add("TabItemScan", ToolsBarContentRegionName);
  1708. dictionary.Add("TabItemEdit", TextEditContentRegionName);
  1709. dictionary.Add("TabItemForm", ToolsBarContentRegionName);
  1710. dictionary.Add("TabItemFill", ToolsBarContentRegionName);
  1711. }
  1712. private void InitialbarContentByTabItem(ref Dictionary<string, string> dictionary)
  1713. {
  1714. dictionary.Add("TabItemPageEdit", "PageEditContent");
  1715. dictionary.Add("TabItemTool", "ToolsBarContent");
  1716. dictionary.Add("TabItemAnnotation", "AnnotToolContent");
  1717. dictionary.Add("TabItemConvert", "ConverterBarContent");
  1718. dictionary.Add("TabItemScan", "ScanContent");
  1719. dictionary.Add("TabItemEdit", "TextEditToolContent");
  1720. dictionary.Add("TabItemForm", "FormsToolContent");
  1721. dictionary.Add("TabItemFill", "FillAndSignContent");
  1722. }
  1723. private void UpdateShowContent(string currentBar)
  1724. {
  1725. ToolContentVisible = Visibility.Collapsed;
  1726. ToolsBarContentVisible = Visibility.Collapsed;
  1727. ToolsBarContentVisible = Visibility.Collapsed;
  1728. TextEditToolContentVisible = Visibility.Collapsed;
  1729. OCRContentVisible = Visibility.Collapsed;
  1730. switch (currentBar)
  1731. {
  1732. case "TabItemAnnotation":
  1733. case "TabItemTool":
  1734. case "TabItemForm":
  1735. case "TabItemFill":
  1736. ToolsBarContentVisible = Visibility.Visible;
  1737. //当退出页面编辑后
  1738. //缩略图选中页面,要和当前显示的页面,一致
  1739. if (PDFViewer != null)
  1740. {
  1741. events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex });
  1742. }
  1743. #region part1
  1744. //bool isTabItemThumbnail = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemThumbnail");
  1745. //if (isTabItemThumbnail)
  1746. //{
  1747. // Views.PageEdit.PageEditContent pageEditContent = null;
  1748. // PageEditContentViewModel viewModel = GetPageEditContentVM(bOTAContentViewModel, out pageEditContent);
  1749. // if (viewModel != null)
  1750. // {
  1751. // viewModel.ListSelectedIndex = PDFViewer.CurrentIndex;
  1752. // pageEditContent.ListPageEdit.ScrollIntoView(pageEditContent.ListPageEdit.SelectedItem);
  1753. // }
  1754. //}
  1755. #endregion part1
  1756. break;
  1757. case "TabItemScan":
  1758. ToolsBarContentVisible = Visibility.Visible;
  1759. OCRContentVisible = Visibility.Visible;
  1760. break;
  1761. case "TabItemEdit":
  1762. TextEditToolContentVisible = Visibility.Visible;
  1763. break;
  1764. case "TabItemConvert":
  1765. ToolsBarContentVisible = Visibility.Visible;
  1766. //当退出页面编辑后
  1767. //缩略图选中页面,要和当前显示的页面,一致
  1768. if (PDFViewer != null)
  1769. {
  1770. events.GetEvent<PageEditSelectedItemEvent>().Publish(new PageEditSelectedItemEventArgs() { Unicode = unicode, SelectedItemIndex = PDFViewer.CurrentIndex });
  1771. }
  1772. break;
  1773. case "TabItemPageEdit":
  1774. case "HeaderFooterContent":
  1775. case "BatesContent":
  1776. case "WatermarkContent":
  1777. case "BackgroundContent":
  1778. case "RedactionContent":
  1779. ToolContentVisible = Visibility.Visible;
  1780. break;
  1781. default:
  1782. break;
  1783. }
  1784. PDFEditMode(currentBar);
  1785. FormMode(currentBar);
  1786. }
  1787. private void PDFEditMode(string currentBar)
  1788. {
  1789. if (currentBar == "TabItemEdit")
  1790. {
  1791. if (PDFViewer != null)
  1792. {
  1793. SolidColorBrush brush = new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#18A0FB"));
  1794. brush.Opacity = 0.2;
  1795. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  1796. CommonDrawData.PDFEditCoverBrush = brush;
  1797. CommonDrawData.PDFEditCoverPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
  1798. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  1799. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  1800. //SelectedPrpoertyPanel("TextEditProperty", null);
  1801. //IsPropertyOpen = true;
  1802. }
  1803. }
  1804. else
  1805. {
  1806. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.PDFEdit)
  1807. {
  1808. IsPropertyOpen = false;
  1809. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1810. }
  1811. }
  1812. }
  1813. private void FormMode(string currentBar)
  1814. {
  1815. if (currentBar == "TabItemForm")
  1816. {
  1817. if (PDFViewer != null)
  1818. {
  1819. PDFViewer.SetMouseMode(MouseModes.FormEditTool);
  1820. }
  1821. }
  1822. else
  1823. {
  1824. if (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool)
  1825. {
  1826. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1827. }
  1828. }
  1829. }
  1830. private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  1831. {
  1832. //不处于页面编辑模式下时,根据PDFVIewer的undo redo状态来更新按钮状态
  1833. if (e.PropertyName == "CanUndo")
  1834. {
  1835. CanUndo = PDFViewer.UndoManager.CanUndo;
  1836. }
  1837. if (e.PropertyName == "CanRedo")
  1838. {
  1839. CanRedo = PDFViewer.UndoManager.CanRedo;
  1840. }
  1841. if (e.PropertyName == "CanSave")
  1842. {
  1843. CanSave = PDFViewer.UndoManager.CanSave;
  1844. }
  1845. }
  1846. /// <summary>
  1847. /// 选项卡切换事件
  1848. /// </summary>
  1849. /// <param name="e"></param>
  1850. private void TabControlSelectonChangedEvent(object e)
  1851. {
  1852. var args = e as SelectionChangedEventArgs;
  1853. if (args != null && args.AddedItems.Count > 0)
  1854. {
  1855. var item = args.AddedItems[0] as TabItem;
  1856. CurrentBar = item.Name;
  1857. if (previousBar != CurrentBar)
  1858. {
  1859. if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
  1860. {
  1861. EnterPageEdit();
  1862. }
  1863. else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
  1864. {
  1865. EnterSelectedBar(CurrentBar);
  1866. isInPageEdit = false;
  1867. }
  1868. previousBar = CurrentBar;
  1869. }
  1870. }
  1871. }
  1872. /// <summary>
  1873. /// 进入页面编辑模式
  1874. /// </summary>
  1875. //工具栏添加功能应注意自处
  1876. public void EnterPageEdit()
  1877. {
  1878. if (TabSelectedIndex != 2)
  1879. {
  1880. TabSelectedIndex = 2;
  1881. }
  1882. CurrentBar = "TabItemPageEdit";
  1883. EnterToolMode(barContentByTabItem[CurrentBar]);
  1884. isInPageEdit = true;
  1885. }
  1886. /// <summary>
  1887. /// 阅读模式
  1888. /// </summary>
  1889. /// <param name="viewContent"></param>
  1890. public async void On_ReadMode()
  1891. {
  1892. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = true;
  1893. mainViewModel.IsBookMode = true;
  1894. IsLoading = Visibility.Visible;
  1895. await Task.Delay(1);
  1896. PDFViewer.DisableClearSelectAnnot(false);
  1897. PDFViewer.ClearSelectAnnots();
  1898. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1899. var annotArgs = new SelectToolArgs();
  1900. PDFViewer.SetToolParam(annotArgs);
  1901. #region 旧版本
  1902. //NavigationParameters param = new NavigationParameters();
  1903. //param.Add(ParameterNames.PDFViewer, PDFViewer);
  1904. //param.Add(ParameterNames.ViewContentViewModel, this);
  1905. //region.RequestNavigate(ToolContentRegionName, "ReadViewContent", param);
  1906. ////ShowContent(CurrentBar, true);
  1907. //if (GridToolRow != 0)
  1908. //{
  1909. // GridToolRow = 0;
  1910. //}
  1911. //if (GridToolRowSpan != 4)
  1912. //{
  1913. // GridToolRowSpan = 4;
  1914. //}
  1915. ////isInPageEdit = true;
  1916. //UpdateShowContent("TabItemPageEdit");
  1917. #endregion 旧版本
  1918. //5.15
  1919. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  1920. botaState = OpenBOTA;
  1921. propertyOpenState = IsPropertyOpen;
  1922. //5.6注释
  1923. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  1924. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  1925. //OpenBOTA = false;
  1926. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = true });
  1927. //模拟一次用户点击 关闭属性面板
  1928. //如果直接设置属性可能因为偏好设置设置成手动的原因 无法生效
  1929. FromClick = true;
  1930. IsPropertyOpen = false;
  1931. FromClick = false;
  1932. AnnotToolContentViewModel annotToolContent = GetAnnotToolContentVM();
  1933. if (annotToolContent != null)
  1934. {
  1935. annotToolContent.StrAnnotToolChecked = "";
  1936. }
  1937. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1938. {
  1939. var views = region.Regions[TipContentRegionName].Views;
  1940. var isHasView = views.FindFirst(q => q is Views.TipContent.EnterReadModeTip);
  1941. if (isHasView == null)
  1942. {
  1943. region.RequestNavigate(TipContentRegionName, "EnterReadModeTip");
  1944. }
  1945. else
  1946. {
  1947. region.Regions[TipContentRegionName].Activate(isHasView);
  1948. }
  1949. }
  1950. IsLoading = Visibility.Collapsed;
  1951. ShowTip(true);
  1952. await Task.Delay(3000);
  1953. TipVisible = Visibility.Collapsed;
  1954. }
  1955. /// <summary>
  1956. /// 退出阅读模式
  1957. /// </summary>
  1958. public async void Off_ReadModel()
  1959. {
  1960. App.mainWindowViewModel.SelectedItem.IsInReadctonMode = false;
  1961. mainViewModel.IsBookMode = false;
  1962. IsLoading = Visibility.Visible;
  1963. await Task.Delay(1);
  1964. //PDFViewer.MouseMode = MouseModes.None;
  1965. #region 旧版本
  1966. //if (region.Regions.ContainsRegionWithName(ViwerRegionName))
  1967. //{
  1968. // if (region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  1969. // {
  1970. // var contentRegion = region.Regions[ViwerRegionName];
  1971. // contentRegion.Remove(PDFViewer);
  1972. // }
  1973. // //还原背景色
  1974. // PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1975. // region.AddToRegion(ViwerRegionName, PDFViewer);
  1976. //}
  1977. //if (string.IsNullOrEmpty(CurrentBar) || CurrentBar.Equals("TabItemPageEdit", StringComparison.OrdinalIgnoreCase))
  1978. //{
  1979. // EnterSelectedBar("TabItemAnnotation");
  1980. //}
  1981. //else
  1982. //{
  1983. // EnterSelectedBar(CurrentBar);
  1984. //}
  1985. #endregion 旧版本
  1986. //还原背景色
  1987. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  1988. this.events.GetEvent<ReadModeEvent>().Publish(new ReadModeArgs() { Unicode = unicode, IsReadMode = false });
  1989. if (region.Regions.ContainsRegionWithName(TipContentRegionName))
  1990. {
  1991. var views = region.Regions[TipContentRegionName].Views;
  1992. var isHasView = views.FindFirst(q => q is Views.TipContent.ReadModelTip);
  1993. if (isHasView == null)
  1994. {
  1995. region.RequestNavigate(TipContentRegionName, "ReadModelTip");
  1996. }
  1997. else
  1998. {
  1999. region.Regions[TipContentRegionName].Activate(isHasView);
  2000. }
  2001. }
  2002. ///退出阅读模式 显示视图面板
  2003. BottomToolContent bottomTool = null;
  2004. BottomToolContentViewModel bottomToolVM = GetBottomToolContentVM(ref bottomTool);
  2005. if (bottomToolVM != null)
  2006. {
  2007. bottomToolVM.IsShowViewModular = propertyOpenState;
  2008. IsPropertyOpen = propertyOpenState;
  2009. if (bottomToolVM.IsShowViewModular && bottomTool != null)
  2010. {
  2011. bottomToolVM.ShowViewModularCommand.Execute(true);
  2012. }
  2013. }
  2014. //if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  2015. //{
  2016. // var views = region.Regions[BottomToolRegionName].Views;
  2017. // var isHasView = views.FindFirst(q => q is BottomToolContent);
  2018. // if (isHasView is BottomToolContent bottomToolContent)
  2019. // {
  2020. // BottomToolContentViewModel toolContentViewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  2021. // toolContentViewModel.IsShowViewModular = propertyOpenState;
  2022. // IsPropertyOpen = propertyOpenState;
  2023. // }
  2024. //}
  2025. IsLoading = Visibility.Collapsed;
  2026. //5.6注释
  2027. //已调整左右侧边栏层级,暂时注释掉,修复展开BOTA,进入阅读模式再退出后,BOTA保持展开,但没有选中的问题
  2028. //留意测试阶段是否会有问题,如果没问题,在上线前删除
  2029. //5.15
  2030. //15722 【视图-阅读模式】退出阅读模式,页面应保持原来的视图结构
  2031. OpenBOTA = botaState;
  2032. PDFViewer.DisableClearSelectAnnot(false);
  2033. PDFViewer.ClearSelectAnnots();
  2034. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  2035. var annotArgs = new SelectToolArgs();
  2036. PDFViewer.SetToolParam(annotArgs);
  2037. ShowTip(true);
  2038. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  2039. await Task.Delay(3000);
  2040. //ReadModelTip = Visibility.Collapsed;
  2041. TipVisible = Visibility.Collapsed;
  2042. }
  2043. public BottomToolContentViewModel GetBottomToolContentVM(ref BottomToolContent bottomTool)
  2044. {
  2045. BottomToolContentViewModel viewModel = null;
  2046. if (region.Regions.ContainsRegionWithName(BottomToolRegionName))
  2047. {
  2048. var views = region.Regions[BottomToolRegionName].Views;
  2049. var isHasView = views.FindFirst(q => q is BottomToolContent);
  2050. if (isHasView is BottomToolContent bottomToolContent)
  2051. {
  2052. bottomTool = bottomToolContent;
  2053. viewModel = bottomToolContent.DataContext as BottomToolContentViewModel;
  2054. }
  2055. }
  2056. return viewModel;
  2057. }
  2058. #region PDFViewer鼠标滚轮缩放事件
  2059. public void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
  2060. {
  2061. double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
  2062. PDFViewer.Zoom(newZoom);
  2063. }
  2064. public double CheckZoomLevel(double zoom, bool IsGrowth)
  2065. {
  2066. double standardZoom = 100;
  2067. //最小缩放倍数 0.01倍
  2068. double minrate = 0.01;
  2069. //最大缩放倍数 100倍
  2070. double maxrate = 100;
  2071. if (zoom <= minrate)
  2072. {
  2073. return minrate;
  2074. }
  2075. //最大缩放倍数 100倍
  2076. if (zoom >= maxrate)
  2077. {
  2078. return maxrate;
  2079. }
  2080. zoom *= 100;
  2081. for (int i = 0; i < zoomLevel.Length - 1; i++)
  2082. {
  2083. if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
  2084. {
  2085. standardZoom = zoomLevel[i + 1];
  2086. break;
  2087. }
  2088. if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
  2089. {
  2090. standardZoom = zoomLevel[i];
  2091. break;
  2092. }
  2093. }
  2094. return standardZoom / 100;
  2095. }
  2096. #endregion PDFViewer鼠标滚轮缩放事件
  2097. #region 方法
  2098. /// <summary>
  2099. /// 快捷键
  2100. /// </summary>
  2101. /// <param name="sender"></param>
  2102. /// <param name="e"></param>
  2103. /// <exception cref="NotImplementedException"></exception>
  2104. private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  2105. {
  2106. if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
  2107. {
  2108. //判断是不是不是注释工具下
  2109. bool isunannotTool = true;
  2110. //内容选择 退出
  2111. if (PDFViewer.MouseMode != MouseModes.PanTool)
  2112. {
  2113. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2114. if (annotToolContent != null && toolContentViewModel != null)
  2115. {
  2116. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2117. {
  2118. if (toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs != null)
  2119. {
  2120. toolContentViewModel.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  2121. annotToolContent.BtnSelecttool.IsChecked = false;
  2122. PDFViewer.SetMouseMode(MouseModes.PanTool);
  2123. isunannotTool = false;
  2124. }
  2125. }
  2126. else
  2127. {
  2128. //如果注释是在拖拉创建中 或者 选中 了图片 不退出阅读模式
  2129. if (toolContentViewModel != null)
  2130. {
  2131. if (toolContentViewModel.IsCreateAnnot)
  2132. {
  2133. isunannotTool = false;
  2134. toolContentViewModel.IsCreateAnnot = false;
  2135. }
  2136. if (toolContentViewModel.IsSelectImage)
  2137. {
  2138. isunannotTool = false;
  2139. toolContentViewModel.IsSelectImage = false;
  2140. }
  2141. }
  2142. }
  2143. }
  2144. }
  2145. if (mainViewModel.IsBookMode == true && isunannotTool)
  2146. {
  2147. Off_ReadModel();
  2148. }
  2149. }
  2150. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.C))
  2151. {
  2152. //内容选择 复制 快捷键
  2153. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2154. if (annotToolContent != null && toolContentViewModel != null)
  2155. {
  2156. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2157. {
  2158. toolContentViewModel.SnapshotEditMenuViewModel.SnapCopyCommand.Execute();
  2159. }
  2160. }
  2161. }
  2162. if (KeyEventsHelper.IsModifierKey(ModifierKeys.Control, Key.P))
  2163. {
  2164. AnnotToolContent annotToolContent = GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel);
  2165. if (annotToolContent != null && toolContentViewModel != null)
  2166. {
  2167. if (annotToolContent.BtnSelecttool.IsChecked == true)
  2168. {
  2169. toolContentViewModel.SnapshotEditMenuViewModel.PrintCommand.Execute();
  2170. }
  2171. }
  2172. }
  2173. }
  2174. private AnnotToolContent GetAnnotToolContent(out AnnotToolContentViewModel toolContentViewModel)
  2175. {
  2176. AnnotToolContent toolContent = null;
  2177. toolContentViewModel = null;
  2178. if (region.Regions.ContainsRegionWithName(ToolsBarContentRegionName))
  2179. {
  2180. var views = region.Regions[ToolsBarContentRegionName].Views;
  2181. var model = views.FirstOrDefault(q => q is AnnotToolContent);
  2182. if (model is AnnotToolContent annotToolContent)
  2183. {
  2184. toolContent = annotToolContent;
  2185. toolContentViewModel = annotToolContent.DataContext as AnnotToolContentViewModel;
  2186. }
  2187. }
  2188. return toolContent;
  2189. }
  2190. /// <summary>
  2191. /// 视图面板 切换分屏模式
  2192. /// </summary>
  2193. /// <param name="mode"></param>
  2194. public void EnterSplitMode(SplitMode mode)
  2195. {
  2196. ///通知UI层更改布局
  2197. this.events.GetEvent<SplitEvent>().Publish(new SplitEventArgs() { Unicode = unicode, Mode = mode });
  2198. }
  2199. private void Undo()
  2200. {
  2201. PDFViewer.UndoManager.Undo();
  2202. PDFViewer.DisableClearSelectAnnot(false);
  2203. PDFViewer.ClearSelectAnnots();
  2204. }
  2205. private void Redo()
  2206. {
  2207. PDFViewer.UndoManager.Redo();
  2208. }
  2209. private void LoadControl()
  2210. {
  2211. NavigationParameters parameters = new NavigationParameters();
  2212. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2213. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2214. region.RequestNavigate(BOTARegionName, "BOTAContent", parameters);
  2215. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2216. region.RequestNavigate(ReadModeRegionName, "PageContent", parameters);
  2217. region.RequestNavigate(SplitViewerRegionName, "SplitScreenContent", parameters);
  2218. //TODO 根据上一次关闭记录的菜单,选中顶部TabItem
  2219. EnterSelectedBar("TabItemAnnotation");
  2220. //}
  2221. //));
  2222. }
  2223. /// <summary>
  2224. /// 各个注释(选中和创建注释)导航到对应注释的属性面板
  2225. /// </summary>
  2226. /// <param name="Content"></param>
  2227. /// <param name="annotPropertyPanel"></param>
  2228. public void SelectedPrpoertyPanel(string Content, AnnotTransfer annotPropertyPanel)
  2229. {
  2230. if (Content == "PropertyPanelContent")
  2231. {
  2232. IsPropertyOpen = false;
  2233. }
  2234. else
  2235. {
  2236. IsPropertyOpen = true;
  2237. }
  2238. NavigationParameters parameters = new NavigationParameters();
  2239. //传其他参数:文档类,空注释面板;
  2240. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2241. parameters.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  2242. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2243. region.RequestNavigate(PropertyRegionName, Content, parameters);
  2244. }
  2245. /// <summary>
  2246. /// 将PDFViwer添加到Region
  2247. /// </summary>
  2248. private bool loadFile()
  2249. {
  2250. PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
  2251. PDFViewer.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  2252. CanSave = PDFViewer.UndoManager.CanSave;
  2253. CanUndo = PDFViewer.UndoManager.CanUndo;
  2254. CanRedo = PDFViewer.UndoManager.CanRedo;
  2255. if (!CheckPassword())
  2256. {
  2257. return false;
  2258. }
  2259. PDFViewer.Load();
  2260. PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2261. PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
  2262. //设置移动注释参考线
  2263. ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"), 1);
  2264. ComPDFKitViewer.CommonDrawData.DrawAnnotGuidesLine = true;
  2265. //还原上一次关闭前的视图设置
  2266. GetOpenFileInfo();
  2267. if (!string.IsNullOrEmpty(PassWord))
  2268. {
  2269. //加密文档解密后刷新底部工具栏页码总数
  2270. NavigationParameters parameters = new NavigationParameters();
  2271. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  2272. parameters.Add(ParameterNames.ViewContentViewModel, this);
  2273. region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
  2274. //解密后,刷新侧边栏逻辑
  2275. botaViewModel.OpenBOTA();
  2276. }
  2277. PDFViewer.SnapsToDevicePixels = true;
  2278. PDFViewer.UseLayoutRounding = true;
  2279. RenderOptions.SetBitmapScalingMode(PDFViewer, BitmapScalingMode.Fant);
  2280. region.AddToRegion(ViwerRegionName, PDFViewer);
  2281. if (App.mainWindowViewModel != null)
  2282. {
  2283. //更新CurrentPDFViewer对象
  2284. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2285. }
  2286. if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
  2287. {
  2288. App.OpenedFileList.Add(PDFViewer.Document.FilePath);
  2289. }
  2290. return true;
  2291. }
  2292. /// <summary>
  2293. /// 处理密码相关的内容
  2294. /// </summary>
  2295. private bool CheckPassword()
  2296. {
  2297. if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
  2298. {
  2299. if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
  2300. {
  2301. PDFViewer.Document.UnlockWithPassword(passwordInfo.OpenPassword);
  2302. }
  2303. if (!string.IsNullOrEmpty(passwordInfo.PermissionsPassword) && passwordInfo.PermissionsPassword != passwordInfo.OpenPassword)
  2304. {
  2305. IsFileLocked = true;
  2306. NavigationParameters param = new NavigationParameters();
  2307. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2308. param.Add(ParameterNames.ViewContentViewModel, this);
  2309. ShowLeftTip(true);
  2310. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2311. }
  2312. }
  2313. else
  2314. {
  2315. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  2316. if (result.IsDiscryptied)
  2317. {
  2318. if (result.Password != null)
  2319. {
  2320. string filePath = PDFViewer.Document.FilePath;
  2321. PDFViewer.Document.UnlockWithPassword(result.Password);
  2322. PDFViewer.Tag = result.Password;
  2323. //记录密码到内存
  2324. this.PassWord = result.Password;
  2325. }
  2326. }
  2327. if (result.IsDiscryptied == false)
  2328. {
  2329. //未成功解密文档时,释放Document对象,返回
  2330. PDFViewer.Document.Release();
  2331. //取消解密时关闭当前页签
  2332. App.mainWindowViewModel.CloseTabItem(App.mainWindowViewModel.SelectedItem);
  2333. return false;
  2334. }
  2335. }
  2336. return true;
  2337. }
  2338. /// <summary>
  2339. /// 还原上一次浏览的视图相关设置
  2340. /// </summary>
  2341. private void GetOpenFileInfo()
  2342. {
  2343. OpenFileInfo = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2344. //偏好设置里设置了记录上次视图设置时
  2345. if (OpenFileInfo != null && Settings.Default.AppProperties.Description.RecoveryViewWhenOpen)
  2346. {
  2347. if (OpenFileInfo.LastViewMode != PDFViewer.ModeView)
  2348. {
  2349. PDFViewer.ChangeViewMode(OpenFileInfo.LastViewMode);
  2350. }
  2351. if (OpenFileInfo.LastFitMode != PDFViewer.ModeFit)
  2352. {
  2353. PDFViewer.ChangeFitMode(OpenFileInfo.LastFitMode);
  2354. }
  2355. if (OpenFileInfo.LastFitMode == ComPDFKitViewer.FitMode.FitFree)
  2356. {
  2357. PDFViewer.Zoom(OpenFileInfo.LastZoom);
  2358. }
  2359. PDFViewer.SetSplitMode(OpenFileInfo.LastSplitMode);
  2360. PDFViewer.SetShowLink(OpenFileInfo.ShowHighLightLink);
  2361. if (OpenFileInfo.LastPageSpace)
  2362. {
  2363. PDFViewer.SetPageSpacing(8);
  2364. }
  2365. else
  2366. {
  2367. PDFViewer.SetPageSpacing(0);
  2368. }
  2369. if (OpenFileInfo.LastDrawMode == ComPDFKitViewer.DrawModes.Draw_Mode_Custom && OpenFileInfo.LastFillColor != 0)
  2370. {
  2371. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode, OpenFileInfo.LastFillColor);
  2372. }
  2373. else
  2374. {
  2375. PDFViewer.SetDrawMode(OpenFileInfo.LastDrawMode);
  2376. }
  2377. if (OpenFileInfo.LastPageIndex == 0 && PDFViewer.GetVerticalOffset() != 0)
  2378. {
  2379. PDFViewer.ScrollToVerticalOffset(0);
  2380. }
  2381. }
  2382. else
  2383. {
  2384. //新文档应用默认设置
  2385. PDFViewer.ChangeViewMode(Settings.Default.AppProperties.InitialVIew.PageView);
  2386. PDFViewer.ChangeFitMode(Settings.Default.AppProperties.InitialVIew.ZoomMode);
  2387. PDFViewer.SetShowLink(Settings.Default.AppProperties.InitialVIew.HighlightLink);
  2388. }
  2389. }
  2390. /// <summary>
  2391. /// 已有路径文档的保存逻辑
  2392. /// </summary>
  2393. public bool saveFile(bool autosave = false)
  2394. {
  2395. try
  2396. {
  2397. //是否取消了水印保存步骤
  2398. bool flg = false;
  2399. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2400. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP== true)
  2401. {
  2402. DialogParameters value = new DialogParameters();
  2403. value.Add(ParameterNames.ViewContentViewModel, this);
  2404. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2405. {
  2406. if (dialogResult.Result == ButtonResult.OK)
  2407. {
  2408. flg = true;
  2409. }
  2410. else
  2411. {
  2412. flg= false;
  2413. }
  2414. });
  2415. return flg;
  2416. }
  2417. if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
  2418. return saveAsFile();
  2419. //文档已被修复时 提示另存为
  2420. if (PDFViewer.Document.HasRepaired)
  2421. {
  2422. AlertsMessage alertsMessage = new AlertsMessage();
  2423. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileRepairedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2424. if (alertsMessage.result == ContentResult.Ok)
  2425. return saveAsFile();
  2426. else
  2427. return false;
  2428. }
  2429. //文件路径无法存在时
  2430. if (!File.Exists(PDFViewer.Document.FilePath))
  2431. {
  2432. AlertsMessage alertsMessage = new AlertsMessage();
  2433. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileNotExistWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2434. if (alertsMessage.result == ContentResult.Ok)
  2435. return saveAsFile();
  2436. else
  2437. return false;
  2438. }
  2439. //只读文件无法写入时,提示另存为
  2440. FileInfo fileInfo = new FileInfo(PDFViewer.Document.FilePath);
  2441. if (fileInfo.IsReadOnly)
  2442. {
  2443. AlertsMessage alertsMessage = new AlertsMessage();
  2444. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileReadonlyWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2445. if (alertsMessage.result == ContentResult.Ok)
  2446. return saveAsFile();
  2447. else
  2448. return false;
  2449. }
  2450. //记录保存前的当前页
  2451. int pageindex = PDFViewer.CurrentIndex;
  2452. //Security Fixed:
  2453. //修改密码后原文档保存的步骤:
  2454. //在设置密码窗口传出“已修改”信号,并允许延迟保存
  2455. //
  2456. if (SecurityInfo.IsPasswordChanged)
  2457. {
  2458. string currentFilePath = PDFViewer.Document.FilePath;
  2459. string tempFilePath = PDFViewer.Document.FilePath + ".temp.pdf";
  2460. string openPassword = string.Empty;
  2461. string permissionsPassword = string.Empty;
  2462. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2463. if (SecurityInfo.NeedOpenPassword)
  2464. {
  2465. openPassword = SecurityInfo.OpenPassword;
  2466. }
  2467. if (SecurityInfo.NeedPermissionsPassword)
  2468. {
  2469. permissionsPassword = SecurityInfo.PermissionsPassword;
  2470. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2471. }
  2472. try
  2473. {
  2474. string currentPath = PDFViewer.Document.FilePath;
  2475. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2476. if (PDFViewer.Document.Descrypt(tempPath))
  2477. {
  2478. PDFViewer.CloseDocument();
  2479. PDFViewer.InitDocument(tempPath);
  2480. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2481. if (PDFViewer.Document.WriteToFilePath(currentPath))
  2482. {
  2483. PDFViewer.CloseDocument();
  2484. PDFViewer.InitDocument(currentPath);
  2485. if (!string.IsNullOrEmpty(openPassword))
  2486. {
  2487. PDFViewer.Document.UnlockWithPassword(openPassword);
  2488. }
  2489. if (!string.IsNullOrEmpty(permissionsPassword) && openPassword != permissionsPassword)
  2490. {
  2491. //PDFViewer.Document.CheckOwnerPassword(permissionsPassword);
  2492. IsFileLocked = true;
  2493. NavigationParameters param = new NavigationParameters();
  2494. param.Add(ParameterNames.PDFViewer, PDFViewer);
  2495. param.Add(ParameterNames.ViewContentViewModel, this);
  2496. ShowLeftTip(true);
  2497. region.RequestNavigate(LeftTipContentRegionName, "FileRestrictedTip", param);
  2498. }
  2499. try
  2500. {
  2501. PDFViewer.Load();
  2502. //跳转到保存前的页面
  2503. PDFViewer.GoToPage(pageindex);
  2504. }
  2505. catch
  2506. {
  2507. }
  2508. if (!autosave)
  2509. {
  2510. PDFViewer.UndoManager.CanSave = false;
  2511. }
  2512. SecurityInfo.IsPasswordChanged = false;
  2513. }
  2514. else
  2515. {
  2516. return false;
  2517. }
  2518. System.IO.File.Delete(tempPath);
  2519. }
  2520. else
  2521. {
  2522. return false;
  2523. }
  2524. return true;
  2525. }
  2526. catch
  2527. {
  2528. return false;
  2529. }
  2530. }
  2531. else if (SecurityInfo.IsPasswordRemoved)
  2532. {
  2533. try
  2534. {
  2535. string currentPath = PDFViewer.Document.FilePath;
  2536. string tempPath = PDFViewer.Document.FilePath + ".temp.pdf";
  2537. PDFViewer.Document.Descrypt(tempPath);
  2538. PDFViewer.CloseDocument();
  2539. PDFViewer.InitDocument(tempPath);
  2540. PDFViewer.Document.WriteToFilePath(currentPath);
  2541. PDFViewer.CloseDocument();
  2542. PDFViewer.InitDocument(currentPath);
  2543. PDFViewer.Load();
  2544. //跳转到保存前的页面
  2545. PDFViewer.GoToPage(pageindex);
  2546. System.IO.File.Delete(tempPath);
  2547. }
  2548. catch
  2549. {
  2550. return false;
  2551. }
  2552. }
  2553. //自动裁剪保存
  2554. List<int> cropPageList = new List<int>();
  2555. for (int i = 0; i < PDFViewer.Document.PageCount; i++)
  2556. {
  2557. cropPageList.Clear();
  2558. cropPageList.Add(i);
  2559. CPDFPage cPDFPage = PDFViewer.Document.PageAtIndex(i);
  2560. if (PDFViewer.IsCropMode(i) == true)
  2561. {
  2562. Rect rect = cPDFPage.GetCropBounds();
  2563. PDFViewer?.CropPage(CPDFDisplayBox.CropBox, rect, cropPageList);
  2564. }
  2565. }
  2566. bool result = PDFViewer.Document.WriteToLoadedPath();
  2567. if (result)
  2568. {
  2569. if (!autosave)
  2570. {
  2571. PDFViewer.UndoManager.CanSave = false;
  2572. }
  2573. App.Current.Dispatcher.Invoke(() =>
  2574. {
  2575. //保存时更新缩略图
  2576. OpenFileInfo info = SettingHelper.GetFileInfo(PDFViewer.Document.FilePath);
  2577. try
  2578. {
  2579. if (info != null && !string.IsNullOrEmpty(info.ThumbImgPath) && !PDFViewer.Document.IsEncrypted)//加密的文档不获取缩略图
  2580. {
  2581. var size = PDFViewer.Document.GetPageSize(0);
  2582. System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)size.Width, (int)size.Height, 0, true, true);
  2583. string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
  2584. if (File.Exists(folderPath))
  2585. File.Delete(folderPath);
  2586. DirectoryInfo folder = new DirectoryInfo(folderPath);
  2587. if (!folder.Exists)
  2588. folder.Create();
  2589. string imagePath = info.ThumbImgPath;
  2590. if (!File.Exists(imagePath))//由加密文档变为非加密文档时 新建一个路径
  2591. {
  2592. string imageName = Guid.NewGuid().ToString();
  2593. imagePath = System.IO.Path.Combine(folderPath, imageName);
  2594. using (FileStream stream = new FileStream(imagePath, FileMode.Create))
  2595. {
  2596. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2597. }
  2598. }
  2599. else
  2600. {
  2601. using (FileStream stream = new FileStream(imagePath, FileMode.Open))
  2602. {
  2603. bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  2604. }
  2605. }
  2606. info.ThumbImgPath = imagePath;
  2607. SettingHelper.SetFileInfo(info);
  2608. }
  2609. }
  2610. catch
  2611. {
  2612. info.ThumbImgPath = null;
  2613. SettingHelper.SetFileInfo(info);
  2614. }
  2615. });
  2616. //编辑不要刷新,否则保存时会崩溃
  2617. if (PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.None)
  2618. {
  2619. PDFViewer.ReloadDocument();
  2620. }
  2621. //PDFViewer.ReloadDocument();
  2622. }
  2623. else
  2624. {
  2625. //弹窗前 激活主窗体
  2626. //App.Current.MainWindow.Activate();
  2627. AlertsMessage alertsMessage = new AlertsMessage();
  2628. //文件被占用 保存失败时
  2629. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
  2630. //显示当前窗体,防止窗口置底
  2631. App.Current.MainWindow.Activate();
  2632. if (alertsMessage.result == ContentResult.Ok)
  2633. return saveAsFile();
  2634. else
  2635. return false;
  2636. }
  2637. return result;
  2638. }
  2639. catch { return false; }
  2640. finally
  2641. {
  2642. if (!IsFileLocked)
  2643. {
  2644. ShowLeftTip(false);
  2645. }
  2646. }
  2647. }
  2648. /// <summary>
  2649. /// 另存为或新文档保存逻辑
  2650. /// </summary>
  2651. public bool saveAsFile(Action RedactionAction = null, String IsFormSave=null)
  2652. {
  2653. //是否来自savefile方法
  2654. if(IsFormSave=="FormSave")
  2655. {
  2656. var dlg = new Microsoft.Win32.SaveFileDialog();
  2657. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2658. dlg.FileName = PDFViewer.Document.FileName;
  2659. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2660. {
  2661. bool result = false;
  2662. if (RedactionAction != null)
  2663. {
  2664. //保存前进行标记密文处理应用或擦除
  2665. RedactionAction.Invoke();
  2666. }
  2667. if (App.OpenedFileList.Contains(dlg.FileName))
  2668. {
  2669. //提示文件已经被打开
  2670. }
  2671. else
  2672. {
  2673. string oldpath = PDFViewer.Document.FilePath;
  2674. string openPassword = string.Empty;
  2675. string permissionsPassword = string.Empty;
  2676. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2677. if (SecurityInfo.NeedOpenPassword)
  2678. {
  2679. openPassword = SecurityInfo.OpenPassword;
  2680. passwordInfo.OpenPassword = openPassword;
  2681. }
  2682. if (SecurityInfo.NeedPermissionsPassword)
  2683. {
  2684. permissionsPassword = SecurityInfo.PermissionsPassword;
  2685. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2686. passwordInfo.PermissionsPassword = permissionsPassword;
  2687. }
  2688. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2689. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2690. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2691. if (resourceInfo != null)
  2692. {
  2693. using (Stream stream = resourceInfo.Stream)
  2694. {
  2695. BitmapFrame frame = null;
  2696. int width = 0;
  2697. int height = 0;
  2698. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2699. if (decoder != null && decoder.Frames.Count > 0)
  2700. {
  2701. frame = decoder.Frames[0];
  2702. }
  2703. if (frame != null)
  2704. {
  2705. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2706. width = frame.PixelWidth;
  2707. height = frame.PixelHeight;
  2708. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2709. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2710. watermark.SetImage(ImageArray, width, height);
  2711. watermark.SetScale(1);
  2712. watermark.SetRotation(0);
  2713. watermark.SetOpacity(255);
  2714. watermark.SetFront(true);
  2715. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2716. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2717. watermark.SetFullScreen(false);
  2718. watermark.SetVertOffset(0);
  2719. watermark.SetHorizOffset(0);
  2720. watermark.SetHorizontalSpacing(0);
  2721. watermark.SetVerticalSpacing(0);
  2722. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2723. watermark.SetPages(setpages);
  2724. watermark.UpdateWatermark();
  2725. PDFViewer.Document.ReleasePages();
  2726. PDFViewer.ReloadDocument();
  2727. }
  2728. }
  2729. }
  2730. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2731. if (result)
  2732. {
  2733. mainViewModel.NewFile = false;
  2734. App.OpenedFileList.Remove(oldpath);
  2735. DoAfterSaveAs(dlg.FileName);
  2736. }
  2737. else
  2738. {
  2739. //提示文件被其他软件占用 无法保存
  2740. //
  2741. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2742. }
  2743. }
  2744. return result;
  2745. }
  2746. else
  2747. return false;
  2748. }
  2749. else
  2750. {
  2751. bool flg = false;
  2752. //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
  2753. if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true)
  2754. {
  2755. DialogParameters value = new DialogParameters();
  2756. value.Add(ParameterNames.ViewContentViewModel, this);
  2757. value.Add(ParameterNames.Open, "saveAs");
  2758. dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
  2759. {
  2760. if (dialogResult.Result == ButtonResult.OK)
  2761. {
  2762. flg = true;
  2763. }
  2764. else
  2765. {
  2766. flg = false;
  2767. }
  2768. });
  2769. if (flg == false)
  2770. {
  2771. return false;
  2772. }
  2773. }
  2774. var dlg = new Microsoft.Win32.SaveFileDialog();
  2775. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2776. dlg.FileName = PDFViewer.Document.FileName;
  2777. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2778. {
  2779. bool result = false;
  2780. if (RedactionAction != null)
  2781. {
  2782. //保存前进行标记密文处理应用或擦除
  2783. RedactionAction.Invoke();
  2784. }
  2785. if (App.OpenedFileList.Contains(dlg.FileName))
  2786. {
  2787. //提示文件已经被打开
  2788. }
  2789. else
  2790. {
  2791. string oldpath = PDFViewer.Document.FilePath;
  2792. string openPassword = string.Empty;
  2793. string permissionsPassword = string.Empty;
  2794. CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
  2795. if (SecurityInfo.NeedOpenPassword)
  2796. {
  2797. openPassword = SecurityInfo.OpenPassword;
  2798. passwordInfo.OpenPassword = openPassword;
  2799. }
  2800. if (SecurityInfo.NeedPermissionsPassword)
  2801. {
  2802. permissionsPassword = SecurityInfo.PermissionsPassword;
  2803. cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
  2804. passwordInfo.PermissionsPassword = permissionsPassword;
  2805. }
  2806. PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
  2807. //是否需要加水印
  2808. if(flg==true)
  2809. {
  2810. Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
  2811. StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
  2812. if (resourceInfo != null)
  2813. {
  2814. using (Stream stream = resourceInfo.Stream)
  2815. {
  2816. BitmapFrame frame = null;
  2817. int width = 0;
  2818. int height = 0;
  2819. BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
  2820. if (decoder != null && decoder.Frames.Count > 0)
  2821. {
  2822. frame = decoder.Frames[0];
  2823. }
  2824. if (frame != null)
  2825. {
  2826. var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  2827. width = frame.PixelWidth;
  2828. height = frame.PixelHeight;
  2829. frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
  2830. watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
  2831. watermark.SetImage(ImageArray, width, height);
  2832. watermark.SetScale(1);
  2833. watermark.SetRotation(0);
  2834. watermark.SetOpacity(255);
  2835. watermark.SetFront(true);
  2836. watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
  2837. watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
  2838. watermark.SetFullScreen(false);
  2839. watermark.SetVertOffset(0);
  2840. watermark.SetHorizOffset(0);
  2841. watermark.SetHorizontalSpacing(0);
  2842. watermark.SetVerticalSpacing(0);
  2843. string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
  2844. watermark.SetPages(setpages);
  2845. watermark.UpdateWatermark();
  2846. PDFViewer.Document.ReleasePages();
  2847. PDFViewer.ReloadDocument();
  2848. }
  2849. }
  2850. }
  2851. }
  2852. result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
  2853. if (result)
  2854. {
  2855. mainViewModel.NewFile = false;
  2856. App.OpenedFileList.Remove(oldpath);
  2857. DoAfterSaveAs(dlg.FileName);
  2858. }
  2859. else
  2860. {
  2861. //提示文件被其他软件占用 无法保存
  2862. //
  2863. //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
  2864. }
  2865. }
  2866. return result;
  2867. }
  2868. else
  2869. return false;
  2870. }
  2871. }
  2872. /// <summary>
  2873. /// 转档、压缩、合并前自动保存
  2874. /// </summary>
  2875. public async Task<bool> SaveBeforeOption()
  2876. {
  2877. bool result = true;
  2878. //因配合权益弹窗弹出,暂时移除可保存条件判断
  2879. //if (PDFViewer.UndoManager.CanSave)
  2880. {
  2881. string title = "Saving File";
  2882. App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
  2883. //让保存的效果更明显
  2884. await Task.Delay(200);
  2885. //合并前自动保存一次
  2886. result = saveFile(true);
  2887. App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
  2888. }
  2889. //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
  2890. return result;
  2891. }
  2892. /// <summary>
  2893. /// 另存为Flatten
  2894. /// </summary>
  2895. private void saveAsFlatten()
  2896. {
  2897. var dlg = new SaveFileDialog();
  2898. dlg.Filter = Properties.Resources.OpenDialogFilter;
  2899. dlg.FileName = PDFViewer.Document.FileName + "_Flattened.pdf";
  2900. if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
  2901. {
  2902. saveFile();
  2903. CPDFDocument kmdoc = CPDFDocument.InitWithFilePath(PDFViewer.Document.FilePath);
  2904. if (kmdoc == null)
  2905. {
  2906. return;
  2907. }
  2908. bool result = kmdoc.WriteFlattenToFilePath(dlg.FileName);
  2909. if (result)
  2910. {
  2911. System.Diagnostics.Process.Start("explorer", "/select,\"" + dlg.FileName + "\"");
  2912. }
  2913. kmdoc.Release();
  2914. }
  2915. }
  2916. /// <summary>
  2917. /// 另存为后进行的操作
  2918. /// 重新打开新文档
  2919. /// </summary>
  2920. /// <param name="targetPath"></param>
  2921. public void DoAfterSaveAs(string targetPath)
  2922. {
  2923. PDFViewer.UndoManager.CanSave = false;
  2924. //从新路径重新加载
  2925. //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
  2926. PDFViewer.CloseDocument();
  2927. PDFViewer.InitDocument(targetPath);
  2928. //处理解密相关的逻辑 现在的逻辑另存为自动打开后会需要重新输入密码
  2929. CheckPassword();
  2930. PDFViewer.Load();
  2931. //刷新最近文件列表
  2932. OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);
  2933. if (isnew == null)
  2934. {
  2935. if (App.OpenedFileList.Contains(targetPath) == false)
  2936. {
  2937. App.OpenedFileList.Add(targetPath);
  2938. }
  2939. }
  2940. //打开文件后,不管是新文件还是旧文件都需要更新排序
  2941. SettingHelper.SortRecentOpenFiles(targetPath);
  2942. //更新页签文件名
  2943. mainViewModel.FilePath = PDFViewer.Document.FilePath;
  2944. App.mainWindowViewModel.CurrentPDFViewer = PDFViewer;
  2945. //刷新Bota 和底部工具栏的PDFviwer对象
  2946. LoadControl();
  2947. }
  2948. /// <summary>
  2949. /// 显示前添加内容到Region
  2950. /// </summary>
  2951. /// <param name="isPageEdit"></param>
  2952. private void ShowContent(string currentBar, bool isToolMode = false)
  2953. {
  2954. GridVisibility = Visibility.Visible;
  2955. //显示页面编辑或其他工具
  2956. if (currentBar == "TabItemPageEdit" || isToolMode)
  2957. {
  2958. if (currentBar == "TabItemPageEdit")//进入页面编辑
  2959. {
  2960. if (GridToolRow != 1)
  2961. {
  2962. GridToolRow = 1;
  2963. }
  2964. if (GridToolRowSpan != 3)
  2965. {
  2966. GridToolRowSpan = 3;
  2967. }
  2968. }
  2969. else//进入水印等其他工具模式
  2970. {
  2971. GridVisibility = Visibility.Collapsed;
  2972. if (GridToolRow != 0)
  2973. {
  2974. GridToolRow = 0;
  2975. }
  2976. if (GridToolRowSpan != 4)
  2977. {
  2978. GridToolRowSpan = 4;
  2979. }
  2980. }
  2981. //ToolContent的visible跟toolsbarContent 的visible是互斥的
  2982. UpdateShowContent(currentBar);
  2983. }
  2984. else
  2985. {
  2986. if (GridToolRow != 1)
  2987. {
  2988. GridToolRow = 1;
  2989. }
  2990. UpdateShowContent(currentBar);
  2991. }
  2992. }
  2993. /// <summary>
  2994. /// 从二级工具栏进入需要修改界面布局的场景
  2995. /// </summary>
  2996. /// <param name="EditToolName"></param>
  2997. private void EnterEditTools(StringWithUnicode EditToolName)
  2998. {
  2999. EnterSelectedEditTool(EditToolName);
  3000. }
  3001. private void CloseEditTool(EnumCloseModeUnicode enumCloseModeunicode)
  3002. {
  3003. EnumCloseMode enumCloseMode = enumCloseModeunicode.Status;
  3004. if (enumCloseMode == EnumCloseMode.StatusConfirm)
  3005. {
  3006. PDFViewer.Document.ReleasePages();
  3007. PDFViewer.ReloadDocument();
  3008. }
  3009. //如果是其他工具共用一个PDFview,退出工具模式后,需要重新添加到Region,否则不会显示
  3010. if (!region.Regions[ViwerRegionName].Views.Contains(PDFViewer))
  3011. {
  3012. region.AddToRegion(ViwerRegionName, PDFViewer);
  3013. }
  3014. CurrentBar = "TabItemTool";
  3015. EnterSelectedBar(CurrentBar);
  3016. }
  3017. /// <summary>
  3018. /// 二级菜单指定目标处理
  3019. /// </summary>
  3020. /// <param name="e"></param>
  3021. private void EnterSelectedEditTool(StringWithUnicode EditToolName)
  3022. {
  3023. CurrentBar = EditToolName.EditToolsContentName;
  3024. EnterToolMode(CurrentBar);
  3025. }
  3026. /// <summary>
  3027. /// 进入工具编辑(如页面编辑、水印、密文等)模式
  3028. /// </summary>
  3029. /// <param name="targetToolMode">要导航过去的控件名称</param>
  3030. /// <param name="valuePairs">导航需要传送的参数,为空时,默认传送PDFView和ViewContentViewModel</param>
  3031. private async void EnterToolMode(string targetToolMode, NavigationParameters valuePairs = null)
  3032. {
  3033. IsLoading = Visibility.Visible;
  3034. await Task.Delay(3);
  3035. NavigationParameters param = new NavigationParameters();
  3036. if (valuePairs == null)
  3037. {
  3038. param.Add(ParameterNames.PDFViewer, PDFViewer);
  3039. param.Add(ParameterNames.ViewContentViewModel, this);
  3040. }
  3041. else//有传入其他内容的参数时
  3042. {
  3043. param = valuePairs;
  3044. }
  3045. region.RequestNavigate(ToolContentRegionName, targetToolMode, param);
  3046. ShowContent(CurrentBar, true);
  3047. IsLoading = Visibility.Collapsed;
  3048. }
  3049. private void EnterSelectedBar(string currentBar)
  3050. {
  3051. if (currentBar == "TabItemEdit")
  3052. {
  3053. if (!ServiceHelper.IAPBeforeFunction())
  3054. {
  3055. TabSelectedIndex = 0;
  3056. isInPageEdit = false;
  3057. return;
  3058. }
  3059. }
  3060. NavigationParameters param = new NavigationParameters();
  3061. param.Add(ParameterNames.PDFViewer, PDFViewer);
  3062. param.Add(ParameterNames.ViewContentViewModel, this);
  3063. region.RequestNavigate(regionNameByTabItem[currentBar], barContentByTabItem[currentBar], param);
  3064. if (currentBar == "TabItemScan")
  3065. {
  3066. region.RequestNavigate(RegionNames.OCRViewerRegionName, "ScanViwer", param);
  3067. }
  3068. ShowContent(currentBar);
  3069. }
  3070. /// <summary>
  3071. /// 退出工具(水印、密文等)编辑模式,隐藏ToolContent
  3072. /// </summary>
  3073. public void ExitToolMode()
  3074. {
  3075. ToolContentVisible = Visibility.Collapsed;
  3076. if (isInPageEdit)
  3077. {
  3078. TabSelectedIndex = 0;
  3079. isInPageEdit = false;
  3080. }
  3081. }
  3082. #endregion 方法
  3083. #region Navigate
  3084. public void OnNavigatedTo(NavigationContext navigationContext)
  3085. {
  3086. navigationContext.Parameters.TryGetValue(ParameterNames.PasswordInfo, out PasswordInfo);
  3087. var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
  3088. if (mainVM != null)
  3089. {
  3090. mainViewModel = mainVM;
  3091. mainViewModel.viewContentViewModel = this;
  3092. }
  3093. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  3094. if (pdfview != null)
  3095. {
  3096. PDFViewer = pdfview;
  3097. if (loadFile())
  3098. {
  3099. CheckHaveAllPermission();
  3100. }
  3101. }
  3102. //快捷键
  3103. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3104. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  3105. //弹窗需要放到最后(确保在各字段赋值语句的后面),弹窗显示会触发控件的Loaded事件,会导致后续段没有赋值,而加载等事件继续往后跑了
  3106. //例如这里的问题 会因为显示注册弹窗,导致其他模块没有接受到正常的PDFviewer对象
  3107. Settings.Default.UserDate.CheckRegisterStatus();
  3108. App.mainWindowViewModel.OphVis = Visibility.Collapsed;
  3109. if (Settings.Default.UserDate.TodayRegister == false && App.IsLogin == false)
  3110. {
  3111. Settings.Default.UserDate.TodayRegister = true;
  3112. DateTime currentTime = DateTime.Now;
  3113. Settings.Default.UserDate.TodayRegisterTime = currentTime.ToString();
  3114. Settings.Default.Save();
  3115. App.mainWindowViewModel.OpenRegister();
  3116. }
  3117. //需要在pdfview赋值后绑定
  3118. GlobalCommands.FullWindowCommand.RegisterCommand(new DelegateCommand(() => { OpenFullWindow(); }));
  3119. }
  3120. public bool IsNavigationTarget(NavigationContext navigationContext)
  3121. {
  3122. if (navigationContext != null)
  3123. {
  3124. //另存为打开导航进来时 不能新建一个实例
  3125. return true;
  3126. }
  3127. else
  3128. {
  3129. //一次性打开多个文件时,需要新建实例
  3130. return false;
  3131. }
  3132. }
  3133. public void OnNavigatedFrom(NavigationContext navigationContext)
  3134. {
  3135. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  3136. }
  3137. internal void FindPageEditContent(out Views.PageEdit.PageEditContent pageEditContent)
  3138. {
  3139. pageEditContent = null;
  3140. if (region.Regions.ContainsRegionWithName(ToolContentRegionName))
  3141. {
  3142. var views = region.Regions[ToolContentRegionName].Views;
  3143. var model = views.FirstOrDefault(q => q is Views.PageEdit.PageEditContent);
  3144. if (model is Views.PageEdit.PageEditContent page)
  3145. {
  3146. pageEditContent = page;
  3147. }
  3148. }
  3149. }
  3150. #endregion Navigate
  3151. }
  3152. }