PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Exception printing large page range
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3039
Page 1 of 1

Author:  JmsRoland [ Tue Jan 27, 2015 2:00 am ]
Post subject:  Exception printing large page range

If the user prints a page range, whose last page is past the end of the document, an unhanded exception is thrown because the setting of MigraDocPrintDocument.pageCount in
Code:
 protected override void OnBeginPrint(PrintEventArgs e)

ignores the actual number of pages. The following is a proposed fix.

Code:
Index: MigraDocPrintDocument.cs
===================================================================
--- MigraDocPrintDocument.cs    (revision 200)
+++ MigraDocPrintDocument.cs    (working copy)
@@ -108,7 +108,10 @@

           case PrintRange.SomePages:
             this.pageNumber = PrinterSettings.FromPage;
-            this.pageCount = PrinterSettings.ToPage - PrinterSettings.FromPage + 1;
+            var toPage = this.PrinterSettings.ToPage > this.renderer.FormattedDocument.PageCount
+                ? this.renderer.FormattedDocument.PageCount
+                : this.PrinterSettings.ToPage;
+            this.pageCount = toPage - PrinterSettings.FromPage + 1;
             break;

           case PrintRange.Selection:

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/