Added logic so that MSWord 2010 and beyond uses the internal export to PDF function.
Added logic to handle errors when a document is closed. The code will attempt to do a close 10 times. If it fails ten times, it will document the exception and continue. If an exception occurs when an MSWord section is being saved, a message will be displayed that will document the error.
This commit is contained in:
parent
54db0e1e81
commit
3e1d22674c
@ -110,7 +110,9 @@ namespace LBWordLibrary
|
|||||||
public string CreatePDF(string pdfFileName)
|
public string CreatePDF(string pdfFileName)
|
||||||
{
|
{
|
||||||
pdfFileName = AvailableFileName(pdfFileName);
|
pdfFileName = AvailableFileName(pdfFileName);
|
||||||
if (Convert.ToSingle(Version) >= 12.0F && WordPDFExporterInstalled)
|
if (Convert.ToSingle(Version) > 12.0F)
|
||||||
|
return CreatePDF2007(pdfFileName);
|
||||||
|
if (Convert.ToSingle(Version) == 12.0F && WordPDFExporterInstalled)
|
||||||
return CreatePDF2007(pdfFileName);
|
return CreatePDF2007(pdfFileName);
|
||||||
else if (VolianPDFInstalled)
|
else if (VolianPDFInstalled)
|
||||||
return CreatePDF2003BG(pdfFileName);
|
return CreatePDF2003BG(pdfFileName);
|
||||||
@ -189,8 +191,9 @@ namespace LBWordLibrary
|
|||||||
public string CreatePDF2007(string pdfFileName)
|
public string CreatePDF2007(string pdfFileName)
|
||||||
{
|
{
|
||||||
pdfFileName = AvailableFileName(pdfFileName);
|
pdfFileName = AvailableFileName(pdfFileName);
|
||||||
if (!WordPDFExporterInstalled)
|
// Removed to support MSWord 2010 and beyond.
|
||||||
throw new Exception("MS Word PDF Exporter is not installed");
|
//if (!WordPDFExporterInstalled)
|
||||||
|
// throw new Exception("MS Word PDF Exporter is not installed");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ActiveDocument.ExportAsFixedFormat(pdfFileName, LBWdExportFormat.wdExportFormatPDF);
|
ActiveDocument.ExportAsFixedFormat(pdfFileName, LBWdExportFormat.wdExportFormatPDF);
|
||||||
|
@ -790,7 +790,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
}
|
}
|
||||||
LBSelection sel = MyApp.Selection;
|
LBSelection sel = MyApp.Selection;
|
||||||
sel.WholeStory();
|
sel.WholeStory();
|
||||||
if(statusChange != null) statusChange(VolianStatusType.Initialize, sel.End, "Refreshing ROs");
|
if (statusChange != null) statusChange(VolianStatusType.Initialize, sel.End, "Refreshing ROs");
|
||||||
sel = hasRos ? FindRO() : null;
|
sel = hasRos ? FindRO() : null;
|
||||||
int roCount = 0;
|
int roCount = 0;
|
||||||
// force Print of MS Word Attachment to Final without revisions and comments
|
// force Print of MS Word Attachment to Final without revisions and comments
|
||||||
@ -920,7 +920,7 @@ namespace VEPROMS.CSLA.Library
|
|||||||
sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor);
|
sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor);
|
||||||
sect.MSWordPageCount = myDoc.Length;
|
sect.MSWordPageCount = myDoc.Length;
|
||||||
fileName = CreatePDF(fileName, openPdf);
|
fileName = CreatePDF(fileName, openPdf);
|
||||||
MyApp.ActiveDocument.Close(false);
|
CloseDocument();
|
||||||
if (CloseWordWhenDone)
|
if (CloseWordWhenDone)
|
||||||
{
|
{
|
||||||
CloseAppAfterWait();
|
CloseAppAfterWait();
|
||||||
@ -929,6 +929,31 @@ namespace VEPROMS.CSLA.Library
|
|||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static void CloseDocument()
|
||||||
|
{
|
||||||
|
int attempts = 0;
|
||||||
|
while (++attempts < 11)
|
||||||
|
{
|
||||||
|
if (TryToClose(attempts)) return;
|
||||||
|
WaitMS(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static bool TryToClose(int attempts)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw(new Exception("Oops!");
|
||||||
|
MyApp.ActiveDocument.Close(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_MyLog.WarnFormat("{0} - {1}, Attempt {2}", ex.GetType().Name, ex.Message, attempts);
|
||||||
|
if (attempts >= 10)
|
||||||
|
_MyLog.Error("Failed to close 10 times.", ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
private static string FindEmbeddedText(string p, ref string resXyPlot)
|
private static string FindEmbeddedText(string p, ref string resXyPlot)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder(); // contains embedded text
|
StringBuilder sb = new StringBuilder(); // contains embedded text
|
||||||
|
@ -503,6 +503,7 @@ namespace Volian.Controls.Library
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("SaveDSO", ex);
|
if (_MyLog.IsErrorEnabled) _MyLog.Error("SaveDSO", ex);
|
||||||
|
MessageBox.Show(ex.Message, "Error Saving Document", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user