Browse Source

打印 - bug处理

liuaoran 2 years ago
parent
commit
684399aee3

+ 7 - 1
PDF Office/EventAggregators/SendPrintInfoEvent.cs

@@ -43,10 +43,12 @@ namespace PDF_Office.EventAggregators
         public string Unicode;
     }
 
-    public class GetCurrentViewEvent
+    public class FinishedFrontSide
     {
+        public string Unicode;
     }
 
+
     public class SendPrintSettingsInfoEvent : PubSubEvent<PrintSettingsInfoWithUnicode>
     {
     }
@@ -66,4 +68,8 @@ namespace PDF_Office.EventAggregators
     public class SendDuplexPrintModEvent : PubSubEvent<EnumDuplexPrintModWithUnicode>
     {
     }
+
+    public class SendFinishedFrontSideEvent : PubSubEvent<FinishedFrontSide>
+    {
+    }
 }

+ 2 - 1
PDF Office/StyleAndTemplateList.txt

@@ -81,8 +81,9 @@
 SecurityHelper.VerifyPasswordByPasswordKind需要传入的参数:PDFViewer.Document,需要验证的密码类型(开启密码/权限密码),当前ViewModel的IDialogService对象
 ecurityHelper.VerifyPasswordForSelectedPermissions需要传入的参数:PDFViewer.Document, 需要验证的权限子集(形如 枚举1|枚举2|枚举3),当前ViewModel的IDialogService对象。
 返回值result对象包含两个成员:IsDiscryptied标志是否可以解锁/提权,Password对象标志当前正确的密码,当密码为空时表示当前无需输入。
+该框架下的一些状态说明,
 IsDiscryptied == false  解锁/提权失败,拒绝下一步
-IsDiscryptied == true password == null; 当前无需解锁/提权,不会显示输入密码弹窗,直接进行下一步
+IsDiscryptied == true password == null; 当前无需解锁/提权,不会唤起输入密码弹窗,直接进行下一步
 IsDiscryptied == true  password != null; 提权/解锁成功,共用当前PDFView的同权限级别操作全部开放,不再需要校验
 * 下一步 *指解锁后的具体业务操作,例如唤起需求复制权限的弹窗等
 

+ 48 - 19
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialogViewModel.cs

@@ -79,6 +79,19 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             get => _printOrientationIndex;
             set => SetProperty(ref _printOrientationIndex, value);
         }
+        private int _maxPageRange = 0;
+        public int MaxPageRange
+        {
+            get => _maxPageRange;
+            set => SetProperty(ref _maxPageRange, value);
+        }
+
+        private int _pageRangeSelectIndex = 0;
+        public int PageRangeSelectIndex
+        {
+            get => _pageRangeSelectIndex;
+            set => SetProperty(ref _pageRangeSelectIndex, value);
+        }
         #region 相关region
         private string _homePagePrinterDocumentRegionName;
         public string HomePagePrinterDocumentRegionName
@@ -183,6 +196,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             set => _isBothSides = value;
         }
 
+        public bool FinishedFrontSideFlag = false;
         public int printCurrentPageIndex;
         public bool isCurrentPage;
 
@@ -287,6 +301,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
             printEvent.GetEvent<SendPrintSettingsModInfoEvent>().Subscribe(RecvPrintSettingsModInfo, e => e.Unicode == Unicode);
             printEvent.GetEvent<SendDuplexPrintModEvent>().Subscribe(RecvDuplexPrintMod, e => e.Unicode == Unicode);
+            printEvent.GetEvent<SendFinishedFrontSideEvent>().Subscribe(RecvFinishedFrontSide, e => e.Unicode == Unicode);
 
             PrintSettingsInfo.PrintDocument.DefaultPageSettings = pageSetupDialog.PageSettings;
             if (!PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape)
@@ -316,7 +331,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         {
             printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
             List<PageMediaSize> PageMediaSizeList = new List<PageMediaSize>();
-
         }
 
         private void InitPrinterNameList()
