diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index ae107039..b1e2b9ee 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -518,29 +518,32 @@ namespace VEPROMS.CSLA.Library //doc.DTS = _MyFile.LastWriteTimeUtc; doc.DTS = DateTime.Now.ToUniversalTime(); doc = doc.Save(); - List roids = new List(); - string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument, roids, myItemInfo,statusChange); - FileInfo pdfFile = new FileInfo(pdfTmp); - fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - buf = new byte[pdfFile.Length]; - fs.Read(buf, 0, buf.Length); - fs.Close(); - pdfFile.Delete(); - Pdf.DeleteAll(doc.DocID); // clear the PDF table for DocID first - DocStyle myDocStyle = myItemInfo.ActiveSection.MyDocStyle; - SectionConfig sc = myItemInfo.ActiveSection.MyConfig as SectionConfig; - if (sc != null && sc.Section_WordMargin == "Y") + if (myItemInfo != null) // B2016-131 if myItemInfo is null, the lib doc is not referenced from any procedure. Just save changes, but don't generate a PDF { - using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, 0, 0, 0, 0, (double)myItemInfo.MSWordPageCount, buf)) { ;} + List roids = new List(); + string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument, roids, myItemInfo, statusChange); + FileInfo pdfFile = new FileInfo(pdfTmp); + fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + buf = new byte[pdfFile.Length]; + fs.Read(buf, 0, buf.Length); + fs.Close(); + pdfFile.Delete(); + Pdf.DeleteAll(doc.DocID); // clear the PDF table for DocID first + DocStyle myDocStyle = myItemInfo.ActiveSection.MyDocStyle; + SectionConfig sc = myItemInfo.ActiveSection.MyConfig as SectionConfig; + if (sc != null && sc.Section_WordMargin == "Y") + { + using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, 0, 0, 0, 0, (double)myItemInfo.MSWordPageCount, buf)) { ;} + } + else + { + using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopMargin, (int)myDocStyle.Layout.PageLength, + (int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth, (double)myItemInfo.MSWordPageCount, buf)) { ;} + } + doc.UpdateDRoUsages(roids); + doc.Save(); + if (savLen != _MyFile.Length) _MyLog.ErrorFormat("DSO FRAMER: File size changed during Save for Word Document, beginSize = {0}, endSize = {1}", savLen, _MyFile.Length); } - else - { - using (Pdf myPdf = Pdf.MakePdf(doc, MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopMargin, (int)myDocStyle.Layout.PageLength, - (int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth, (double)myItemInfo.MSWordPageCount, buf)) { ;} - } - doc.UpdateDRoUsages(roids); - doc.Save(); - if (savLen != _MyFile.Length) _MyLog.ErrorFormat("DSO FRAMER: File size changed during Save for Word Document, beginSize = {0}, endSize = {1}", savLen, _MyFile.Length); } #endregion #region Constructors