B2019-041: The merging of pdfs crashes when there is a bad (corrupt) procedure pdf to merge

This commit is contained in:
Kathy Ruffing 2019-03-22 13:15:43 +00:00
parent 3aa1834cca
commit 17ae2c3df7

View File

@ -42,6 +42,7 @@ namespace Volian.Print.Library
// selects the 'Merge' button off of the print dialog when doing a Print All. (C2019-012)
public class MergedPdf
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private List<MergedPdfProc> _mergedPdfs = null; // This list has all procedure pdfs that will be included in the merged file.
public List<MergedPdfProc> MergedPdfs
{
@ -116,7 +117,10 @@ namespace Volian.Print.Library
FlexibleMessageBox.Show("Error in finding pdf files to merge. Cannot print with date/time as part of pdf name. Or check that individual pdfs were generated.", "Error on CreatePdf", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
PdfReader reader = new PdfReader(_folder + @"\" + mpp.PdfFileName);
PdfReader reader = null;
try // B2019-041: added a try/catch for when a corrupt pdf was created for a procedure, just skip & add message to error log.
{
reader = new PdfReader(_folder + @"\" + mpp.PdfFileName);
int numPages = reader.NumberOfPages;
int currentPageNumber = 0;
PdfOutline outline = null;
@ -136,12 +140,18 @@ namespace Volian.Print.Library
// if on the first page, add the pdfname & title as part of outline. If on remaining pages, just put out page number.
// Later this may need expanded to put sections/steps/etc.
if (currentPageNumber == 1)
outline = new PdfOutline(canvas.RootOutline, dest, mpp.PdfFileName.Replace(".pdf", "")+" - "+mpp.Title, false);
outline = new PdfOutline(canvas.RootOutline, dest, mpp.PdfFileName.Replace(".pdf", "") + " - " + mpp.Title, false);
else
new PdfOutline(outline, dest, "Page " + currentPageNumber.ToString(), false);
canvas.AddTemplate(page, 0, 0); // adds the page to the combined pdf
} while (currentPageNumber < numPages);
}
catch (Exception ex)
{
string tmp = string.Format("Error merging pdf {0}", mpp.PdfFileName);
_MyLog.Error(tmp, ex);
}
}
doc.Close();
return true;
}