Browse Source

打印 - 性能问题

liuaoran 2 years ago
parent
commit
9755d75fff

+ 5 - 0
PDF Office/Model/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogModel.cs

@@ -86,6 +86,11 @@ namespace PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePagePrinter
         /// </summary>
         public bool needRerendering = true;
 
+        /// <summary>
+        /// 解决一直获取纸张信息引发卡顿的问题
+        /// </summary>
+        public bool IsPaperSizeChanged = false;
+
         public PrintSettingsInfo()
         {
             PrintDocument.DefaultPageSettings.Landscape = false;

+ 4 - 27
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs

@@ -393,14 +393,13 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         /// </summary>
         public void SetPaper()
         {
-            if (true)
-            {
                 PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
                 pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;
                 pageSetupDialog.Document.DefaultPageSettings.Margins = new Margins((int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Left * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Right * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Top * 2.54), (int)(PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins.Bottom * 2.54));
 
                 if (pageSetupDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
+                    PrintSettingsInfo.IsPaperSizeChanged= true;
                     PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
 
                     if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
@@ -412,30 +411,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                         PrintOrientationIndex = 1;
                     }
                     this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
-                }
-            }
-            else
-            {
-                printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
-                LoadPrinterSettings();
-                DialogParameters value = new DialogParameters();
-                value.Add("Unicode", Unicode);
-                value.Add(ParameterNames.PrintQueue, printQueue);
-                printDialogs.ShowDialog(DialogNames.HomePagePrinterPaperSettingsDialog, value, e =>
-                {
-                    if (e.Result == ButtonResult.OK)
-                    {
-                        PrintSettingsInfo.PageMediaSize = e.Parameters.GetValue<PageMediaSize>("PageMediaSize");
-                        PrintSettingsInfo.Margin.Clear();
-                        PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginLeft"));
-                        PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginTop"));
-                        PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginRight"));
-                        PrintSettingsInfo.Margin.Add(e.Parameters.GetValue<int>("MarginBottom"));
-                        this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
-                    }
-                });
+                    PrintSettingsInfo.IsPaperSizeChanged= false;
             }
-
         }
 
         public void ChangePrintMod(object e)
@@ -716,7 +693,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             if (printModInfoWithUnicode.printModInfo.EnumPrintMod == currentHomePagePrinterMod)
             {
                 PrintSettingsInfo.PrintModInfo = printModInfoWithUnicode.printModInfo;
-                this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
+               this.printEvent.GetEvent<SendPrintSettingsInfoEvent>().Publish(new PrintSettingsInfoWithUnicode { printSettingsInfo = this.PrintSettingsInfo, Unicode = this.Unicode });
             }
         }
 
@@ -741,7 +718,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             param.Add(ParameterNames.PDFViewer, PDFViewer);
             param.Add(ParameterNames.PrintSettingsInfo, PrintSettingsInfo);
             param.Add("Unicode", Unicode);
-            printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
+           printRegion.RequestNavigate(HomePagePrinterDocumentRegionName, HomePagePrinterDocumentName, param);
             PageSetupDialog pageSetupDialog = new PageSetupDialog();
             PrintSettingsInfo.PrintDocument.PrinterSettings.PrinterName = PrinterName;
             pageSetupDialog.Document = PrintSettingsInfo.PrintDocument;

+ 12 - 5
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContentViewModel.cs

@@ -104,6 +104,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             public Rectangle DocumentBounds = new Rectangle();
             public bool DocumentLandscape = false;
             public bool DocumentColor = false;
+            public bool IsSettingsChanged = true;
         }
 
         public DocumentSettingsInfo documentSettingsInfo = new DocumentSettingsInfo();
@@ -1671,10 +1672,17 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         {
             if (PDFViewer != null && printSettingsInfoWIthUnicode.printSettingsInfo != null)
             {
-                documentSettingsInfo.DocumentWidth = PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width;
-                documentSettingsInfo.DocumentHeight = PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height;
-                documentSettingsInfo.margins = PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins;
-                documentSettingsInfo.DocumentBounds = PrintSettingsInfo.PrintDocument.DefaultPageSettings.Bounds;
+                if (PrintSettingsInfo.IsPaperSizeChanged)
+                {
+                    documentSettingsInfo.IsSettingsChanged = true;
+                }
+                if (!documentSettingsInfo.IsSettingsChanged)
+                {
+                    documentSettingsInfo.DocumentWidth = PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width;
+                    documentSettingsInfo.DocumentHeight = PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height;
+                    documentSettingsInfo.margins = PrintSettingsInfo.PrintDocument.DefaultPageSettings.Margins;
+                    documentSettingsInfo.DocumentBounds = PrintSettingsInfo.PrintDocument.DefaultPageSettings.Bounds;
+                }
                 CaculatePrintedPageCount();
                 SetPaperCollection();
                 if (PrintedPageCount != PreviousPrintedPageCount)
@@ -1683,7 +1691,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     PreviousPrintedPageCount = PrintedPageCount;
                 }
                 PaintPageByCurrentPreviewIndex(TargetPaperIndex);
-
             }
         }
 

+ 1 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModPosterContentViewModel.cs

@@ -344,7 +344,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            DefaultLabel = "(Column, Row) -Page -xxx.pdf - yyyy/mm/dd hh-mm-ss";
+            DefaultLabel = "(Column, Row) -Page -xxx.pdf - yyyy/MM/dd hh-mm-ss";
             navigationContext.Parameters.TryGetValue<string>("Unicode", out Unicode);
             SendPosterInfo();
         }

+ 1 - 1
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModSizeContentViewModel.cs

@@ -110,7 +110,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         {
             if (SizeInfo != null)
             {
-                this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode});
+               this.eventAggregator.GetEvent<SendPrintSettingsModInfoEvent>().Publish(new PrintModInfoWithUnicode { printModInfo = SizeInfo, Unicode = this.Unicode});
             }
         }
 

+ 25 - 6
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -1165,13 +1165,32 @@ namespace PDF_Office.ViewModels
                         permissionsPassword = SecurityInfo.PermissionsPassword;
                         cPDFPermissionsInfo = SecurityInfo.CPDFPermissionsInfo;
                     }
-                    PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                    AlertsMessage alertsMessage = new AlertsMessage();
-                    alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
-                    if (alertsMessage.result == ContentResult.Ok)
-                        return saveAsFile();
+                    if (false)
+                    {
+                        //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                        AlertsMessage alertsMessage = new AlertsMessage();
+                        alertsMessage.ShowDialog("", "文件安全设置已修改,需要另存为", "Cancel", "OK");
+                        if (alertsMessage.result == ContentResult.Ok)
+                            return saveAsFile();
+                        else
+                            return false;
+                    }
                     else
-                        return false;
+                    {
+                        string currentPath = PDFViewer.Document.FilePath;
+                        string tempPath = PDFViewer.Document.FilePath+".temp.pdf";
+                        PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                        PDFViewer.Document.WriteToFilePath(tempPath);
+                        PDFViewer.InitDocument(tempPath);
+                        //PDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                        //PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                        PDFViewer.Document.WriteToFilePath(currentPath);
+                        System.IO.File.Delete(tempPath);
+                        PDFViewer.CloseDocument();
+                        PDFViewer.InitDocument(currentPath);
+                        PDFViewer.Document.UnlockWithPassword(permissionsPassword);
+                    }
+             
                 }
 
                 bool result = PDFViewer.Document.WriteToLoadedPath();