@@ -423,6 +437,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
 
         public void ChangePrintMod(object e)
         {
+
             var rdo = e as System.Windows.Controls.RadioButton;
             CurrentHomePagePrinterModName = GetPrintModNameFromRadioButton[rdo.Name];
             if (CurrentHomePagePrinterModName == "HomePagePrinterModMultipleContent" || CurrentHomePagePrinterModName == "HomePagePrinterModBookletContent")
@@ -531,6 +546,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                             {
                                 PrintSettingsInfo.PageRangeList.Add(temp);
                             }
+                            PageRangeSelectIndex = 0;
                         }
                         else
                         {
@@ -573,6 +589,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                             {
                                 PrintSettingsInfo.PageRangeList.Add(temp);
                             }
+                            PageRangeSelectIndex = 0;
                         }
                         else
                         {
@@ -590,10 +607,18 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             {
                 if (!isCurrentPage)
                 {
+                    for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
+                    {
+                        PrintSettingsInfo.PageRangeList.Add(temp);
+                    }
                     PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithoutCurrentPage.StatusCustomizedRange;
                 }
                 else
                 {
+                    for (int temp = 0; temp < PDFViewer.Document.PageCount; temp++)
+                    {
+                        PrintSettingsInfo.PageRangeList.Add(temp);
+                    }
                     PrintSettingsInfo.EnumPageRange = (int)EnumPageRangeWithCurrentPage.StatusCustomizedRange;
 
                 }
@@ -696,6 +721,11 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         {
             PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod = enumDuplexPrintModWithUnicode.enumDuplexPrintMod;
         }
+
+        public void RecvFinishedFrontSide(FinishedFrontSide finishedFrontSide)
+        {
+            FinishedFrontSideFlag = true;
+        }
         #endregion
         public void Cancel()
         {
@@ -784,7 +814,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         /// </summary>
         public void ConfirmPrint()
         {
-
             printQueue = localDefaultPrintServer.GetPrintQueue(PrinterName);
             LoadPrinterSettings();
 
@@ -804,10 +833,13 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
             if (PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod == EnumDuplexPrintMod.StatusNone && !IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
             {
                 this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
+
             }
             else if (IsBookletSinglePage(PrintSettingsInfo.PrintModInfo))
             {
                 this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
+                RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
+
             }
             ///双面打印的情况
             else if ((int)PrintSettingsInfo.PrintModInfo.EnumDuplexPrintMod > 0 || IsBookletBothPage(PrintSettingsInfo.PrintModInfo))
@@ -816,7 +848,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 if (list.Count > 0)
                 {
                     this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
-                    RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
                 }
                 ///手动翻面
                 ///手动翻面需要注意只有一页时和单面打印一致
@@ -826,7 +857,6 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     if ((PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusSize && PrintSettingsInfo.PageRangeList.Count == 1) || (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusBooklet && PrintSettingsInfo.PageRangeList.Count == 1))
                     {
                         this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
-                        RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
                     }
                     else if (PrintSettingsInfo.PrintModInfo.EnumPrintMod == EnumPrintMod.StatusMultiple)
                     {
@@ -834,40 +864,32 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                         if (PrintSettingsInfo.PageRangeList.Count / (multipleInfo.HorizontalPageNumber * multipleInfo.VerticalPageNumber) == 0)
                         {
                             this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusNone, Unicode = this.Unicode });
-                            RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
                         }
                         else
                         {
-                            ///z
                             this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
-                            if (MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
+                            if (FinishedFrontSideFlag && MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                             {
+
                                 this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
-                                RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
-                            }
-                            else
-                            {
-                                RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
                             }
                         }
                     }
                     else
                     {
                         this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusFrontSide, Unicode = this.Unicode });
-                        if (MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
+                        if (FinishedFrontSideFlag && MessageBoxEx.Show("Printing on the front side of the paper is complete. Please reverse the paper, click 'OK' to print the reverse side", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                         {
                             this.printEvent.GetEvent<SendPrintQueueEvent>().Publish(new PrintQueueWithUnicode { printQueue = this.printQueue, EnumBothSidesStage = EnumBothSidesStage.StatusBackSide, Unicode = this.Unicode });
-                            RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
-                        }
-                        else
-                        {
-                            RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
                         }
                     }
                 }
             }
+            RequestClose.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.OK));
         }
 
+
+
         public event Action<IDialogResult> RequestClose;
 
         public bool CanCloseDialog()
@@ -898,7 +920,14 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     isCurrentPage = false;
                 }
                 System.Windows.Size pageSize = PDFViewer.Document.GetPageSize(0);
