|
@@ -3,6 +3,7 @@ using ComPDFKit.PDFDocument;
|
|
|
using ComPDFKitViewer;
|
|
|
using ComPDFKitViewer.AnnotEvent;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
+using DotNetSpeech;
|
|
|
using ImTools;
|
|
|
using Microsoft.Win32;
|
|
|
using PDF_Master.CustomControl;
|
|
@@ -28,6 +29,7 @@ using Prism.Services.Dialogs;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
+using System.Drawing.Imaging;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
@@ -1382,13 +1384,13 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
{
|
|
|
if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
|
|
|
AnnotEvent?.UpdateAnnot();
|
|
|
}
|
|
|
else if (annot is FreeTextAnnotArgs)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (menu.tag.ToString() == "FontColor")
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
|
|
|
else
|
|
@@ -1398,7 +1400,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
}
|
|
|
else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (menu.tag.ToString() == "FillColor")
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
|
|
|
else
|
|
@@ -1408,7 +1410,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
}
|
|
|
else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
|
|
|
AnnotEvent?.UpdateAnnot();
|
|
|
}
|
|
@@ -1475,7 +1477,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
var annot = menu.Parameter as FreehandAnnotArgs;
|
|
|
if (annot != null)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (menu.tag.ToString() == "Solid")
|
|
|
{
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, AnnotTransfer.GetLineDashStyle(true));
|
|
@@ -1500,7 +1502,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
var annot = menu.Parameter as AnnotHandlerEventArgs;
|
|
|
if (annot != null)
|
|
|
{
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
|
|
|
AnnotEvent?.UpdateAnnot();
|
|
|
}
|
|
@@ -1518,7 +1520,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
{
|
|
|
var strTag = tag.ToString();
|
|
|
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (strTag == "Left")
|
|
|
{
|
|
|
AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
|
|
@@ -1575,7 +1577,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
if (annot != null && tag != null)
|
|
|
{
|
|
|
var strTag = tag.ToString();
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (strTag == "Solid")
|
|
|
{
|
|
|
var dashStyle = AnnotTransfer.GetLineDashStyle(true);
|
|
@@ -1601,7 +1603,7 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
if (annot != null && tag != null)
|
|
|
{
|
|
|
var strTag = tag.ToString();
|
|
|
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
|
|
|
+ var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
|
|
|
if (strTag == "Ver")
|
|
|
{
|
|
|
annot.SetLineVertical();
|
|
@@ -1661,29 +1663,52 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
var stampPicture = dlg.FileName;
|
|
|
if (menu.tag.ToString() == "PDF")
|
|
|
{
|
|
|
- var writeStamp = annot.GetStampDrawing();
|
|
|
- var tempDoc = new CPDFViewer();
|
|
|
- tempDoc.CreateDocument();
|
|
|
- if (tempDoc.Document == null)
|
|
|
- {
|
|
|
- AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
- alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
|
|
|
- return;
|
|
|
- }
|
|
|
- byte[] buffer;
|
|
|
- var encoder = new PngBitmapEncoder();
|
|
|
- encoder.Frames.Add(BitmapFrame.Create(writeStamp));
|
|
|
- using (var memoryStream = new MemoryStream())
|
|
|
- {
|
|
|
- encoder.Save(memoryStream);
|
|
|
- buffer = memoryStream.ToArray();
|
|
|
- }
|
|
|
-
|
|
|
- tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
|
|
|
- var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
|
|
|
- if (result)
|
|
|
- {
|
|
|
- }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var writeStamp = annot.GetStampDrawing();
|
|
|
+ var tempDoc = new CPDFViewer();
|
|
|
+ tempDoc.CreateDocument();
|
|
|
+ if (tempDoc.Document == null)
|
|
|
+ {
|
|
|
+ AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
+ alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ byte[] buffer = new byte[writeStamp.PixelWidth * writeStamp.PixelHeight * 4];
|
|
|
+ writeStamp.CopyPixels(buffer, writeStamp.PixelWidth * 4, 0);
|
|
|
+
|
|
|
+ tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
|
|
|
+ var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ #region
|
|
|
+ //之前的方法1
|
|
|
+ //var encoder = new PngBitmapEncoder();
|
|
|
+ //encoder.Frames.Add(BitmapFrame.Create(writeStamp));
|
|
|
+ //using (var memoryStream = new MemoryStream())
|
|
|
+ //{
|
|
|
+ // encoder.Save(memoryStream);
|
|
|
+ // buffer = memoryStream.ToArray();
|
|
|
+ //}
|
|
|
+
|
|
|
+ //tempDoc.Document.InsertPage(0, writeStamp.PixelWidth, writeStamp.PixelHeight, buffer, CPDFDocumentImageMode.CPDFDocumentImageModeScaleAspectFit);
|
|
|
+ //var result = tempDoc.Document.WriteToFilePath(dlg.FileName);
|
|
|
+ //if (result)
|
|
|
+ //{
|
|
|
+ //}
|
|
|
+ //之前的方法2
|
|
|
+ //string imagePath = SaveImage(writeStamp);
|
|
|
+ //if (CreateFile(imagePath, tempDoc))
|
|
|
+ //{
|
|
|
+ // bool result = tempDoc.Document.WriteToFilePath(dlg.FileName);
|
|
|
+ //}
|
|
|
+ #endregion 注释右键菜单事件
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1695,11 +1720,102 @@ namespace PDF_Master.ViewModels.Tools
|
|
|
encoder5.Save(stream5);
|
|
|
}
|
|
|
}
|
|
|
+ CommonHelper.ExplorerFile(dlg.FileName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private string SaveImage(WriteableBitmap wtbBmp)
|
|
|
+ {
|
|
|
+ string isSave = null;
|
|
|
+ if (wtbBmp == null)
|
|
|
+ {
|
|
|
+ return isSave;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DirectoryInfo tempfolder = new DirectoryInfo(Path.Combine(App.CurrentPath, "Temp"));
|
|
|
+ string strpath = Path.Combine(tempfolder.FullName, DateTime.Now.ToString("yyyyMMddfff") + ".jpg");
|
|
|
+ if (!File.Exists(tempfolder.FullName))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(tempfolder.FullName);
|
|
|
+ }
|
|
|
+
|
|
|
+ using (FileStream stream = new FileStream(strpath, FileMode.Create))
|
|
|
+ {
|
|
|
+ JpegBitmapEncoder bitmapEncoder = new JpegBitmapEncoder();
|
|
|
+ bitmapEncoder.Frames.Add(BitmapFrame.Create(wtbBmp));
|
|
|
+ bitmapEncoder.Save(stream);
|
|
|
+ isSave = strpath;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ System.Diagnostics.Debug.WriteLine(ex.ToString());
|
|
|
+ isSave = null;
|
|
|
+ }
|
|
|
+ return isSave;
|
|
|
}
|
|
|
|
|
|
+ public bool CreateFile(string imagePath = null, CPDFViewer saveToPDFViewer = null)
|
|
|
+ {
|
|
|
+ string fileName = null;
|
|
|
+
|
|
|
+ //saveToPDFViewer.CreateDocument();
|
|
|
+ //if (saveToPDFViewer.Document == null)
|
|
|
+ //{
|
|
|
+ // AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
+ // alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
|
|
|
+ // return false;
|
|
|
+ //}
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(imagePath))
|
|
|
+ {
|
|
|
+ fileName = "Blank Page.pdf";
|
|
|
+ //默认插入595*842 大小的页面
|
|
|
+ saveToPDFViewer.Document.InsertPage(0, 595, 842, null);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ fileName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1) + ".pdf";
|
|
|
+ System.Drawing.Bitmap pic = new System.Drawing.Bitmap(imagePath);
|
|
|
+ int width = pic.Size.Width;
|
|
|
+ int height = pic.Size.Height;
|
|
|
+
|
|
|
+ string ex = System.IO.Path.GetExtension(imagePath);
|
|
|
+ //其他格式或者名称中含空格的图片 在本地先转存一下
|
|
|
+ if ((ex != ".jpg" && ex != ".jpeg") || !Uri.IsWellFormedUriString(imagePath, UriKind.Absolute))
|
|
|
+ {
|
|
|
+ //将其他格式图片转换成jpg
|
|
|
+ string folderPath = Path.GetTempPath();
|
|
|
+ if (File.Exists(folderPath))
|
|
|
+ {
|
|
|
+ File.Delete(folderPath);
|
|
|
+ }
|
|
|
+ DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
|
|
|
+ if (!tempfolder.Exists)
|
|
|
+ {
|
|
|
+ tempfolder.Create();
|
|
|
+ }
|
|
|
+ string targetPath = System.IO.Path.Combine(folderPath, Guid.NewGuid().ToString());
|
|
|
+ imagePath = targetPath;
|
|
|
+ pic.Save(targetPath, ImageFormat.Jpeg);
|
|
|
+ }
|
|
|
+ pic.Dispose();
|
|
|
+
|
|
|
+ var result = saveToPDFViewer.Document.InsertPage(0, width, height, imagePath);
|
|
|
+ if (!result)
|
|
|
+ {
|
|
|
+ AlertsMessage alertsMessage = new AlertsMessage();
|
|
|
+ alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Create PDF failed"), App.ServiceLoader.GetString("Text_ok"));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
#endregion 注释右键菜单事件
|
|
|
|
|
|
#region 快捷键
|