Explorar el Código

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng hace 2 años
padre
commit
304856339c

+ 11 - 9
PDF Office/App.xaml.cs

@@ -52,6 +52,7 @@ using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomeP
 using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageWatermark;
 using PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBackground;
 using ComDocumentAIKit;
+using PDF_Office.Views.PropertyPanel.Scan;
 using PDF_Office.Views.Dialog.Redaction;
 
 namespace PDF_Office
@@ -72,9 +73,9 @@ namespace PDF_Office
 
         public static CacheFilePath CachePath;
         /// <summary>
-        /// OCR引擎对象
+        /// OCR数据模型所在目录
         /// </summary>
-        public static COCREngine ocrEngine=null;
+        public static string modelFolderPath = null;
 
         public static bool IsFirstOpen = true;
         public static bool IsBookMode = false;
@@ -237,6 +238,7 @@ namespace PDF_Office
             containerRegistry.RegisterForNavigation<TextAnnotProperty>();
             containerRegistry.RegisterForNavigation<ImageEditProperty>();
             containerRegistry.RegisterForNavigation<TextEditProperty>();
+            containerRegistry.RegisterForNavigation<ScanPropertyPanel>();
             containerRegistry.RegisterForNavigation<BatesContent>();
             containerRegistry.RegisterForNavigation<BatesTemplateListContent>();
             containerRegistry.RegisterForNavigation<BatesCreateContent>();
