|
@@ -1,8 +1,13 @@
|
|
|
-using ComPDFKitViewer.AnnotEvent;
|
|
|
+using ComPDFKit.Import;
|
|
|
+using ComPDFKit.PDFAnnotation;
|
|
|
+using ComPDFKit.PDFPage;
|
|
|
+using ComPDFKitViewer;
|
|
|
+using ComPDFKitViewer.AnnotEvent;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using PDF_Office.CustomControl;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using PDF_Office.Model;
|
|
|
+using PDF_Office.Properties;
|
|
|
using Prism.Commands;
|
|
|
using Prism.Events;
|
|
|
using Prism.Mvvm;
|
|
@@ -28,6 +33,8 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
|
|
|
|
|
|
private ViewContentViewModel viewContentViewModel;
|
|
|
|
|
|
+ private RedactionAnnotArgs redactionArgs = new RedactionAnnotArgs();
|
|
|
+
|
|
|
public string RedactionDocumentRegionName { get; set; }
|
|
|
public string RedactionBottomBarRegionName { get; set; }
|
|
|
|
|
@@ -43,6 +50,38 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
|
|
|
|
|
|
public DelegateCommand PageRedactionCommand { get; set; }
|
|
|
|
|
|
+ private int currentPage = 0;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 是否因为本身传递值 防止循环调用
|
|
|
+ /// </summary>
|
|
|
+ private bool isFromSelf = false;
|
|
|
+
|
|
|
+ public int CurrentPage
|
|
|
+ {
|
|
|
+ get { return currentPage; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref currentPage, value);
|
|
|
+ if(value>=1&&value<=PDFViewer.Document.PageCount&&!isFromSelf)
|
|
|
+ {
|
|
|
+ PDFViewer.GoToPage(value-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int pageCount = 0;
|
|
|
+
|
|
|
+ public int PageCount
|
|
|
+ {
|
|
|
+ get { return pageCount; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref pageCount, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public RedactionContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator,IDialogService dialogService)
|
|
|
{
|
|
|
this.redactionRegion = regionManager;
|
|
@@ -82,18 +121,140 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
|
|
|
|
|
|
private void pageMark()
|
|
|
{
|
|
|
- dialogs.ShowDialog(DialogNames.PageMarkDialog);
|
|
|
+ DialogParameters valuePairs = new DialogParameters();
|
|
|
+ valuePairs.Add(ParameterNames.PageCount,PDFViewer.Document.PageCount);
|
|
|
+ valuePairs.Add(ParameterNames.CurrentPageIndex,PDFViewer.CurrentIndex);
|
|
|
+ dialogs.ShowDialog(DialogNames.PageMarkDialog,valuePairs,e=> {
|
|
|
+ if(e.Result == ButtonResult.OK)
|
|
|
+ {
|
|
|
+ var pagelist = e.Parameters.GetValue<List<int>>(ParameterNames.PageList);
|
|
|
+ addMarkToPages(pagelist);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ private void addMarkToPages(List<int> list)
|
|
|
+ {
|
|
|
+ foreach (var page in list)
|
|
|
+ {
|
|
|
+
|
|
|
+ //根据页面大小,创建标记密文注释
|
|
|
+ CPDFPage docPage = PDFViewer.Document.PageAtIndex(page);
|
|
|
+
|
|
|
+ CPDFRedactAnnotation redactionAnnot = docPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_REDACT) as CPDFRedactAnnotation;
|
|
|
+ if (redactionAnnot == null)
|
|
|
+ {
|
|
|
+ //TODO 操作失败
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ redactionAnnot.SetQuardRects(new List<CRect>() { new CRect(0, (float)docPage.PageSize.Height, (float)docPage.PageSize.Width,0)});
|
|
|
+
|
|
|
+ if (redactionArgs == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ byte[] lineColor = { redactionArgs.LineColor.R, redactionArgs.LineColor.G, redactionArgs.LineColor.B };
|
|
|
+ redactionAnnot.SetOutlineColor(lineColor);
|
|
|
+
|
|
|
+ if (redactionArgs.BgColor != Colors.Transparent)
|
|
|
+ {
|
|
|
+ byte[] bgColor = { redactionArgs.BgColor.R, redactionArgs.BgColor.G, redactionArgs.BgColor.B };
|
|
|
+ redactionAnnot.SetFillColor(bgColor);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // redactionAnnot.ClearBgColor();
|
|
|
+ }
|
|
|
+
|
|
|
+ CTextAttribute textAttr = new CTextAttribute();
|
|
|
+ byte[] fontColor = { redactionArgs.FontColor.R, redactionArgs.FontColor.G, redactionArgs.FontColor.B };
|
|
|
+ textAttr.FontColor = fontColor;
|
|
|
+ textAttr.FontSize = (float)redactionArgs.FontSize;
|
|
|
+ redactionAnnot.SetTextAttribute(textAttr);
|
|
|
+ switch (redactionArgs.Align)
|
|
|
+ {
|
|
|
+ case TextAlignment.Left:
|
|
|
+ redactionAnnot.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_LEFT);
|
|
|
+ break;
|
|
|
+ case TextAlignment.Center:
|
|
|
+ redactionAnnot.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_CENTER);
|
|
|
+ break;
|
|
|
+ case TextAlignment.Right:
|
|
|
+ redactionAnnot.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ redactionAnnot.SetTextAlignment(C_TEXT_ALIGNMENT.ALIGNMENT_LEFT);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ //byte transparency = (byte)Math.Round(redactionArgs.Transparency * 255);
|
|
|
+ //redactionAnnot.SetTransparency(transparency);
|
|
|
+ redactionAnnot.SetBorderWidth(1);
|
|
|
+ //redactionAnnot.SetRect(new CRect(Left, Bottom, Right, Top));
|
|
|
+
|
|
|
+ //redactionAnnot.SetCreationDate(Helpers.GetCurrentPdfTime());
|
|
|
+ if (string.IsNullOrEmpty(Settings.Default.AppProperties.Description.Author))
|
|
|
+ {
|
|
|
+ redactionAnnot.SetAuthor(Settings.Default.AppProperties.Description.Author);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (redactionArgs.Content != null && redactionArgs.Content != string.Empty)
|
|
|
+ {
|
|
|
+ redactionAnnot.SetOverlayText(redactionArgs.Content);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (redactionAnnot.GetIsLocked() != redactionArgs.Locked)
|
|
|
+ {
|
|
|
+ redactionAnnot.SetIsLocked(redactionArgs.Locked);
|
|
|
+ }
|
|
|
+
|
|
|
+ redactionAnnot.UpdateAp();
|
|
|
+ redactionAnnot.ReleaseAnnot();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public void CloseEditTool()
|
|
|
{
|
|
|
- PDFViewer.SetMouseMode(MouseModes.Default);
|
|
|
- redactionRegion.Regions[RegionNames.ViwerRegionName].Remove(PDFViewer);
|
|
|
- redactionRegion.Regions[RedactionDocumentRegionName].Remove(PDFViewer);
|
|
|
- this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = this.Unicode, Status = EnumCloseMode.StatusCancel });
|
|
|
+ bool isClose = true;
|
|
|
+ if (CheckHasRedactionAnnote())
|
|
|
+ {
|
|
|
+ AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
+ alertsMessage.ShowDialog("", "There are unapplied redactions in this file. Exit will not save redaction.", "Cancel", "Exit");
|
|
|
+ if (alertsMessage.result != ContentResult.Ok)
|
|
|
+ {
|
|
|
+ isClose = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isClose)
|
|
|
+ {
|
|
|
+ PDFViewer.SetMouseMode(MouseModes.Default);
|
|
|
+ redactionRegion.Regions[RegionNames.ViwerRegionName].Remove(PDFViewer);
|
|
|
+ redactionRegion.Regions[RedactionDocumentRegionName].Remove(PDFViewer);
|
|
|
+ this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish(new EnumCloseModeUnicode { Unicode = this.Unicode, Status = EnumCloseMode.StatusCancel });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 检查是否有未应用的标记密文
|
|
|
+ /// </summary>
|
|
|
+ private bool CheckHasRedactionAnnote()
|
|
|
+ {
|
|
|
+ for (int i = 0; i < PDFViewer.Document.PageCount; i++)
|
|
|
+ {
|
|
|
+ var items = PDFViewer.GetAnnotCommentList(i, PDFViewer.Document);
|
|
|
+ for (int j = 0; j < items.Count; j++)
|
|
|
+ {
|
|
|
+ if (items[j].EventType == AnnotArgsType.AnnotRedaction)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
#region Navigation
|
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
@@ -109,27 +270,28 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
|
|
|
{
|
|
|
navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
|
|
|
navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
|
|
|
+ PDFViewer.InfoChanged += PDFViewer_InfoChanged;
|
|
|
+ CurrentPage = PDFViewer.CurrentIndex + 1;
|
|
|
+ PageCount = PDFViewer.Document.PageCount;
|
|
|
if (!redactionRegion.Regions[RedactionDocumentRegionName].Views.Contains(PDFViewer))
|
|
|
{
|
|
|
- RedactionAnnotArgs redactionArgs = new RedactionAnnotArgs();
|
|
|
+ redactionArgs = new RedactionAnnotArgs();
|
|
|
AnnotHandlerEventArgs annotArgs = null;
|
|
|
- redactionArgs.LineColor = ((SolidColorBrush)Brushes.Black).Color;
|
|
|
- redactionArgs.BgColor = ((SolidColorBrush)Brushes.Black).Color;
|
|
|
- redactionArgs.FontColor = ((SolidColorBrush)Brushes.Red).Color;
|
|
|
- //redactionArgs.LineColor = Settings.Default.RedactionsSettings.LineColor;
|
|
|
- //redactionArgs.BgColor = Settings.Default.RedactionsSettings.BgColor;
|
|
|
- //redactionArgs.FontColor = Settings.Default.RedactionsSettings.FontColor;
|
|
|
- //redactionArgs.Align = Settings.Default.RedactionsSettings.Align;
|
|
|
- //redactionArgs.FontSize = Settings.Default.RedactionsSettings.FontSize;
|
|
|
- //redactionArgs.Content = Settings.Default.RedactionsSettings.Content;
|
|
|
- //if (!Settings.Default.RedactionsSettings.isUseText)
|
|
|
- //{
|
|
|
- // redactionArgs.Content = "";
|
|
|
- //}
|
|
|
+ redactionArgs.LineColor = Settings.Default.RedactionsSettings.LineColor;
|
|
|
+ redactionArgs.BgColor = Settings.Default.RedactionsSettings.BgColor;
|
|
|
+ redactionArgs.FontColor = Settings.Default.RedactionsSettings.FontColor;
|
|
|
+ redactionArgs.Align = Settings.Default.RedactionsSettings.Align;
|
|
|
+ redactionArgs.FontSize = Settings.Default.RedactionsSettings.FontSize;
|
|
|
+ redactionArgs.Content = Settings.Default.RedactionsSettings.Content;
|
|
|
+ if (!Settings.Default.RedactionsSettings.isUseText)
|
|
|
+ {
|
|
|
+ redactionArgs.Content = "";
|
|
|
+ }
|
|
|
annotArgs = redactionArgs;
|
|
|
if (annotArgs != null)
|
|
|
{
|
|
|
- //annotArgs.Author = Settings.Default.AppProperties.Description.Author;
|
|
|
+ //设置注释作者
|
|
|
+ annotArgs.Author = Settings.Default.AppProperties.Description.Author;
|
|
|
PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
|
|
|
PDFViewer.SetToolParam(annotArgs);
|
|
|
}
|
|
@@ -137,6 +299,17 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
+ {
|
|
|
+ isFromSelf = true;
|
|
|
+ if(e.Key=="PageNum")
|
|
|
+ {
|
|
|
+ var data = e.Value as RenderData;
|
|
|
+ CurrentPage = data.PageIndex;
|
|
|
+ }
|
|
|
+ isFromSelf = false;
|
|
|
+ }
|
|
|
#endregion
|
|
|
}
|
|
|
}
|