-
+                if ((pageSize.Height / pageSize.Width > 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width < 1.0)
+                    || (pageSize.Height / pageSize.Width < 1.0 && (double)PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Height / PrintSettingsInfo.PrintDocument.DefaultPageSettings.PaperSize.Width > 1.0))
+                {
+                    PrintSettingsInfo.PrintDocument.DefaultPageSettings.Landscape = true;
+                    PrintOrientationIndex = 0;
+                    PrintSettingsInfo.EnumPrintOrientation = EnumPrintOrientation.StatusLandscape;
+                }
+                MaxPageRange = PDFViewer.Document.PageCount;
                 NavigationParameters param = new NavigationParameters();
                 NavigateDocumentRegion();
                 NavigateModRegion();

+ 138 - 126
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDocumentContentViewModel.cs

@@ -337,6 +337,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 {
                     MessageBoxEx.Show("另一个进程正在占用该打印机或发生未知错误");
                 }
+                finally
+                {
+                    printDocument.Dispose();
+                }
             }
         }
 
@@ -478,6 +482,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     else
                     {
                         e.HasMorePages = false;
+                        if (PrintIndex%2 == 0)
+                        {
+                            this.printDocumentEvent.GetEvent<SendFinishedFrontSideEvent>().Publish(new FinishedFrontSide { Unicode = this.Unicode });
+                        }
                     }
                 }
                 //单面打印
@@ -576,10 +584,11 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 CPDFPage cPDFPage = PDFViewer.Document.PageAtIndex(PrintSettingsInfo.PageRangeList[posterPrintPaperIndex]);
                 if (cPDFPage != null)
                 {
+
+
                     ///仅当每一页第一张纸打印时,进行一次渲染,,更换打印底图
                     if (HorizonPaperIndex == 0 && VerticalPaperIndex == 0)
                     {
-                        {
                             PosterCurrentBitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)(cPDFPage.PageSize.Width * PDFToMediaDpiRatio * (posterInfo.TileRatio / 100.0) * widthDpiRatio), (int)(cPDFPage.PageSize.Height * PDFToMediaDpiRatio * (posterInfo.TileRatio / 100.0) * heightDpiRatio), PrintSettingsInfo.PageRangeList[posterPrintPaperIndex], PrintSettingsInfo.IsPrintWithAnnot, PrintSettingsInfo.IsPrintWithForm);
                             if (PrintSettingsInfo.IsGrayscale)
                             {
@@ -604,147 +613,142 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                             startPoint.X = (int)((PreviewWidth - PosterCurrentBitmap.Width) / 2);
                             startPoint.Y = (int)((PreviewHeight - PosterCurrentBitmap.Height) / 2);
                             DisplayBitmap = CombineBitmap(DisplayBitmap, PosterCurrentBitmap, startPoint);
-                        }
                     }
