Prechádzať zdrojové kódy

分包下载-部分逻辑,移除OCR相关库

liyijie 1 rok pred
rodič
commit
8ef4ec6634

+ 5 - 1
PDF Office/App.xaml.cs

@@ -745,6 +745,9 @@ namespace PDF_Master
             //chatgtp
             //chatgtp
             containerRegistry.RegisterDialog<DocumentaryTranslationDialog>(DialogNames.DocumentaryTranslation);
             containerRegistry.RegisterDialog<DocumentaryTranslationDialog>(DialogNames.DocumentaryTranslation);
             containerRegistry.RegisterDialog<SelectedTranslationDialog>(DialogNames.SelectedTranslation);
             containerRegistry.RegisterDialog<SelectedTranslationDialog>(DialogNames.SelectedTranslation);
+
+            //OCR下载弹窗
+            containerRegistry.RegisterDialog<OCRDownloadProgress>(DialogNames.OCRDownloadProgress);
             
             
 
 
             #endregion 注册弹窗
             #endregion 注册弹窗
@@ -823,11 +826,12 @@ namespace PDF_Master
                
                
                 string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
                 string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
                 CPDFConverter.Init(resPath);
                 CPDFConverter.Init(resPath);
+                
                 LicenseError licenseerror = CPDFConverter.LicenseVerify(ConverterDevKey, ConverterDevSecret);
                 LicenseError licenseerror = CPDFConverter.LicenseVerify(ConverterDevKey, ConverterDevSecret);
                 //初始化ocr库
                 //初始化ocr库
                 CPDFConverter.InitOcrLibrary(Path.Combine(resPath, "x64"));
                 CPDFConverter.InitOcrLibrary(Path.Combine(resPath, "x64"));
                 //初始化资源
                 //初始化资源
