|
@@ -1,6 +1,8 @@
|
|
|
-using compdfkit_tools.PDFControl;
|
|
|
+using compdfkit_tools.Helper;
|
|
|
+using compdfkit_tools.PDFControl;
|
|
|
using compdfkit_tools.PDFControlUI;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
@@ -15,6 +17,7 @@ namespace viewer_ctrl_demo
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
private CPDFViewer pdfViewer;
|
|
|
+ private CPDFViewer passwordViewer;
|
|
|
private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
|
|
|
public MainWindow()
|
|
|
{
|
|
@@ -45,6 +48,9 @@ namespace viewer_ctrl_demo
|
|
|
pdfViewer.MouseWheelZoomHandler -= PdfViewer_MouseWheelZoomHandler;
|
|
|
pdfViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
|
|
|
pdfViewer.InfoChanged += PdfViewer_InfoChanged;
|
|
|
+ PasswordUI.Closed += PasswordUI_Closed;
|
|
|
+ PasswordUI.Canceled += PasswordUI_Canceled;
|
|
|
+ PasswordUI.Confirmed += PasswordUI_Confirmed;
|
|
|
|
|
|
UIElement currentBotaTool = GetBotaTool();
|
|
|
if (currentBotaTool is CPDFSearchControl)
|
|
@@ -68,6 +74,39 @@ namespace viewer_ctrl_demo
|
|
|
ZoomTextBox.Text = string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)) + "%";
|
|
|
}
|
|
|
|
|
|
+ private void PasswordUI_Confirmed(object sender, string e)
|
|
|
+ {
|
|
|
+ if(passwordViewer!=null && passwordViewer.Document!=null)
|
|
|
+ {
|
|
|
+ passwordViewer.Document.UnlockWithPassword(e);
|
|
|
+ if (passwordViewer.Document.IsLocked == false)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("", Visibility.Collapsed);
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ pdfViewer = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowError("error", Visibility.Visible);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Canceled(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordUI_Closed(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
+ PasswordUI.Visibility = Visibility.Collapsed;
|
|
|
+ }
|
|
|
+
|
|
|
private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
|
|
|
{
|
|
|
if(e.Key== "PageNum")
|
|
@@ -382,14 +421,52 @@ namespace viewer_ctrl_demo
|
|
|
|
|
|
private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- PopupBorder.Visibility= Visibility.Visible;
|
|
|
+ PasswordUI.Visibility=Visibility.Collapsed;
|
|
|
+ FileInfoUI.Visibility = Visibility.Visible;
|
|
|
FileInfoControl.InitWithPDFViewer(pdfViewer);
|
|
|
+ PopupBorder.Visibility = Visibility.Visible;
|
|
|
}
|
|
|
|
|
|
private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
PopupBorder.Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
+
|
|
|
+ private void OpenFile_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string filePath = CommonHelper.GetFilePathOrEmpty();
|
|
|
+ if (!string.IsNullOrEmpty(filePath) && pdfViewer != null)
|
|
|
+ {
|
|
|
+ passwordViewer = new CPDFViewer();
|
|
|
+ passwordViewer.InitDocument(filePath);
|
|
|
+ if(passwordViewer.Document == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Open File Failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (passwordViewer.Document.IsLocked)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath)+ " password encrypted.");
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PopupBorder.Visibility=Visibility.Visible;
|
|
|
+ PasswordUI.Visibility=Visibility.Visible;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pdfViewer = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|