-
-
-                    /////当前页未打印完
-                    if (HorizonPaperIndex * VerticalPaperIndex < WholeCountSinglePage - 1)
+                    if (WholeCountSinglePage > 1)
                     {
-                        ///取有效尺寸和重叠,边沿合并
-                        ///有效尺寸+重叠边
-                        Rectangle rectangle = new Rectangle((int)(HorizonPaperIndex * effectiveWidth), (int)(VerticalPaperIndex * effectiveHeight), (int)effectiveWidth, (int)effectiveHeight);
-                        ///左重叠
-                        if (HorizonPaperIndex != 0)
-                        {
-                            rectangle.Location = new System.Drawing.Point((int)(rectangle.Location.X - posterInfo.OverLap * mmToDpiRatio * widthDpiRatio), rectangle.Location.Y);
-                        }
-
-                        ///上重叠
-                        if (VerticalPaperIndex != 0)
-                        {
-                            rectangle.Size = new System.Drawing.Size(rectangle.Size.Width, (int)(rectangle.Size.Height + posterInfo.OverLap * mmToDpiRatio * heightDpiRatio));
-                        }
-
-                        ///右重叠
-                        if (HorizonPaperIndex != HorizonPaperCount)
-                        {
-                            rectangle.Size = new System.Drawing.Size((int)(rectangle.Size.Width + posterInfo.OverLap * mmToDpiRatio * widthDpiRatio), rectangle.Size.Height);
-                        }
-
-                        ///下重叠
-                        if (VerticalPaperIndex != VerticalPaperCount)
-                        {
-                            rectangle.Location = new System.Drawing.Point(rectangle.Location.X, (int)(rectangle.Location.Y - posterInfo.OverLap * mmToDpiRatio * heightDpiRatio));
-                        }
-
-
-                        ///当存在边沿时
-                        int margin = 0;
-
-                        ///Label和CutMarks
-                        ///
-                        if (posterInfo.HasLabel || posterInfo.HasCutMarks)
-                        {
-                            margin = 20;
-                        }
-
-                        if (posterInfo.HasLabel)
+                        /////当前页未打印完
+                        if (HorizonPaperIndex * VerticalPaperIndex < WholeCountSinglePage - 1)
                         {
-                            string sign = null;
-                            if (posterInfo.Label == null || posterInfo.Label == "")
+                            ///取有效尺寸和重叠,边沿合并
+                            ///有效尺寸+重叠边
+                            Rectangle rectangle = new Rectangle((int)(HorizonPaperIndex * effectiveWidth), (int)(VerticalPaperIndex * effectiveHeight), (int)effectiveWidth, (int)effectiveHeight);
+                            ///左重叠
+                            if (HorizonPaperIndex != 0)
                             {
-                                sign = string.Format("({0},{1})  -{2} -{3}.pdf {4} {5}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PrintIndex + 1, PDFViewer.Document.FileName, System.DateTime.Today.ToString("yyyy/MM/dd"), System.DateTime.Now.ToString("HH:mm:ss"));
+                                rectangle.Location = new System.Drawing.Point((int)(rectangle.Location.X - posterInfo.OverLap * mmToDpiRatio * widthDpiRatio), rectangle.Location.Y);
                             }
-                            else
+
+                            ///上重叠
+                            if (VerticalPaperIndex != 0)
                             {
-                                sign = posterInfo.Label;
+                                rectangle.Size = new System.Drawing.Size(rectangle.Size.Width, (int)(rectangle.Size.Height + posterInfo.OverLap * mmToDpiRatio * heightDpiRatio));
                             }
-                            e.Graphics.DrawString(sign, new Font("Helvetica", 10.0f), System.Drawing.Brushes.Black, margin + 5, 0);
-                        }
 
-                        if (posterInfo.HasCutMarks)
-                        {
-                            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 2);
-                            //除了四角之外都要添加裁切标记
+                            ///右重叠
+                            if (HorizonPaperIndex != HorizonPaperCount)
+                            {
+                                rectangle.Size = new System.Drawing.Size((int)(rectangle.Size.Width + posterInfo.OverLap * mmToDpiRatio * widthDpiRatio), rectangle.Size.Height);
+                            }
 
-                            if (!(HorizonPaperIndex == 0 && VerticalPaperIndex == 0))
+                            ///下重叠
+                            if (VerticalPaperIndex != VerticalPaperCount)
                             {
-                                e.Graphics.DrawRectangle(pen, new Rectangle(-margin, -margin, 2 * margin, 2 * margin));
+                                rectangle.Location = new System.Drawing.Point(rectangle.Location.X, (int)(rectangle.Location.Y - posterInfo.OverLap * mmToDpiRatio * heightDpiRatio));
                             }
-                            if (!(HorizonPaperIndex == HorizonPaperCount - 1 && VerticalPaperIndex == 0))
+
+
+                            ///当存在边沿时
+                            int margin = 0;
+
+                            ///Label和CutMarks
+                            ///
+                            if (posterInfo.HasLabel || posterInfo.HasCutMarks)
                             {
-                                e.Graphics.DrawRectangle(pen, new Rectangle(pageBound.Width - margin, -margin, margin * 2, margin * 2));
+                                margin = 20;
                             }
-                            if (!(HorizonPaperIndex == 0 && VerticalPaperIndex == VerticalPaperCount - 1))
+
+                            if (posterInfo.HasLabel)
                             {
-                                e.Graphics.DrawRectangle(pen, new Rectangle(-margin, pageBound.Height - margin, margin * 2, margin * 2));
+                                string sign = null;
+                                if (posterInfo.Label == null || posterInfo.Label == "")
+                                {
+                                    sign = string.Format("({0},{1})  -{2} -{3}.pdf {4} {5}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PrintIndex + 1, PDFViewer.Document.FileName, System.DateTime.Today.ToString("yyyy/MM/dd"), System.DateTime.Now.ToString("HH:mm:ss"));
+                                }
+                                else
+                                {
+                                    sign = posterInfo.Label;
+                                }
+                                e.Graphics.DrawString(sign, new Font("Helvetica", 10.0f), System.Drawing.Brushes.Black, margin + 5, 0);
                             }
-                            if (!(HorizonPaperIndex == HorizonPaperCount - 1 && VerticalPaperIndex == VerticalPaperCount - 1))
+
+                            if (posterInfo.HasCutMarks)
                             {
-                                e.Graphics.DrawRectangle(pen, new Rectangle(pageBound.Width - margin, (int)pageBound.Height - margin, margin * 2, margin * 2));
+                                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 2);
+                                //除了四角之外都要添加裁切标记
+
+                                if (!(HorizonPaperIndex == 0 && VerticalPaperIndex == 0))
+                                {
+                                    e.Graphics.DrawRectangle(pen, new Rectangle(-margin, -margin, 2 * margin, 2 * margin));
+                                }
+                                if (!(HorizonPaperIndex == HorizonPaperCount - 1 && VerticalPaperIndex == 0))
+                                {
+                                    e.Graphics.DrawRectangle(pen, new Rectangle(pageBound.Width - margin, -margin, margin * 2, margin * 2));
+                                }
+                                if (!(HorizonPaperIndex == 0 && VerticalPaperIndex == VerticalPaperCount - 1))
+                                {
+                                    e.Graphics.DrawRectangle(pen, new Rectangle(-margin, pageBound.Height - margin, margin * 2, margin * 2));
+                                }
+                                if (!(HorizonPaperIndex == HorizonPaperCount - 1 && VerticalPaperIndex == VerticalPaperCount - 1))
+                                {
+                                    e.Graphics.DrawRectangle(pen, new Rectangle(pageBound.Width - margin, (int)pageBound.Height - margin, margin * 2, margin * 2));
+                                }
+                                pen.Dispose();
                             }
-                            pen.Dispose();
+                            Bitmap currentPrintBitmap = Crop(DisplayBitmap, rectangle);
+                            e.Graphics.DrawImage(currentPrintBitmap, new Rectangle(margin, margin, pageBound.Width - 2 * margin, pageBound.Height - 2 * margin), new Rectangle(0, 0, currentPrintBitmap.Width, currentPrintBitmap.Height), GraphicsUnit.Pixel);
+                            currentPrintBitmap.Dispose();
                         }
-                        Bitmap currentPrintBitmap = Crop(DisplayBitmap, rectangle);
-                        e.Graphics.DrawImage(currentPrintBitmap, new Rectangle(margin, margin, pageBound.Width - 2 * margin, pageBound.Height - 2 * margin), new Rectangle(0, 0, currentPrintBitmap.Width, currentPrintBitmap.Height), GraphicsUnit.Pixel);
-                        currentPrintBitmap.Dispose();
-                    }
-                    ///三种进位:当前列,当前行,当前页
-                    if (HorizonPaperIndex < HorizonPaperCount - 1)
-                    {
-                        HorizonPaperIndex++;
-                        e.HasMorePages = true;
-                    }
-                    else if (VerticalPaperIndex < VerticalPaperCount - 1)
-                    {
-                        HorizonPaperIndex = 0;
-                        VerticalPaperIndex++;
-                        e.HasMorePages = true;
-                    }
-                    else if (posterPrintPaperIndex < PrintedPageCount - 1)
-                    {
-                        ///当前总文件未打印完
-                        posterPrintPaperIndex++;
-                        PosterCurrentBitmap.Dispose();
-                        DisplayBitmap.Dispose();
-                        GC.Collect();
-                        GC.WaitForPendingFinalizers();
-                        HorizonPaperIndex = 0;
-                        VerticalPaperIndex = 0;
-                        e.HasMorePages = true;
-                    }
+                        ///三种进位:当前列,当前行,当前页
+                        if (HorizonPaperIndex < HorizonPaperCount - 1)
+                        {
+                            HorizonPaperIndex++;
+                            e.HasMorePages = true;
+                        }
+                        else if (VerticalPaperIndex < VerticalPaperCount - 1)
+                        {
+                            HorizonPaperIndex = 0;
+                            VerticalPaperIndex++;
+                            e.HasMorePages = true;
+                        }
+                        else if (posterPrintPaperIndex < PrintedPageCount - 1)
+                        {
+                            ///当前总文件未打印完
+                            posterPrintPaperIndex++;
+                            PosterCurrentBitmap.Dispose();
+                            DisplayBitmap.Dispose();
+                            GC.Collect();
+                            GC.WaitForPendingFinalizers();
+                            HorizonPaperIndex = 0;
+                            VerticalPaperIndex = 0;
+                            e.HasMorePages = true;
+                        }
+                        else
+                        {
+                            HorizonPaperIndex = 0;
+                            VerticalPaperIndex = 0;
+                            e.HasMorePages = false;
+                        }
+                    }   //当一页只有一张打印纸的时候
                     else
                     {
-                        HorizonPaperIndex = 0;
-                        VerticalPaperIndex = 0;
-                        e.HasMorePages = false;
-                    }
-                }
+                        e.Graphics.DrawImage(DisplayBitmap, new Rectangle(0, 0, pageBound.Width, pageBound.Height), new Rectangle(0, 0, DisplayBitmap.Width, DisplayBitmap.Height), GraphicsUnit.Pixel);
 