-                CPDFConverter.SetOCRModelPath(Path.Combine(resPath, "source", "models"));
+                CPDFConverter.SetOCRModelPath(Path.Combine(resPath, "source"));
                 if (licenseerror != LicenseError.ERR_SUCCESS)
                 if (licenseerror != LicenseError.ERR_SUCCESS)
                 {
                 {
                     //MessageBox.Show("ComPDFKit Conversion SDK Load Failed!");
                     //MessageBox.Show("ComPDFKit Conversion SDK Load Failed!");

+ 183 - 0
PDF Office/Helper/FileComparisonHelper.cs

@@ -0,0 +1,183 @@
+using PDF_Master.Properties;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml;
+
+namespace PDF_Master.Helper
+{
+    public static class FileComparisonHelper
+    {
+#if DEBUG
+        public static string URI_AppXml = "http://test-pdf-pro.kdan.cn:3021/downloads/pdfreaderprocast_win_en_Us.xml";
+#else
+        public static string URI_AppXml = "https://www.pdfreaderpro.com/downloads/pdfreaderprocast_win_en_Us.xml";
+#endif
+
+        private static string OCRmodelMD5 = "";
+
+        /// <summary>
+        /// 获取文件MD5
+        /// </summary>
+        /// <param name="folderPath">文件路径</param>
+        /// <returns></returns>
+        public static string CalculateFileMD5(string filePath)
+        {
+            using (var md5 = MD5.Create())
+            {
+                using (var stream = File.OpenRead(filePath))
+                {
+                    var hash = md5.ComputeHash(stream);
+                    return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+                }
+            }
+        }
+
+        /// <summary>
+        /// 获取文件夹MD5
+        /// </summary>
+        /// <param name="folderPath">文件路径</param>
+        /// <returns></returns>
+        public static string CalculateFolderMD5(string folderPath)
+        {
+            var files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories);
+            using (var md5 = MD5.Create())
+            {
+                //遍历文件夹获取,各个文件夹MD5合并为一个MD5
+                foreach (var file in files)
+                {
+                    var fileHash = CalculateFileMD5(file);
+                    var hashBytes = Encoding.UTF8.GetBytes(fileHash);
+                    md5.TransformBlock(hashBytes, 0, hashBytes.Length, hashBytes, 0);
+                }
+
+                md5.TransformFinalBlock(new byte[0], 0, 0);
+                var hash = md5.Hash;
+                return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+            }
+        }
+
+
+        /// <summary>
+        /// 判断OCR资源是否存在
+        /// </summary>
+        public static bool OCRModelItExist()
+        {
+
+            string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+            if (Directory.Exists(folderPath))
+            {
+                if (!Getpdfreaderprocast())
+                {
+                    return false;
+                }
+                string folderMD5 = FileComparisonHelper.CalculateFolderMD5(folderPath);
+                if (folderMD5 == Settings.Default.AppProperties.OCRmodelMD5)
+                {
+                    return true;
+                }
+            }
+            else
+            {
+                Console.WriteLine("文件夹不存在");
+            }
+            if (!Getpdfreaderprocast())
+            {
+                return false;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 删除OCR资源
+        /// </summary>
+        public static void RemoveOCRModel()
+        {
+            try
+            {
+                string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+                if (Directory.Exists(folderPath))
+                {
+                    Directory.Delete(folderPath, true);
+                }
+                string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+                if (Directory.Exists(folderzipPath))
+                {
+                    Directory.Delete(folderzipPath, true);
+                }
+            }
+            catch
+            {
+
+            }
+        }
+
+        /// <summary>
+        /// 获取OCR下载信息
+        /// </summary>
+        /// <returns></returns>
+        public static bool Getpdfreaderprocast()
+        {
+            if (string.IsNullOrEmpty(Settings.Default.AppProperties.OCRFile_Url) && string.IsNullOrEmpty(Settings.Default.AppProperties.OCRmodelMD5))
+            {
+                string folder = System.IO.Path.Combine(App.CurrentPath, "AppXml");
+                DirectoryInfo directory = new DirectoryInfo(folder);
+                try
+                {
+                    if (!directory.Exists)
+                    {
+                        directory.Create();
+
+                    }
+
+                    string FileNameAppxml = folder + "\\" + "appxml" + ".xml";
+                    //下载What`s new
+                    WebClient client = new WebClient();
+                    client.DownloadFile(URI_AppXml, FileNameAppxml);
+                    XmlDocument xmlDoc = new XmlDocument();
+                    xmlDoc.Load(FileNameAppxml);
+                    XmlNode root = xmlDoc.DocumentElement;
+                    //获取OCR信息父节点
+                    XmlNode itemNodes = root.SelectSingleNode("channel/item/ocrenclosure");
+                    //获取OCR信息子节点个数
+                    int siblingCount = 0;
+                    foreach (XmlNode itemNode in itemNodes)
+                    {
+                        XmlNode parentNode = itemNode.ParentNode;
+                        siblingCount = parentNode.ChildNodes.Count;
+                    }
+                    //遍历子节点
+                    for (int i = 0; i < siblingCount; i++)
+                    {
+                        //对应子节点对象
+                        XmlNode itemNode = root.SelectSingleNode("channel/item/ocrenclosure/ocrenclosure" + i);
+                        XmlAttribute ocrstartversionUrlAttribute = itemNode.Attributes["sparkle:startversion"];
+                        XmlAttribute ocrendversionUrlAttribute = itemNode.Attributes["sparkle:endversion"];
+                        //版本号区间
+                        Version ocrendversion = new Version(ocrendversionUrlAttribute.Value);
+                        Version ocrstartversion = new Version(ocrstartversionUrlAttribute.Value);
+                        Version Appversion = new Version(App.Version);
+                        if (ocrstartversion <= Appversion && Appversion <= ocrendversion)
+                        {
+                            //获取OCR下载链接
+                            XmlAttribute ocrUrlAttribute = itemNode.Attributes["ocrurl"];
+                            Settings.Default.AppProperties.OCRFile_Url = ocrUrlAttribute?.Value;
+                            //获取OCRMD5
+                            XmlAttribute ocrUrlAttributemd5 = itemNode.Attributes["ocrmd5"];
+                            Settings.Default.AppProperties.OCRmodelMD5 = ocrUrlAttributemd5?.Value;
+                            return true;
+                        }
+                    }
+                    //return true;
+                }
+                catch { return false; }
+            }
+            return true;
+        }
+    }
+}

+ 2 - 0
PDF Office/Model/DialogNames.cs

@@ -244,5 +244,7 @@ namespace PDF_Master.Model
         public static string DocumentaryTranslation = "DocumentaryTranslationDialog";
         public static string DocumentaryTranslation = "DocumentaryTranslationDialog";
 
 
         public static string SelectedTranslation = "SelectedTranslationDialog";
         public static string SelectedTranslation = "SelectedTranslationDialog";
+
+        public static string OCRDownloadProgress = "OCRDownloadProgress";
     }
     }
 }
 }

