B2017-218 - Handle invalid MS Word sections when printing

This commit is contained in:
Rich 2017-09-22 18:23:10 +00:00
parent 73593b8546
commit 7a97ee3b07

View File

@ -1014,11 +1014,20 @@ namespace Volian.Print.Library
float locEndOfWordDoc = 0;
float pdfSize = 0;
using (PdfInfo myPdf = PdfInfo.Get(mySection,false))
{
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++)