-                //当一页只有一张打印纸的时候
-                else if (WholeCountSinglePage == 1)
-                {
-                    if (PrintSettingsInfo.IsGrayscale)
-                    {
-                        PosterCurrentBitmap = ToGray(PosterCurrentBitmap, 0);
-                    }
-                    e.Graphics.DrawImage(DisplayBitmap, e.PageBounds);
-                    if (posterPrintPaperIndex < PrintedPageCount - 1)
-                    {
-                        ///当前总文件未打印完
-                        posterPrintPaperIndex++;
-                        PosterCurrentBitmap.Dispose();
-                        DisplayBitmap.Dispose();
-                        GC.Collect();
-                        GC.WaitForPendingFinalizers();
-                        HorizonPaperIndex = 0;
-                        VerticalPaperIndex = 0;
-                        e.HasMorePages = true;
-                    }
-                    else
-                    {
-                        e.HasMorePages = false;
+                        if (posterPrintPaperIndex < PrintedPageCount - 1)
+                        {
+                            ///当前总文件未打印完
+                            posterPrintPaperIndex++;
+                            PosterCurrentBitmap.Dispose();
+                            DisplayBitmap.Dispose();
+                            GC.Collect();
+                            GC.WaitForPendingFinalizers();
+                            HorizonPaperIndex = 0;
+                            VerticalPaperIndex = 0;
+                            e.HasMorePages = true;
+                        }
+                        else
+                        {
+                            e.HasMorePages = false;
+                        }
                     }
                 }
             }