+ 9 - 15
PDF Office/PDF Master.csproj

@@ -399,6 +399,7 @@
     <Compile Include="Helper\CropPageUndoManager.cs" />
     <Compile Include="Helper\CropPageUndoManager.cs" />
     <Compile Include="Helper\DataTrackingHelper.cs" />
     <Compile Include="Helper\DataTrackingHelper.cs" />
     <Compile Include="Helper\ErrorCodeHelper.cs" />
     <Compile Include="Helper\ErrorCodeHelper.cs" />
+    <Compile Include="Helper\FileComparisonHelper.cs" />
     <Compile Include="Helper\GlobalCommands.cs" />
     <Compile Include="Helper\GlobalCommands.cs" />
     <Compile Include="Helper\KeyEventsHelper.cs" />
     <Compile Include="Helper\KeyEventsHelper.cs" />
     <Compile Include="Helper\Win32Helper.cs" />
     <Compile Include="Helper\Win32Helper.cs" />
@@ -627,6 +628,7 @@
     <Compile Include="ViewModels\HomePanel\HomeChatGPTAIContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeChatGPTAIContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\PDFTools\PDFToolsContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\PDFTools\PDFToolsContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\PDFTools\QuickToolsContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\PDFTools\QuickToolsContentViewModel.cs" />
+    <Compile Include="ViewModels\Dialog\ConverterDialogs\OCRDownloadProgressViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SignatureAnnotPropertyViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SignatureAnnotPropertyViewModel.cs" />
     <Compile Include="ViewModels\Dialog\SignatureCreateDialogViewModel.cs" />
     <Compile Include="ViewModels\Dialog\SignatureCreateDialogViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SnapshotEditMenuViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SnapshotEditMenuViewModel.cs" />
@@ -786,6 +788,9 @@
     <Compile Include="Views\Dialog\BOTA\BookmarkInfoDialog.xaml.cs">
     <Compile Include="Views\Dialog\BOTA\BookmarkInfoDialog.xaml.cs">
       <DependentUpon>BookmarkInfoDialog.xaml</DependentUpon>
       <DependentUpon>BookmarkInfoDialog.xaml</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="Views\Dialog\ConverterDialogs\OCRDownloadProgress.xaml.cs">
+      <DependentUpon>OCRDownloadProgress.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\Dialog\FullScreenWindow.xaml.cs">
     <Compile Include="Views\Dialog\FullScreenWindow.xaml.cs">
       <DependentUpon>FullScreenWindow.xaml</DependentUpon>
       <DependentUpon>FullScreenWindow.xaml</DependentUpon>
     </Compile>
     </Compile>
@@ -1563,6 +1568,10 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
+    <Page Include="Views\Dialog\ConverterDialogs\OCRDownloadProgress.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\Dialog\FullScreenWindow.xaml">
     <Page Include="Views\Dialog\FullScreenWindow.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
@@ -2378,9 +2387,6 @@
     <Resource Include="Resources\Service\merging.png" />
     <Resource Include="Resources\Service\merging.png" />
     <Resource Include="Resources\Service\AI.png" />
     <Resource Include="Resources\Service\AI.png" />
     <Resource Include="Resources\Service\merge.png" />
     <Resource Include="Resources\Service\merge.png" />
-    <Content Include="source\models\OCR.model">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
     <Resource Include="Resources\ToolBarIcon\Scan\enhance.png">
     <Resource Include="Resources\ToolBarIcon\Scan\enhance.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Resource>
     </Resource>
