|
@@ -312,7 +312,7 @@ namespace PDFViewer
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
ToggleButton senderBtn = sender as ToggleButton;
|
|
@@ -351,7 +351,7 @@ namespace PDFViewer
|
|
|
pdfViewControl.PDFView.UndoManager?.Redo();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void ClearPDFEditState(ToggleButton ignoreBtn = null)
|
|
|
{
|
|
|
List<ToggleButton> clearBtnList = new List<ToggleButton>()
|
|
@@ -664,24 +664,17 @@ namespace PDFViewer
|
|
|
{
|
|
|
string choosePath = folderBrowser.SelectedPath;
|
|
|
string openPath = choosePath;
|
|
|
- try
|
|
|
+ foreach (int pageIndex in imageDict.Keys)
|
|
|
{
|
|
|
- foreach (int pageIndex in imageDict.Keys)
|
|
|
+ List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
+ foreach (Bitmap image in imageList)
|
|
|
{
|
|
|
- List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
- foreach (Bitmap image in imageList)
|
|
|
- {
|
|
|
- string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
|
|
|
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
- openPath = savePath;
|
|
|
- }
|
|
|
+ string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
|
|
|
+ image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
+ openPath = savePath;
|
|
|
}
|
|
|
- Process.Start("explorer", "/select,\"" + openPath + "\"");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
-
|
|
|
}
|
|
|
+ Process.Start("explorer", "/select,\"" + openPath + "\"");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -773,64 +766,49 @@ namespace PDFViewer
|
|
|
{
|
|
|
string choosePath = folderDialog.SelectedPath;
|
|
|
string openPath = choosePath;
|
|
|
- try
|
|
|
- {
|
|
|
- Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
|
|
|
+ Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
|
|
|
|
|
|
- if (imageDict != null && imageDict.Count > 0)
|
|
|
+ if (imageDict != null && imageDict.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (int pageIndex in imageDict.Keys)
|
|
|
{
|
|
|
- foreach (int pageIndex in imageDict.Keys)
|
|
|
+ List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
+ foreach (Bitmap image in imageList)
|
|
|
{
|
|
|
- List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
- foreach (Bitmap image in imageList)
|
|
|
- {
|
|
|
- string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
|
|
|
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
- openPath = savePath;
|
|
|
- }
|
|
|
+ string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
|
|
|
+ image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
|
+ openPath = savePath;
|
|
|
}
|
|
|
}
|
|
|
- Process.Start("explorer", "/select,\"" + openPath + "\"");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
+ Process.Start("explorer", "/select,\"" + openPath + "\"");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void CopyImage_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
|
|
|
+ Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
|
|
|
|
|
|
- if (imageDict != null && imageDict.Count > 0)
|
|
|
+ if (imageDict != null && imageDict.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (int pageIndex in imageDict.Keys)
|
|
|
{
|
|
|
- foreach (int pageIndex in imageDict.Keys)
|
|
|
+ List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
+ foreach (Bitmap image in imageList)
|
|
|
{
|
|
|
- List<Bitmap> imageList = imageDict[pageIndex];
|
|
|
- foreach (Bitmap image in imageList)
|
|
|
- {
|
|
|
- MemoryStream ms = new MemoryStream();
|
|
|
- image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
- BitmapImage imageData = new BitmapImage();
|
|
|
- imageData.BeginInit();
|
|
|
- imageData.StreamSource = ms;
|
|
|
- imageData.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
- imageData.EndInit();
|
|
|
- imageData.Freeze();
|
|
|
- Clipboard.SetImage(imageData);
|
|
|
- break;
|
|
|
- }
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
+ image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
+ BitmapImage imageData = new BitmapImage();
|
|
|
+ imageData.BeginInit();
|
|
|
+ imageData.StreamSource = ms;
|
|
|
+ imageData.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
+ imageData.EndInit();
|
|
|
+ imageData.Freeze();
|
|
|
+ Clipboard.SetImage(imageData);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -839,7 +817,7 @@ namespace PDFViewer
|
|
|
protected void OnPropertyChanged([CallerMemberName] string name = null)
|
|
|
{
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
#endregion
|
|
|
|
|
@@ -909,22 +887,15 @@ namespace PDFViewer
|
|
|
{
|
|
|
if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
|
|
|
- SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
- saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
- saveDialog.DefaultExt = ".pdf";
|
|
|
- saveDialog.OverwritePrompt = true;
|
|
|
+ CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
|
|
|
+ SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
+ saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
+ saveDialog.DefaultExt = ".pdf";
|
|
|
+ saveDialog.OverwritePrompt = true;
|
|
|
|
|
|
- if (saveDialog.ShowDialog() == true)
|
|
|
- {
|
|
|
- pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ if (saveDialog.ShowDialog() == true)
|
|
|
{
|
|
|
-
|
|
|
+ pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -937,80 +908,66 @@ namespace PDFViewer
|
|
|
{
|
|
|
if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
{
|
|
|
- try
|
|
|
+ CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
|
|
|
+ if (pdfDoc.WriteToLoadedPath())
|
|
|
{
|
|
|
- CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
|
|
|
- if (pdfDoc.WriteToLoadedPath())
|
|
|
- {
|
|
|
- pdfViewControl.PDFView.UndoManager.CanSave = false;
|
|
|
- return;
|
|
|
- }
|
|
|
+ pdfViewControl.PDFView.UndoManager.CanSave = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
- saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
- saveDialog.DefaultExt = ".pdf";
|
|
|
- saveDialog.OverwritePrompt = true;
|
|
|
+ SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
+ saveDialog.Filter = "(*.pdf)|*.pdf";
|
|
|
+ saveDialog.DefaultExt = ".pdf";
|
|
|
+ saveDialog.OverwritePrompt = true;
|
|
|
|
|
|
- if (saveDialog.ShowDialog() == true)
|
|
|
- {
|
|
|
- pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ if (saveDialog.ShowDialog() == true)
|
|
|
{
|
|
|
-
|
|
|
+ pdfDoc.WriteToFilePath(saveDialog.FileName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void OpenFile()
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- string filePath = CommonHelper.GetFilePathOrEmpty();
|
|
|
- string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
|
|
|
+ string filePath = CommonHelper.GetFilePathOrEmpty();
|
|
|
+ string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
|
|
|
|
|
|
- if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
|
|
|
+ if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
|
|
|
+ {
|
|
|
+ if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
{
|
|
|
- if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
|
|
|
- {
|
|
|
- if (oldFilePath.ToLower() == filePath.ToLower())
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
|
|
|
+ if (oldFilePath.ToLower() == filePath.ToLower())
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- passwordViewer = new PDFViewControl();
|
|
|
- passwordViewer.PDFView.InitDocument(filePath);
|
|
|
- if (passwordViewer.PDFView.Document == null)
|
|
|
- {
|
|
|
- MessageBox.Show("Open File Failed");
|
|
|
- return;
|
|
|
- }
|
|
|
+ if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (passwordViewer.PDFView.Document.IsLocked)
|
|
|
- {
|
|
|
- PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
|
|
|
- PasswordUI.ClearPassword();
|
|
|
- PopupBorder.Visibility = Visibility.Visible;
|
|
|
- PasswordUI.Visibility = Visibility.Visible;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pdfViewControl = passwordViewer;
|
|
|
- LoadDocument();
|
|
|
- FileChangeEvent?.Invoke(null, EventArgs.Empty);
|
|
|
- }
|
|
|
+ passwordViewer = new PDFViewControl();
|
|
|
+ passwordViewer.PDFView.InitDocument(filePath);
|
|
|
+ if (passwordViewer.PDFView.Document == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Open File Failed");
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
|
|
|
+ if (passwordViewer.PDFView.Document.IsLocked)
|
|
|
+ {
|
|
|
+ PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
|
|
|
+ PasswordUI.ClearPassword();
|
|
|
+ PopupBorder.Visibility = Visibility.Visible;
|
|
|
+ PasswordUI.Visibility = Visibility.Visible;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pdfViewControl = passwordViewer;
|
|
|
+ LoadDocument();
|
|
|
+ FileChangeEvent?.Invoke(null, EventArgs.Empty);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|