@@ -837,7 +841,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     if (posterInfo.Label == null || posterInfo.Label == "")
                     {
                         ///Fix 13366: (行、列)文件名 时间 日期)
-                        sign = string.Format("({0},{1}){2}.pdf {3} {4}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PDFViewer.Document.FileName, System.DateTime.Today.ToString("yyyy-MM-dd"), System.DateTime.Now.ToString("HH:mm:ss"));
+                        sign = string.Format("({0},{1})  -{2} -{3}.pdf {4} {5}", HorizonPaperIndex + 1, VerticalPaperIndex + 1, PrintIndex + 1, PDFViewer.Document.FileName, System.DateTime.Today.ToString("yyyy/MM/dd"), System.DateTime.Now.ToString("HH:mm:ss"));
                     }
                     else
                     {
@@ -1107,6 +1111,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                     else
                     {
                         e.HasMorePages = false;
+                        if (PrintIndex % 2 == 0)
+                        {
+                            this.printDocumentEvent.GetEvent<SendFinishedFrontSideEvent>().Publish(new FinishedFrontSide { Unicode = this.Unicode });
+                        }
                     }
                 }
                 //单面打印
@@ -1137,7 +1145,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 heightDpiRatio = (int)e.Graphics.DpiY / 100;
             }
             Bitmap printBitmap;
-            Rectangle realBound = new Rectangle(documentSettingsInfo.margins.Left, documentSettingsInfo.margins.Top,  e.PageBounds.Width - documentSettingsInfo.margins.Left - documentSettingsInfo.margins.Right,  e.PageBounds.Height - documentSettingsInfo.margins.Top - documentSettingsInfo.margins.Bottom);
+            Rectangle realBound = new Rectangle(documentSettingsInfo.margins.Left, documentSettingsInfo.margins.Top, e.PageBounds.Width - documentSettingsInfo.margins.Left - documentSettingsInfo.margins.Right, e.PageBounds.Height - documentSettingsInfo.margins.Top - documentSettingsInfo.margins.Bottom);
             double singlePageHeight;
             double singlePageWidth;
             if (PrintSettingsInfo.EnumPrintOrientation == EnumPrintOrientation.StatusPortrait)