@@ -2649,21 +2655,12 @@
     <Content Include="Updater\NetSparkleUpdater.UI.WinForms.dll" />
     <Content Include="Updater\NetSparkleUpdater.UI.WinForms.dll" />
     <Content Include="Updater\zh-CN\NetSparkleUpdater.UI.WinForms.resources.dll" />
     <Content Include="Updater\zh-CN\NetSparkleUpdater.UI.WinForms.resources.dll" />
     <Content Include="Updater\zh-TW\NetSparkleUpdater.UI.WinForms.resources.dll" />
     <Content Include="Updater\zh-TW\NetSparkleUpdater.UI.WinForms.resources.dll" />
-    <Content Include="x64\ComDocumentAINative.dll">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
     <Content Include="x64\ComPDFKit.dll">
     <Content Include="x64\ComPDFKit.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
     </Content>
     <Content Include="x64\CPDFConverterNative.dll">
     <Content Include="x64\CPDFConverterNative.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
     </Content>
-    <Content Include="x64\DocumentAI.dll">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
-    <Content Include="x64\onnxruntime.dll">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
     <Content Include="x64\opencv_world420.dll">
     <Content Include="x64\opencv_world420.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
     </Content>
@@ -2673,9 +2670,6 @@
     <Content Include="x64\libpng16.dll">
     <Content Include="x64\libpng16.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
     </Content>
-    <Content Include="x64\paddle2onnx.dll">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
     <Content Include="x64\TechPDFKit.dll">
     <Content Include="x64\TechPDFKit.dll">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
     </Content>

+ 3 - 0
PDF Office/ViewModels/Dialog/ConverterDialogs/ConverterWordDialogViewModel.cs

@@ -125,6 +125,9 @@ namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
             set
             set
             {
             {
                 SetProperty(ref oCRCheckBoxIsCheckBox, value);
                 SetProperty(ref oCRCheckBoxIsCheckBox, value);
+                //测试代码,到时候需要去除
+                //CPDFConverter.InitOcrLibrary(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\ConvertAndOCRSource", "x64"));
+                //CPDFConverter.SetOCRModelPath(Path.Combine("C:\\Users\\kdanmobile\\Documents\\PDF Master\\ConvertAndOCRSource", "source", "models"));
                 ConverterWordModel.Options.IsAllowOCR = oCRCheckBoxIsCheckBox;
                 ConverterWordModel.Options.IsAllowOCR = oCRCheckBoxIsCheckBox;
             }
             }
         }
         }

+ 440 - 0
PDF Office/ViewModels/Dialog/ConverterDialogs/OCRDownloadProgressViewModel.cs

