Make sure that SearchResults.pdf donot cause a failure.

Calculate Table Location
This commit is contained in:
Rich 2010-10-12 15:01:54 +00:00
parent e278a2ca37
commit c6d2003414
2 changed files with 85 additions and 20 deletions

View File

@ -195,23 +195,10 @@ namespace Volian.Print.Library
public void Build()
{
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 36, 36, 36, 36);
if (!CreateResultsPDF(document)) return;
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(_FileName, FileMode.Create));
// we add some meta information to the document
//document.AddAuthor("Gerald Henson");
//document.AddSubject("This is the result of a Test.");
document.SetMargins(36, 36, 36, 36);
// step 3: we open the document
document.Open();
BuildTable1(document);
//AddTable(document, 10, 90);
//AddTable(document, 10, 100);
//AddTable(document, 15, 75);
//AddTable(document, 20, 70);
//AddTable(document, 25, 65);
//AddTable(document, 30, 60);
}
catch (Exception ex)
{
@ -226,10 +213,72 @@ namespace Volian.Print.Library
}
finally
{
document.Close();
if (document.IsOpen())
{
document.Close();
System.Diagnostics.Process.Start(_FileName);
}
}
}
/// <summary>
/// Attempt to open a file for the PDF output.
/// If the file cannot be opened because it is in use, try adding a suffix
/// If the file cannot be opened for some other reason, display an error message
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private bool CreateResultsPDF(iTextSharp.text.Document document)
{
bool result = false;
string suffix = "";
int i = 0;
// Try to open a file for creating the PDF.
while (result == false)
{
string fileName = _FileName.ToLower().Replace(".pdf", suffix + ".pdf");
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
document.SetMargins(36, 36, 36, 36);
document.Open();
_FileName = fileName;
result = true;
}
catch (System.IO.IOException exIO)
{
if (exIO.Message.Contains("because it is being used by another process"))
suffix = string.Format("_{0}", ++i);// If this file is in use, increment the suffix and try again
else // If some other error, display a message and don't print the results
{
ShowException(exIO);
return false;
}
}
catch (Exception ex)
{
ShowException(ex);
return false; // Could not open the output file
}
}
return true;
}
private static void ShowException(Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
StringBuilder msg = new StringBuilder();
string sep = "";
string indent = "";
while (ex != null)
{
msg.Append(string.Format("{0}{1}{2}:\r\n{1}{3}", sep, indent, ex.GetType().Name, ex.Message));
ex = ex.InnerException;
sep = "\r\n";
indent += " ";
}
System.Windows.Forms.MessageBox.Show(msg.ToString(), "Error during PDF creation for search:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
}
/// <summary>
/// Use Cells within Cells to see if I can limit the way Cells break from Page to Page
/// </summary>
/// <param name="document"></param>

View File

@ -772,7 +772,14 @@ namespace Volian.Print.Library
if (rnoLevel < maxRNO && itemInfo.RNOs != null) yOffRight = ChildrenRight.Add(cb, itemInfo.RNOs, XOffset + RnoOffset, YTop, YTop, rnoLevel + 1, maxRNO, formatInfo);
// Need code to determine if the table will overlap the Right Column if it does then
// use YOffRight rather than yoff
if (itemInfo.Tables != null) yoff = ChildrenBelow.Add(cb, itemInfo.Tables, XOffset, yoff, yOffRight, rnoLevel, maxRNO, formatInfo);
if (itemInfo.Tables != null)
{
bool aerTableOrFigure = itemInfo.FormatStepData.Type.Contains("AER");
if(!aerTableOrFigure && itemInfo.RNOLevel == 0) // Centered Table
yoff = ChildrenBelow.Add(cb, itemInfo.Tables, XOffset, yOffRight, yOffRight, rnoLevel, maxRNO, formatInfo);
else // AER or RNO Table
yoff = ChildrenBelow.Add(cb, itemInfo.Tables, XOffset, yoff, yOffRight, rnoLevel, maxRNO, formatInfo);
}
if (itemInfo.Steps != null) yoff = ChildrenBelow.Add(cb, itemInfo.Steps, XOffset, yoff, yOffRight, rnoLevel, maxRNO, formatInfo);
if (itemInfo.Sections != null) yoff = ChildrenBelow.Add(cb, itemInfo.Sections, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo);
if (itemInfo.Procedures != null) yoff = ChildrenBelow.Add(cb, itemInfo.Procedures, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo);
@ -794,17 +801,26 @@ namespace Volian.Print.Library
private void CalculateXOffset(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo)
{
bool aerFigure = itemInfo.FormatStepData.Type.Contains("AER");
bool aerTableOrFigure = itemInfo.FormatStepData.Type.Contains("AER");
vlnParagraph hls1 = MyParent;
while (hls1.MyParent != null && !hls1.MyItemInfo.IsHigh) hls1 = hls1.MyParent;
XOffset = hls1.XOffset + hls1.Width / 2 - Width / 2; // xoffset if AER column
if (!aerFigure)
int colR = int.Parse(formatInfo.MyStepSectionLayoutData.ColRTable.Split(",".ToCharArray())[itemInfo.ColumnMode]);
float xLowerLimit = 6; // Adjusted for HLP VE-PROMS
float xUpperLimit = hls1.XOffset + hls1.Width + colR * itemInfo.ColumnMode + 18; // Adjusted for HLP VE-PROMS
if (!aerTableOrFigure && itemInfo.RNOLevel == 0) // Centered Table of Figure
{
// adjust for RNO
int colR = int.Parse(formatInfo.MyStepSectionLayoutData.ColRTable.Split(",".ToCharArray())[itemInfo.ColumnMode]);
XOffset += (colR * maxRNO) / 2;
XOffset += (colR * itemInfo.ColumnMode) / 2;
XOffset -= (hls1.XOffset - (float)itemInfo.MyDocStyle.Layout.LeftMargin) / 2;
}
else // AER or RNO
XOffset = MyParent.XOffset + MyParent.Width / 2 - Width / 2;
//XOffset += colR * itemInfo.RNOLevel;
if (XOffset < xLowerLimit)
XOffset = xLowerLimit;
if (XOffset + Width > xUpperLimit)
XOffset = xUpperLimit - Width;
if (XOffset < (float)itemInfo.MyDocStyle.Layout.LeftMargin)
XOffsetBox = (float)itemInfo.MyDocStyle.Layout.LeftMargin;
}