@@ -1231,10 +1239,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                         rightPage = null;
                         rightPage = null;
                     }
-                    if(rightPage != null)
+                    if (rightPage != null)
                     {
                         startPoint.X = (int)singlePageWidth;
-                        rightBitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)rightPage.PageSize.Width*widthDpiRatio, (int)rightPage.PageSize.Height*heightDpiRatio, rightPageIndex, PrintSettingsInfo.IsPrintWithAnnot, PrintSettingsInfo.IsPrintWithForm);
+                        rightBitmap = ToolMethod.RenderPageBitmapNoWait(PDFViewer.Document, (int)rightPage.PageSize.Width * widthDpiRatio, (int)rightPage.PageSize.Height * heightDpiRatio, rightPageIndex, PrintSettingsInfo.IsPrintWithAnnot, PrintSettingsInfo.IsPrintWithForm);
                         if (bookletInfo.IsAutoRotate)
                         {
                             if ((rightPage.PageSize.Height / rightPage.PageSize.Width > 1 && (double)singlePageHeight / singlePageWidth < 1) ||
@@ -1353,7 +1361,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                             resizedWidth = (int)(singlePageWidth * 0.96);
                             resizedHeight = (int)(singlePageWidth / rightBitmap.Width * rightBitmap.Height * 0.96);
                         }
-                        startPoint.X+= (int)(singlePageWidth - resizedWidth) / 2;
+                        startPoint.X += (int)(singlePageWidth - resizedWidth) / 2;
                         startPoint.Y = (int)(singlePageHeight - resizedHeight) / 2;
                         if (PrintSettingsInfo.IsGrayscale)
                         {
@@ -1581,6 +1589,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
                 else
                 {
                     e.HasMorePages = false;
+                    if (PrintIndex % 2 == 0)
+                    {
+                        this.printDocumentEvent.GetEvent<SendFinishedFrontSideEvent>().Publish(new FinishedFrontSide { Unicode = this.Unicode });
+                    }
                 }
             }
             //单面打印或自动双面

+ 0 - 3
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterModBookletContentViewModel.cs

@@ -129,15 +129,12 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePagePrinter
         public HomePagePrinterModBookletContentViewModel(IEventAggregator eventAggregator)
         {
             this.eventAggregator = eventAggregator;
-
             SubsetList = new List<string>();
             InitSubsetList();
             BindingList = new List<string>();
             InitBindingList();
-
             BookletInfo = new BookletInfo();
             BookletInfo.EnumPrintMod = EnumPrintMod.StatusBooklet;
-
             SetSheetCommand = new DelegateCommand<object>(SetSheet);
             SetAutoRotateCommand = new DelegateCommand(SetAutoRotate);
         }

+ 1 - 0
PDF Office/ViewModels/Dialog/ToolsDialogs/SaftyDialogs/SetPasswordDialogViewModel.cs

@@ -252,6 +252,7 @@ namespace PDF_Office.ViewModels.Dialog.ToolsDialogs.SaftyDialogs
 
         public void SetOpenPassword(object e)
         {
+            MessageBoxEx.Show("");
             var chk = e as CheckBox;
             if (chk != null)
             {

+ 1 - 1
PDF Office/Views/Dialog/HomePageToolsDialogs/HomePagePrinter/HomePagePrinterDialog.xaml

@@ -62,7 +62,7 @@
                                 <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock Text="Page range:" FontFamily="Segoe UI" FontSize="14" Height="22" Width="80"></TextBlock>
-                                        <cus:WritableComboBox  x:Name="PageRangeComboBox" Loaded="PageRangeComboBox_Loaded" Width="132" Height="32" Margin="16,0,0,0">
+                                        <cus:WritableComboBox  x:Name="PageRangeComboBox" Loaded="PageRangeComboBox_Loaded" Width="132" Height="32" Margin="16,0,0,0" MaxPageRange="{Binding MaxPageRange, Mode=TwoWay}"  SelectedIndex="{Binding PageRangeSelectIndex,Mode=TwoWay}" >
                                             <i:Interaction.Triggers>
                                                 <i:EventTrigger EventName="SelectionChanged">
                                                     <i:InvokeCommandAction Command="{Binding SetPageRangeSelectionIndexCommand}" CommandParameter="{Binding ElementName=PageRangeComboBox}"></i:InvokeCommandAction>