@@ -0,0 +1,440 @@
+using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Interop.Excel;
+using PDF_Master.CustomControl;
+using PDF_Master.Helper;
+using PDF_Master.Properties;
+using PDF_Master.Strings.MainPage;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PDF_Master.ViewModels.Dialog.ConverterDialogs
+{
+    public class OCRDownloadProgressViewModel : BindableBase, IDialogAware
+    {
+        public string Title => throw new NotImplementedException();
+
+        private string T_progressBarName;
+
+        public string T_ProgressBarName
+        {
+            get { return T_progressBarName; }
+            set
+            {
+                SetProperty(ref T_progressBarName, value);
+            }
+        }
+
+        private string T_tryAgainBtn;
+
+        public string T_TryAgainBtn
+        {
+            get { return T_tryAgainBtn; }
+            set
+            {
+                SetProperty(ref T_tryAgainBtn, value);
+            }
+        }
+
+        private string T_errorTextBlock;
+
+        public string T_ErrorTextBlock
+        {
+            get { return T_errorTextBlock; }
+            set
+            {
+                SetProperty(ref T_errorTextBlock, value);
+            }
+        }
+
+        private string T_cancelBtn;
+
+        public string T_CancelBtn
+        {
+            get { return T_cancelBtn; }
+            set
+            {
+                SetProperty(ref T_cancelBtn, value);
+            }
+        }
+
+        private void SetLangText()
+        {
+            T_ProgressBarName = App.MainPageLoader.GetString("OCR_Downloading");
+            T_tryAgainBtn = App.MainPageLoader.GetString("OCR_DownloadRedownload");
+            T_ErrorTextBlock = App.MainPageLoader.GetString("OCR_DownloadError");
+            T_CancelBtn= App.MainPageLoader.GetString("OCR_CancelDownload");
+
+        }
+
+        private Visibility errorStackPanelVisible = Visibility.Collapsed;
+
+        public Visibility ErrorStackPanelVisible
+        {
+            get { return errorStackPanelVisible; }
+            set
+            {
+                SetProperty(ref errorStackPanelVisible, value);
+            }
+        }
+
+        private Visibility tryAgainBtnVisible = Visibility.Collapsed;
+
+        public Visibility TryAgainBtnVisible
+        {
+            get { return tryAgainBtnVisible; }
+            set
+            {
+                SetProperty(ref tryAgainBtnVisible, value);
+            }
+        }
+
+        System.Net.WebClient client = null;
+
+        private MainPage mainPage = null;
+
+        public string exePath = "";
+
+        private string FileNameComPDFKit = "";
+
+        private bool isItemClieck = false;
+
+        private bool isDownloadCancelled = false;
+
+        private CPDFViewer Pdfviewer { set; get; }
+
+        private string password = "";
+
+        private double currentSize;
+
+        //home 是false
+        private bool SelectHomeOrmain = false;
+
+
+        private string progressBarCurrentSizeValue="0 MB";
+
+        public string ProgressBarCurrentSizeValue
+        {
+            get { return progressBarCurrentSizeValue; }
+            set
+            {
+                SetProperty(ref progressBarCurrentSizeValue, value);
+            }
+        }
+
+        private string progressBarFileSize="0 MB";
+
+        public string ProgressBarFileSize
+        {
+            get { return progressBarFileSize; }
+            set
+            {
+                SetProperty(ref progressBarFileSize, value);
+            }
+        }
+
+        private double progressBarCurrentValue = 0;
+
+        public double ProgressBarCurrentValue
+        {
+            get { return progressBarCurrentValue; }
+            set
+            {
+                SetProperty(ref progressBarCurrentValue, value);
+            }
+        }
+
+        #region 委托声明
+
+        public DelegateCommand CancelCommand { get; set; }
+
+        public DelegateCommand TryAgainCommnad { get; set; }
+
+        #endregion
+
+        public OCRDownloadProgressViewModel()
+        {
+            CancelCommand= new DelegateCommand(cancel);
+            TryAgainCommnad= new DelegateCommand(tryAgain);
+        }
+
+        private async void  tryAgain()
+        {
+            try
+            {
+                client = null;
+                FileComparisonHelper.RemoveOCRModel();
+                FileComparisonHelper.Getpdfreaderprocast();
+                await DownloadOCR();
+            }
+            catch
+            {
+                await Task.Delay(100);
+                ErrorStackPanelVisible = Visibility.Visible;
+                TryAgainBtnVisible = Visibility.Visible;
+            }
+        }
+
+        private void cancel()
+        {
+            isDownloadCancelled = true;
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+
+        public async Task<bool> DownloadOCR()
+        {
+            bool canDownloadCancelled = false;
+            ErrorStackPanelVisible = Visibility.Collapsed;
+            TryAgainBtnVisible = Visibility.Collapsed;
+            try
+            {
+                await Task.Run(() =>
+                {
+
+                    string folder = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+
+                    FileNameComPDFKit = folder + "\\" + "model" + ".zip";
+                    long fileSize = 0;
+                    if (!Directory.Exists(folder))
+                    {
+
+
+                        Directory.CreateDirectory(folder);
+                        client = new System.Net.WebClient();
+                        System.Net.WebRequest request = System.Net.WebRequest.Create(Settings.Default.AppProperties.OCRFile_Url);
+                        request.Method = "HEAD";
+
+                        using (System.Net.WebResponse response = request.GetResponse())
+                        {
+                            if (long.TryParse(response.Headers.Get("Content-Length"), out long contentLength))
+                            {
+                                fileSize = contentLength;
+                                App.Current.Dispatcher.Invoke(() =>
+                                {
+                                    ProgressBarFileSize = ((double)fileSize / (1024 * 1024)).ToString("0.00") + " MB";
+                                    currentSize = ((double)fileSize / (1024 * 1024));
+                                });
+                            }
+                        }
+                        client.DownloadProgressChanged += Client_DownloadProgressChanged;
+                        client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(DownloadCompleted);
+                        client.DownloadFileAsync(new Uri(Settings.Default.AppProperties.OCRFile_Url), FileNameComPDFKit);
+                    }
+                    canDownloadCancelled = true;
+                });
+                return canDownloadCancelled;
+            }
+            catch
+            {
+                canDownloadCancelled = false;
+                ErrorStackPanelVisible = Visibility.Visible;
+                TryAgainBtnVisible = Visibility.Visible;
+                //Close();
+                return canDownloadCancelled;
+
+            }
+
+        }
+
+        private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
+        {
+            string folderPath = App.CurrentPath;
+            //解压转档资源文件,intiRes
+            string folderModelPath = App.CurrentPath;
+            if (!Directory.Exists(folderModelPath + "//model"))
+            {
+                ExtractWithProgress(FileNameComPDFKit, folderModelPath);
+            }
+            exePath = folderModelPath;
+
+        }
+
+        public void ExtractWithProgress(string sourceZipFilePath, string destinationFolderPath)
+        {
+            var extractedCount = 0;
+            if (System.IO.File.Exists(sourceZipFilePath))
+            {
+                try
+                {
+                    using (var zip = ZipFile.OpenRead(sourceZipFilePath))
+                    {
+                        var totalEntries = zip.Entries.Count;
+                        var progressStep = totalEntries / 20;
+
+                        foreach (var entry in zip.Entries)
+                        {
+                            var extractionPath = System.IO.Path.Combine(destinationFolderPath, entry.FullName);
+
+                            if (entry.Name == "")
+                            {
+                                // 处理目录的情况,例如在ZIP文件中的文件夹
+                                Directory.CreateDirectory(extractionPath);
+                                continue;
+                            }
+
+                            var entryDirectoryName = System.IO.Path.GetDirectoryName(extractionPath);
+                            if (!Directory.Exists(entryDirectoryName))
+                            {
+                                Directory.CreateDirectory(entryDirectoryName);
+                            }
+
+                            entry.ExtractToFile(extractionPath, true);
+                            extractedCount++;
+
+                            // 更新进度条:输出百分比或者使用其他进度条组件
+                            App.Current.Dispatcher.Invoke(() =>
+                            {
+                                ProgressBarCurrentValue = extractedCount / progressStep + 80;
+                                ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
+                                Trace.WriteLine("进度条 : " + ProgressBarCurrentValue);
+                            });
+                        }
+                    }
+                    App.Current.Dispatcher.Invoke(() =>
+                    {
+                        ProgressBarCurrentValue = 0;
+                        ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
+                        string folderzipPath = System.IO.Path.Combine(App.CurrentPath, "modelzip");
+                        if (Directory.Exists(folderzipPath))
+                        {
+                            Directory.Delete(folderzipPath, true);
+                        }
+                        //Close();
+                        if (FileComparisonHelper.OCRModelItExist())
+                        {
+                            if (SelectHomeOrmain)
+                            {
+                                if (mainPage != null)
+                                {
+                                    //mainPage.ShowOCRDialog(isItemClieck);
+                                }
+
+                            }
+                            else
+                            {
+                                //新OCR弹窗
+                                //ConvertOCRNewDialog convertOCRNewDialog = new ConvertOCRNewDialog();
+                                //convertOCRNewDialog.InitBeforeShow(Pdfviewer, password);
+                                //convertOCRNewDialog.Owner = App.Current.MainWindow;
+                                //convertOCRNewDialog.ShowDialog();
+                                //ConvertOCRDialog dialog = new ConvertOCRDialog();
+                                //dialog.InitBeforeShow(Pdfviewer, password);
+                                //dialog.StartPosition = FormStartPosition.CenterScreen;
+                                //dialog.ShowDialog();
+
+                            }
+                        }
+                        else
+                        {
+                            string folderPath = System.IO.Path.Combine(App.CurrentPath, "model");
+                            if (Directory.Exists(folderPath))
+                            {
+                                Directory.Delete(folderPath, true);
+                            }
+                            MessageBoxEx.Show("需要更新最新版的APP才能下载哦");
+
+                        }
+
+
+
+                    });
+                }
+                catch
+                {
+                    App.Current.Dispatcher.Invoke(() =>
+                    {
+                        ProgressBarCurrentValue = 0;
+                        ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
+                        //Close();
+                        ErrorStackPanelVisible = Visibility.Visible;
+                        TryAgainBtnVisible = Visibility.Visible;
+                    });
+                }
+            }
+            else
+            {
+                App.Current.Dispatcher.Invoke(() =>
+                {
+                    ProgressBarCurrentValue = 0;
+                    ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
+                    ErrorStackPanelVisible = Visibility.Visible;
+                    TryAgainBtnVisible = Visibility.Visible;
+                    //Close();
+                });
+
+            }
+
+        }
+
+        private void Client_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
+        {
+            App.Current.Dispatcher.Invoke(() =>
+            {
+                ProgressBarCurrentValue = e.ProgressPercentage * 0.8;
+                ProgressBarCurrentSizeValue = (currentSize * (ProgressBarCurrentValue / 100)).ToString("0.00") + " MB";
+            });
+            if (isDownloadCancelled)
+            {
+                if (client != null)
+                {
+                    App.Current.Dispatcher.Invoke(() =>
+                    {
+                        client.CancelAsync();
+                    });
+                }
+
+                // 执行其他取消操作
+                // ...
+            }
+        }
+
+        public bool? ShowDialog(MainPage mainPage, bool isItemClieck)
+        {
+            this.mainPage = mainPage;
+            this.isItemClieck = isItemClieck;
+            SelectHomeOrmain = true;
+            return false;
+            //return base.ShowDialog();
+        }
+
+        public bool? ShowDialog(CPDFViewer kmpdfviewer, string password)
+        {
+            Pdfviewer = kmpdfviewer;
+            this.password = password;
+            SelectHomeOrmain = false;
+            return false;
+        }
+
+        private async void Window_Loaded(object sender, RoutedEventArgs e)
+        {
+
+            await DownloadOCR();
+        }
+
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+
+        }
+    }
+}