@@ -359,6 +361,11 @@ namespace PDF_Office
 
             try
             {
+                //加载OCR库
+                if (!DocumentAIKitLicenseVerify())
+                {
+
+                }
                 /*LicenseError licenseerror = CPDFConverter.SDKLicenseVerify(ConverterDevKey, ConverterDevSecret, ConverterUserkey, ConverterUserSecret);
                 string resPath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) + "\\";
                 if (licenseerror != LicenseError.ERR_SUCCESS)
@@ -375,11 +382,6 @@ namespace PDF_Office
                 }
                 CPDFConverter.Init(resPath);
 
-                //加载OCR库
-                if (!DocumentAIKitLicenseVerify())
-                {
-
-                }
             }
             catch { }
             return result;
@@ -394,8 +396,9 @@ namespace PDF_Office
             Task.Factory.StartNew(() =>
             {
                 string exePath = Path.GetDirectoryName(typeof(MainWindow).Assembly.Location);
+                exePath = Path.Combine(exePath, "x64");
                 string libFolderPath = Path.Combine(exePath, "DocumentAILib");
-                string modelFolderPath = Path.Combine(exePath, "models");
+                modelFolderPath = Path.Combine(exePath, "models");
 
                 if (CDocumentAIKit.LoadNativeLibrary(libFolderPath) == false)
                     return;
@@ -404,7 +407,6 @@ namespace PDF_Office
                 if (error != CErrorCode.E_DA_SUCCESS)
                     return;
 
-                ocrEngine = new COCREngine(modelFolderPath);
             });
             return true;
         }

+ 15 - 0
PDF Office/CustomControl/ImageButton.cs

@@ -74,6 +74,12 @@ namespace PDF_Office.CustomControl
         public static readonly DependencyProperty MouseOverBackgroundProperty
             = DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ImageButton));
 
+        /// <summary>
+        /// 鼠标移上去的背景颜色的透明度
+        /// </summary>
+        public static readonly DependencyProperty MouseOverBackgroundOpacityProperty
+            = DependencyProperty.Register("MouseOverBackgroundOpacity", typeof(double), typeof(ImageButton), new PropertyMetadata(1.0, null));
+
         /// <summary>  
         /// 鼠标按下去的背景颜色  
         /// </summary>  
@@ -151,6 +157,15 @@ namespace PDF_Office.CustomControl
             set { SetValue(MouseOverBackgroundProperty, value); }
         }
 
+        public double MouseOverBackgroundOpacity
+        {
+            get
+            {
+                return (double)GetValue(MouseOverBackgroundOpacityProperty);
+            }
+            set { SetValue(MouseOverBackgroundOpacityProperty, value); }
+        }
+
         public Brush MouseDownBackground
         {
             get

+ 1 - 1
PDF Office/Helper/DpiHelpers.cs

@@ -87,7 +87,7 @@ namespace PDF_Office.Helper
         {
             Rect standRect = new Rect(GetDpiUnrelatedNum(oldValue.Left), GetDpiUnrelatedNum(oldValue.Top),
                 GetDpiUnrelatedNum(oldValue.Width), GetDpiUnrelatedNum(oldValue.Height));
-            return new Rect(standRect.Left * 72D / 96D, standRect.Top * 72D / 96D, standRect.Width * 72D / 96D, standRect.Height * 72D / 96D);
+            return new Rect((int)(standRect.Left * 72D / 96D), (int)(standRect.Top * 72D / 96D), (int)(standRect.Width * 72D / 96D), (int)(standRect.Height * 72D / 96D));
         }
 
         /// <summary>

+ 44 - 10
PDF Office/PDF Office.csproj

@@ -478,6 +478,7 @@
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SignatureCreateDialogViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\PDFEdit\ImageEditPropertyViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\PDFEdit\TextEditPropertyViewModel.cs" />
+    <Compile Include="ViewModels\PropertyPanel\Scan\ScanPropertyPanelViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\ViewModular\ReadViewContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\RecentFiles\RecentFilesContentViewModel.cs" />
     <Compile Include="ViewModels\Dialog\CustomCreateDialogViewModel.cs" />
@@ -988,6 +989,9 @@
     <Compile Include="Views\PropertyPanel\PropertyPanelContent.xaml.cs">
       <DependentUpon>PropertyPanelContent.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\PropertyPanel\Scan\ScanPropertyPanel.xaml.cs">
+      <DependentUpon>ScanPropertyPanel.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\PropertyPanel\ViewModular\ReadModeContent.xaml.cs">
       <DependentUpon>ReadModeContent.xaml</DependentUpon>
     </Compile>
@@ -1706,6 +1710,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\PropertyPanel\Scan\ScanPropertyPanel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\PropertyPanel\ViewModular\ReadModeContent.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -1855,18 +1863,45 @@
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
     </None>
     <Content Include="ComDocumentAIKit.dll" />
+    <Resource Include="Resources\ToolBarIcon\Scan\enhance.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
+    <Resource Include="Resources\ToolBarIcon\Scan\ocr.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
+    <Resource Include="Resources\ToolBarIcon\Scan\batch.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Resource>
     <Content Include="source\AnalysisWord\Res\word\_rels\document.xml.rels">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
-    <None Include="x64\models\DA_image_enhance_magic_color_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Classification_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Detection_chinese_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Detection_english_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Recognition_chinese_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Recognition_chinese_cht_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Recognition_english_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Recognition_japan_1.0.0.model" />
-    <None Include="x64\models\DA_Ocr_Recognition_korean_1.0.0.model" />
+    <None Include="x64\models\DA_image_enhance_magic_color_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Classification_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Detection_chinese_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Detection_english_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Recognition_chinese_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Recognition_chinese_cht_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Recognition_english_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Recognition_japan_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Include="x64\models\DA_Ocr_Recognition_korean_1.0.0.model">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
     <Resource Include="Resources\BOTA\Annotation\Arrow.png" />
     <Resource Include="Resources\BOTA\Annotation\Bookmark.png" />
     <Resource Include="Resources\BOTA\Annotation\Circle.png" />
@@ -1959,7 +1994,6 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Views\Edit\" />
-    <Folder Include="Views\Scan\" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="ComOCRKit.Desk.dll">

BIN
PDF Office/Resources/ToolBarIcon/Scan/batch.png


BIN
PDF Office/Resources/ToolBarIcon/Scan/enhance.png


BIN
PDF Office/Resources/ToolBarIcon/Scan/ocr.png


+ 2 - 2
PDF Office/SDKLisence.xml

@@ -1,6 +1,6 @@
 <Lisences
-	devKey = "ehrnKqkWc1XSEAWyPUt6+95GzCoLEyoKrCbsUuJkCqGmxmP5ozX4bS0R6crHItQVNTFvC5mBZ1M7QjJ6Ekdu4Daj7PM+EDLTBKbFJinK4Ri9E5E2X+a9vF5zSj0TkIscQPVnwj9ikxAFOWGIyybMwQQzwc8a4j1cGOqGXQRDMMY="
-  devSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4gQurxTxGuBlGAhs0P1mD3X3bHT+AHfcLiymaqE4DY7kTFHoPs9I3tl5ErS+BHdzHRhrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1367/WkJ00tM7U7tttD6ccHhEu996bvBgqf8Sw8OekQKQq13VBewK5AckaDux4W7SGRhCUNWC4MItkr36JnXMD2tiFQYzMG8C66HYmRGSLh"
+	devKey = "BK8BcXWm+YbGRpEONe43pEJXhshAiAwWoBQgwlEUnxFBkCVal4AYW01RnbuwHCdkktvy9sAYs/SUflLR+KOMayg6z2TE2G3OhIXf95sN8k1sk947zrPGeHPtHx7gMaurYrscLDAumvtymhg4rMTg7XFKfBtchlAi0bE+wPTsqa8="
+  devSecret = "mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4iYSXB8erGstkUyaynN7k8ocNCYAAzc9CPxiym2TlqeSUWpLOaOv47bs7x+UqfQzn9hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBwyVLBY93oKLBB8UJg4t07605BGbaBKUlDopA0iGq1HSnRAJhqHxGgIZ+m3BxAFwgabp2OdkT7I9klGmA/4KertEmsKlSJ3WFqmDWhwfT73yCYDNQpuarUAQxiS1PJu8kUw=="
   userKey = "iBPRM/Tz8b6Z1G2GQt52X7hiNCGfVYXztnPjalgrgARvqfKV6lFNH8QeScTzBRYI8GGFpwelfgh790Kd9JmL7V4adI1jCiFHUT2DLT7QucxY5Nkgys2aJItQS482Ck2G2Xf8gNgojxYxRt65o/MEzkj93foj8qIdfHagXsSorSs="
 	userSecret="mG0c3O3Mzeu5dkZJW3gpqq9uA7o7EGQveSC38Q8TK4ivEHOmPIqbfhpDnKKj+7Ymj2rXQvfZRmke06HMV+3tt064G64WjPW8+EbGCNZaAh1hrp9sGpqfp0B228KI+IMTu4aGVjtYuk+Uxs/kosIBw1FKJi6HYB+DuugQyaqI2prfej861QnJrU4s2T/npZK/"
 	ConverterDevKey="Eahwo7OZAYHJaCF7TJQYKSVqC62MzfBdllVXnC5BRR5BQFDKnQ1FJtCRVdug+VNg/ti+/DeA5Sq4IH2CBpQjAZst5705uk5Sz0ZwRu8Qdn9HFGwh2pG6dJEIrl7lOccoZS6+1IxgOTcTeHqYpym3NsmtbhBWE848Pvme3scpW28="

+ 1 - 0
PDF Office/Styles/ImageButtonStyle.xaml

@@ -63,6 +63,7 @@
                         <Trigger Property="IsMouseOver" Value="True">
                             <Setter TargetName="PART_Content" Property="Foreground" Value="{Binding MouseOverForeground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
                             <Setter TargetName="PART_Border" Property="Background" Value="{Binding MouseOverBackground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
+                            <Setter TargetName="PART_Border" Property="Opacity" Value="{Binding MouseOverBackgroundOpacity, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
                             <Setter TargetName="PART_Border" Property="BorderBrush" Value="{Binding MouseOverBorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type customControl:ImageButton}}}" />
                             <Setter TargetName="PART_MouseOverIcon" Property="Visibility" Value="Visible" />
                             <Setter TargetName="PART_Icon" Property="Visibility" Value="Collapsed" />

+ 62 - 0
PDF Office/ViewModels/PropertyPanel/Scan/ScanPropertyPanelViewModel.cs

@@ -0,0 +1,62 @@
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Model;
+using Prism.Mvvm;
+using Prism.Regions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.ViewModels.PropertyPanel.Scan
+{
+    class ScanPropertyPanelViewModel : BindableBase, INavigationAware
+    {
+        private int pageCount;
+
+        public int PageCount
+        {
+            get { return pageCount; }
+            set
+            {
+                SetProperty(ref pageCount, value);
+            }
+        }
+
+        private string setPageRange;
+
+        public string SetPageRange
+        {
+            get { return setPageRange; }
+            set
+            {
+                SetProperty(ref setPageRange, value);
+            }
+        }
+
+
+        private CPDFViewer PDFViewer;
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+            return;
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+            if (PDFViewer == null)
+            {
+                return;
+            }
+            else
+            {
+                PageCount = PDFViewer.Document.PageCount;
+            }
+        }
+    }
+}

+ 203 - 2
PDF Office/ViewModels/Tools/ScanContentViewModel.cs

@@ -1,18 +1,33 @@
-using ComPDFKitViewer.PdfViewer;
+using ComDocumentAIKit;
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using ComPDFKit.PDFPage.Edit;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Helper;
 using PDF_Office.Model;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
 
 namespace PDF_Office.ViewModels.Tools
 {
     class ScanContentViewModel : BindableBase, INavigationAware
     {
+        #region 模板与导航相关内容
+
         private CPDFViewer PDFViewer;
+
+        public ViewContentViewModel viewContentViewModel;
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -20,12 +35,198 @@ namespace PDF_Office.ViewModels.Tools
 
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
-            return ;
+            return;
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+            navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
+
+        }
+
+        #endregion
+
+        private IRegionManager regions;
+        public DelegateCommand NavigationCommand { get; set; }
+        public DelegateCommand EnhancedCommand { get; set; }
+        public List<string> EnhancedFilePathList;
+        public ScanContentViewModel(IRegionManager regionManager)
+        {
+            regions = regionManager;
+            NavigationCommand = new DelegateCommand(BtnNavigation);
+            EnhancedCommand = new DelegateCommand(EnhancedScan);
+            EnhancedFilePathList = new List<string>();
+        }
+
+        /// <summary>
+        ///导航到OCR的侧边栏
+        /// </summary>
+        private void BtnNavigation()
+        {
+            //替换属性面板的内容
+            NavigationParameters parameters = new NavigationParameters();
+            parameters.Add(ParameterNames.PDFViewer, PDFViewer);
+            parameters.Add(ParameterNames.PropertyPanelContentViewModel, null);
+            regions.RequestNavigate(RegionNames.PropertyRegionName, "ScanPropertyPanel", parameters);
+            //显示属性面板
+            viewContentViewModel.IsPropertyOpen = true;
+        }
+        private void EnhancedScan()
+        {
+            CPDFDocument CurrentDoc = PDFViewer.Document;
+            string path = App.CachePath.MergeFilePath;
+            string name = Guid.NewGuid().ToString();
+            path = Path.Combine(path, name);
+            string EnhancePath = Path.Combine(path, "Enhance");
+
+            Directory.CreateDirectory(path);
+            Directory.CreateDirectory(EnhancePath);
+
+            CIMEngine imEngine = new CIMEngine(App.modelFolderPath);
+            CErrorCode error = imEngine.SetModel();
+            for (int i = 0; i < CurrentDoc.PageCount; i++)
+            {
+                string pageImagePath = Path.Combine(path, i.ToString());
+                string pageEnhancePath = Path.Combine(EnhancePath, i.ToString() + ".png");
+                try
+                {
+                    CPDFPage pdfPage = CurrentDoc.PageAtIndex(i);
+                    float zoom = (float)(DpiHelpers.Dpi / 72D);
+                    int renderWidth = (int)(pdfPage.PageSize.Width * zoom);
+                    int renderHeight = (int)(pdfPage.PageSize.Height * zoom);
+                    byte[] renderData = new byte[renderWidth * renderHeight * 4];
+                    pdfPage.RenderPageBitmapWithMatrix(zoom, new Rect(0, 0, renderWidth, renderHeight), 0xFFFFFFFF, renderData, 0);
+                    WriteableBitmap bitmap = new WriteableBitmap(renderWidth, renderHeight, DpiHelpers.Dpi, DpiHelpers.Dpi, PixelFormats.Bgra32, null);
+                    bitmap.WritePixels(new Int32Rect(0, 0, renderWidth, renderHeight), renderData, bitmap.BackBufferStride, 0);
+                    BitmapEncoder encoder = new PngBitmapEncoder();
+                    encoder.Frames.Add(BitmapFrame.Create(bitmap));
+
+                    using (FileStream imageStream = File.Create(pageImagePath))
+                    {
+                        encoder.Save(imageStream);
+                        imageStream.Flush();
+                    }
+
+                    //File.Create(pageEnhancePath);
+                    error = imEngine.Process(pageImagePath, pageEnhancePath);
+                    EnhancedFilePathList.Add(pageEnhancePath);
+                }
+                catch
+                {
+
+                }
+            }
+        }
+
+        private void OCREnhancedScan()
+        {
+            CPDFDocument EnhanceDoc = CPDFDocument.CreateDocument();
+            COCREngine imEngine = new COCREngine(App.modelFolderPath);
+            //CIMEngine imEngine = new CIMEngine(App.modelFolderPath);
+
+            string path = App.CachePath.MergeFilePath;
+            string name = Guid.NewGuid().ToString();
+            path = Path.Combine(path, name);
+            string EnhancePath = Path.Combine(path, "Enhance");
+
+            Directory.CreateDirectory(path);
+            Directory.CreateDirectory(EnhancePath);
+
+            CPDFDocument CurrentDoc = PDFViewer.Document;
+            //CurrentDoc.FilePath;
+
+            CErrorCode error = imEngine.SetModel(COCRLanguage.Chinese_S);
+            //CErrorCode error = imEngine.SetModel();
+            for (int i = 0; i < 1; i++)
+            {
+                string pageImagePath = Path.Combine(path, i.ToString());
+                string pageEnhancePath = Path.Combine(EnhancePath, i.ToString() + ".png");
+                try
+                {
+                    CPDFPage pdfPage = CurrentDoc.PageAtIndex(i);
+                    float zoom = (float)(DpiHelpers.Dpi / 72D);
+                    int renderWidth = (int)(pdfPage.PageSize.Width * zoom);
+                    int renderHeight = (int)(pdfPage.PageSize.Height * zoom);
+                    byte[] renderData = new byte[renderWidth * renderHeight * 4];
+                    pdfPage.RenderPageBitmapWithMatrix(zoom, new Rect(0, 0, renderWidth, renderHeight), 0xFFFFFFFF, renderData, 0);
+                    WriteableBitmap bitmap = new WriteableBitmap(renderWidth, renderHeight, DpiHelpers.Dpi, DpiHelpers.Dpi, PixelFormats.Bgra32, null);
+                    bitmap.WritePixels(new Int32Rect(0, 0, renderWidth, renderHeight), renderData, bitmap.BackBufferStride, 0);
+                    BitmapEncoder encoder = new PngBitmapEncoder();
+                    encoder.Frames.Add(BitmapFrame.Create(bitmap));
+
+                    using (FileStream imageStream = File.Create(pageImagePath))
+                    {
+                        encoder.Save(imageStream);
+                        imageStream.Flush();
+                    }
+
+                    //File.Create(pageEnhancePath);
+                    //error = imEngine.Process(pageImagePath, pageEnhancePath);
+                    error = imEngine.Process(pageImagePath);
+
+                    if (imEngine.OCRResultList == null)
+                        return;
+
+                    List<KeyValuePair<Rect, string>> textRectList = new List<KeyValuePair<Rect, string>>();
+                    foreach (COCRResult ocrResult in imEngine.OCRResultList)
+                    {
+                        List<Point> rectPoints = new List<Point>();
+                        for (int j = 0; j < ocrResult.position.Length; j += 2)
+                        {
+                            rectPoints.Add(new Point(ocrResult.position[j], ocrResult.position[j + 1]));
+                        }
+                        int left = (int)rectPoints.AsEnumerable().Min(x => x.X);
+                        int right = (int)rectPoints.AsEnumerable().Max(x => x.X);
+                        int top = (int)rectPoints.AsEnumerable().Min(x => x.Y);
+                        int bottom = (int)rectPoints.AsEnumerable().Max(x => x.Y);
+
+                        textRectList.Add(new KeyValuePair<Rect, string>(new Rect(left, top, right - left, bottom - top), ocrResult.text));
+                    }
+
+                    CPDFEditPage editPage = pdfPage.GetEditPage();
+
+                    editPage.BeginEdit(CPDFEditType.EditText);
+                    for (int y = textRectList.Count - 1; y >= 0; y--)
+                    {
+                        KeyValuePair<Rect, string> textBlock = textRectList[y];
+                        int fontSize = 1;
+                        Rect pdfRect = DpiHelpers.GetRawRect(textBlock.Key);
+
+                        for (; fontSize < 100; fontSize++)
+                        {
+                            Rect cmpRect = pdfPage.GetTextContentRect(fontSize, "Helvetica", textBlock.Value);
+                            if (cmpRect.Width > pdfRect.Width || cmpRect.Height > pdfRect.Height)
+                            {
+                                fontSize -= 1;
+                                break;
+                            }
+                        }
+
+                        CPDFEditTextArea editArea = editPage.CreateNewTextArea(pdfRect, "Helvetica", fontSize, new byte[] { 0, 0, 0 });
+
+                        bool x = editArea.SetTextAreaAlign(TextAlignType.AlignChar);
+                        editArea.InsertText(textBlock.Value);
+
+                    }
+                    editPage.EndEdit();
+                }
+                catch (Exception e)
+                {
+                    throw;
+                }
+            }
+            //error = imEngine.Process("C:/test/9.png", "C:/test/9IM.png");
+            imEngine.Release();
+            PDFViewer.InvalidChildVisual(true);
+            return;
+
+            //更新预览
+            //int PageIndex = PDFViewer.CurrentIndex;
+            //PDFViewer.InitDocument(EnhanceDoc);
+            //PDFViewer.GoToPage(PageIndex);
+
         }
+
     }
 }

+ 35 - 0
PDF Office/Views/PropertyPanel/Scan/ScanPropertyPanel.xaml

@@ -0,0 +1,35 @@
+<UserControl x:Class="PDF_Office.Views.PropertyPanel.Scan.ScanPropertyPanel"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PDF_Office.Views.PropertyPanel.Scan" xmlns:customcontrol="clr-namespace:PDF_Office.CustomControl"
+             mc:Ignorable="d" >
+    <Grid>
+        <StackPanel>
+        <TextBlock Text="识别文本"/>
+            <customcontrol:PathRadioButton
+                MouseOverBackground="#EDEEF0" MouseDownBackground="#CED0D4" MouseDownBackgroundOpacity="0.6" 
+                HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+                <customcontrol:PathRadioButton.Content >
+                    <TextBlock Text="页面识别"/>
+                </customcontrol:PathRadioButton.Content>
+            </customcontrol:PathRadioButton>
+            <customcontrol:PathRadioButton
+                MouseOverBackground="#EDEEF0" MouseDownBackground="#CED0D4" MouseDownBackgroundOpacity="0.6" 
+                HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
+                <customcontrol:PathRadioButton.Content >
+                    <TextBlock Text="区域识别"/>
+                </customcontrol:PathRadioButton.Content>
+            </customcontrol:PathRadioButton>
+            <ComboBox SelectedIndex="0">
+                <TextBlock Text="English"/>
+                <TextBlock Text="Chinese Simplified"/>
+                <TextBlock Text="Chinese Traditional"/>
+                <TextBlock Text="French"/>
+            </ComboBox>
+            <customcontrol:WritableComboBox SelectedIndex="0" MaxPageRange="{Binding PageCount}" Text="{Binding SetPageRange,Mode=TwoWay}"/>
+            <Button Content="OCR"/>
+        </StackPanel>
+    </Grid>
+</UserControl>

+ 28 - 0
PDF Office/Views/PropertyPanel/Scan/ScanPropertyPanel.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PDF_Office.Views.PropertyPanel.Scan
+{
+    /// <summary>
+    /// ScanPropertyPanel.xaml 的交互逻辑
+    /// </summary>
+    public partial class ScanPropertyPanel : UserControl
+    {
+        public ScanPropertyPanel()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 25 - 4
PDF Office/Views/Tools/ScanContent.xaml

@@ -3,10 +3,31 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PDF_Office.Views.Tools"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
+             xmlns:local="clr-namespace:PDF_Office.Views.Tools" xmlns:customcontrol="clr-namespace:PDF_Office.CustomControl" xmlns:tools="clr-namespace:PDF_Office.ViewModels.Tools" d:DataContext="{d:DesignInstance Type=tools:ScanContentViewModel}"
+             mc:Ignorable="d" >
     <Grid>
-            
+        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <customcontrol:ImageButton HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
+            Padding="3" Command="{Binding EnhancedCommand}"
+            MouseOverBackground="#000000" MouseOverBackgroundOpacity="0.25"
+            Icon="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/enhance.png"  
+            IconPress="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/enhance.png"  
+            IconMouseOver="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/enhance.png"
+            Background="Transparent" Content="增强扫描"/>
+            <customcontrol:ImageButton HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
+            Padding="3" Command="{Binding NavigationCommand}"
+            MouseOverBackground="#000000" MouseOverBackgroundOpacity="0.25"                         
+            Icon="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/ocr.png"  
+            IconPress="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/ocr.png"  
+            IconMouseOver="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/ocr.png"
+            Background="Transparent" Content="识别文本"/>
+            <customcontrol:ImageButton HorizontalContentAlignment="Center" VerticalContentAlignment="Center" 
+            Padding="3"
+            MouseOverBackground="#000000" MouseOverBackgroundOpacity="0.25"
+            Icon="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/batch.png"  
+            IconPress="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/batch.png"  
+            IconMouseOver="pack://application:,,,/PDF Office;component/Resources/ToolBarIcon/Scan/batch.png"
+            Background="Transparent" Content="批量识别文本"/>
+        </StackPanel>
     </Grid>
 </UserControl>