From 7a97ee3b072a577dfdb1fe3b1a0ee3e8572c1173 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 22 Sep 2017 18:23:10 +0000 Subject: [PATCH] B2017-218 - Handle invalid MS Word sections when printing --- PROMS/Volian.Print.Library/PromsPrinter.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index bc638180..cd6fbf0e 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -1015,9 +1015,18 @@ namespace Volian.Print.Library float pdfSize = 0; using (PdfInfo myPdf = PdfInfo.Get(mySection,false)) { - sectPageCount = (int)(Math.Ceiling(myPdf.PageCount)); - locEndOfWordDoc = (float)(myPdf.PageCount - (sectPageCount - 1)) * 100; - pdfSize = (float)myPdf.PageCount; + if (myPdf == null) // B2017-218 Handle invalid word sections + { + cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 20); + cb.SetTextMatrix(cb.PdfDocument.Left+200,cb.PdfDocument.Bottom+cb.PdfDocument.Top / 2); + cb.ShowText("Word Section Invalid"); + } + else + { + sectPageCount = (int)(Math.Ceiling(myPdf.PageCount)); + locEndOfWordDoc = (float)(myPdf.PageCount - (sectPageCount - 1)) * 100; + pdfSize = (float)myPdf.PageCount; + } } string tocKey = string.Format("TOC{0}", mySection.ItemID); if (_MyHelper.MyTOCPageCounts.ContainsKey(tocKey)) @@ -2288,6 +2297,12 @@ namespace Volian.Print.Library { try { + FileInfo fi = new FileInfo(MyPdfFile); + if (fi.Length == 0) // B2017-218 Handle invalid word sections + { + MessageBox.Show(si.DisplayNumber + " " + si.DisplayText + " is not valid", "Invalid Word Section", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } MyReader = MyPdfFile != null ? new PdfReader(MyPdfFile) : null; string key = string.Empty; for (int i = 1; i <= MyReader.NumberOfPages; i++)