+ 96 - 0
PDF Office/Views/Dialog/ConverterDialogs/OCRDownloadProgress.xaml

@@ -0,0 +1,96 @@
+<UserControl x:Class="PDF_Master.Views.Dialog.ConverterDialogs.OCRDownloadProgress"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        mc:Ignorable="d"
+        Loaded="Window_Loaded"
+        Background="Transparent" Width="374"
+                Height="120" >
+    <Grid>
+        <Border
+              Name="ProgressVisible"  Panel.ZIndex="1" Background="Transparent" Visibility="Visible">
+            <Border 
+                Width="374"
+                Height="120"
+                Background="#FFFFFF"
+                BorderBrush="Gray"
+                BorderThickness="1"
+                CornerRadius="4"
+                >
+                <Grid>
+                    <Grid Margin="16,18,16,0" 
+                Height="54" Background="Transparent" VerticalAlignment="Top">
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Name="ProgressBarName" Foreground="#000000" Text="{Binding T_ProgressBarName}" />
+                            <TextBlock
+                            Margin="16,0,0,0"
+                            Text="("
+                            Foreground="#000000"
+                            Visibility="Visible" />
+                            <TextBlock
+                            Name="ProgressBarCurrentSize"
+                            Foreground="#000000"
+                            Visibility="Visible" Text="{Binding ProgressBarCurrentSizeValue}" />
+                            <TextBlock
+                            Text="/"
+                            Foreground="#000000"
+                            Visibility="Visible" />
+                            <TextBlock
+                            Name="ProgressBarSize"
+                            Foreground="#000000"
+                            Visibility="Visible" Text="{Binding ProgressBarFileSize}"/>
+                            <TextBlock
+                            Text=")"
+                            Foreground="#000000"
+                            Visibility="Visible" />
+                        </StackPanel>
+                        <Button
+                        Width="12"
+                        Height="12"
+                        Padding="0,0,1,1"
+                        Margin="0,0,0,0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Top"
+                        BorderThickness="0"
+                        Background="Transparent"
+                        Command="{Binding CancelCommand}"
+                        Visibility="Visible">
+                            <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
+                        </Button>
+                        <StackPanel Orientation="Horizontal" 
+                        Margin="0,0,0,0"
+                        VerticalAlignment="Bottom" Background="Transparent">
+                            <ProgressBar
+                        Margin="0,0,18,0"
+                        Name="ProgressBar"
+                        Height="5"
+                        Width="280"
+                        BorderThickness="0"
+                        Foreground="Green"
+                        Maximum="100"
+                        Value="{Binding ProgressBarCurrentValue}" />
+                            <TextBlock
+                            FontSize="12"
+                            Foreground="#666666"
+                            Text="{Binding ElementName=ProgressBar,Path=Value, StringFormat={}{0}%}"
+                             />
+                        </StackPanel>
+
+                    </Grid>
+                    <StackPanel Name="errorStackPanel" Orientation="Horizontal" VerticalAlignment="Bottom" Visibility="{Binding ErrorStackPanelVisible}"  Margin="16,18">
+                        <Grid Width="14" Height="14" Margin="4,0,8,0" VerticalAlignment="Center">
+                            <Ellipse Width="12" Height="12" Fill="#F3465B"></Ellipse>
+                            <Path  Data="M7.25 4V9H8.75V4H7.25ZM7.25 10.5V12H8.75L8.75 10.5H7.25Z" Fill="white" Margin="-1,-1,1,1" />
+                        </Grid>
+                        <TextBlock Name="ErrorTextBlock" Text="{Binding T_ErrorTextBlock}" Foreground="#F3465B"  FontSize="11" VerticalAlignment="Center"></TextBlock>
+                    </StackPanel>
+                    <StackPanel  Orientation="Horizontal" VerticalAlignment="Bottom" Visibility="Visible" HorizontalAlignment="Right" Margin="16,13">
+                        <Button Name="tryAgainBtn" Width="60" Height="24" Margin="0,0,8,0" Content="{Binding T_TryAgainBtn}"  Style="{StaticResource Btn.cta}" Click="button1_Click" Command="{Binding TryAgainCommnad}"   Visibility="{Binding tryAgainBtnVisible}"></Button>
+                        <Button Name="CancelBtn" Width="60" Height="24" Content="{Binding T_CancelBtn}" Style="{StaticResource btn.sec}"  Command="{Binding CancelCommand}"  BorderThickness="1" ></Button>
+                    </StackPanel>
+                </Grid>
+            </Border>
+        </Border>
+    </Grid>
+</UserControl>

+ 15 - 0
PDF Office/Views/Dialog/ConverterDialogs/OCRDownloadProgress.xaml.cs

@@ -0,0 +1,15 @@
+using System.Windows.Controls;
+
+namespace PDF_Master.Views.Dialog.ConverterDialogs
+{
+    /// <summary>
+    /// Interaction logic for OCRDownloadProgress
+    /// </summary>
+    public partial class OCRDownloadProgress : UserControl
+    {
+        public OCRDownloadProgress()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 6 - 0
PDFSettings/APPSettingProperties.cs

@@ -59,6 +59,12 @@ namespace PDFSettings
         /// 登录密钥
         /// 登录密钥
         /// </summary>
         /// </summary>
         public string LoginToken = "";
         public string LoginToken = "";
+
+        //OCR文件下载链接
+        public string OCRFile_Url = "";
+
+        //OCRMD5
+        public string OCRmodelMD5 = "";
     }
     }
 
 
     public class DescriptionPropertyClass
     public class DescriptionPropertyClass