Changed report format to increase font size, switch to landscape, add page numbers, add colum headings and add date generated.

This commit is contained in:
Rich 2015-01-25 13:18:02 +00:00
parent 85771b0dda
commit 9c62cc93eb

View File

@ -33,6 +33,24 @@ namespace Volian.Print.Library
get { return _FileName; }
set { _FileName = value; }
}
private PdfPCell _CurrentPageNumberCell = null;
private int _CurrentPageNumber = 1;
public int CurrentPageNumber
{
get
{
return _CurrentPageNumber;
}
set
{
if (_CurrentPageNumberCell != null)
{
_CurrentPageNumber = value;
_CurrentPageNumberCell.Phrase.Clear();
_CurrentPageNumberCell.Phrase.Add("Page " + value.ToString());
}
}
}
private FolderInfo folderInfo;
private ProcedureInfo procedureInfo;
private TransitionInfoList transitionInfoList;
@ -68,7 +86,7 @@ namespace Volian.Print.Library
}
public void BuildTransitionReport()
{
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 36, 36, 36, 36);
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER.Rotate(), 36, 36, 36, 36);
if (!CreateResultsPDF(document)) return;
try
{
@ -137,10 +155,10 @@ namespace Volian.Print.Library
}
PdfOutline outline = null;
ProcedureInfo lastProcedureInfo = null;
private PdfPTable BuildProcedurePDFTable(Dictionary<int, string> levels, Dictionary<int, iTextSharp.text.Font> fonts, int cols, int paddingBottom, int level)
private PdfPTable BuildProcedurePDFTable(Dictionary<int, string> levels, Dictionary<int, iTextSharp.text.Font> fonts, int cols, int paddingBottom, int level, iTextSharp.text.Document doc)
{
PdfPTable t = new PdfPTable(cols);
t.HeaderRows = 3;
t.HeaderRows = 4;
t.DefaultCell.Padding = 4;
t.WidthPercentage = 100;
float[] widths;
@ -157,10 +175,18 @@ namespace Volian.Print.Library
else
h.Add("Transition Report");
PdfPCell c = new PdfPCell(h);
c.Colspan = cols;
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.Colspan = cols-1;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod);
t.AddCell(c);
//date generated
h = new Phrase();
h.Font = fonts[4];
h.Add(DateTime.Now.ToString("dddd MMMM d, yyyy @ h:mm tt"));
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_RIGHT;
c.PaddingBottom = paddingBottom;
//c.Border = borders;
c.BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod);
t.AddCell(c);
//procedure title
@ -174,12 +200,15 @@ namespace Volian.Print.Library
lastProcedureInfo = procedureInfo;
}
c = new PdfPCell(h);
c.Colspan = cols;
c.Colspan = cols-1;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
//c.Border = borders;
c.BackgroundColor = new Color(System.Drawing.Color.Goldenrod);
t.AddCell(c);
//page number
_CurrentPageNumberCell = BuildCell(1, string.Format("Page {0}",CurrentPageNumber), fonts[4], new Color(System.Drawing.Color.Goldenrod));
_CurrentPageNumberCell.PaddingBottom = paddingBottom;
t.AddCell(_CurrentPageNumberCell);
//transition category
h = new Phrase();
h.Font = fonts[3];
@ -197,6 +226,31 @@ namespace Volian.Print.Library
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.Khaki);
t.AddCell(c);
//add column headers
h = new Phrase();
h.Font = fonts[4];
h.Add("From Procedure Location");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
h = new Phrase();
h.Font = fonts[4];
h.Add("From Procedure Text");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
h = new Phrase();
h.Font = fonts[4];
h.Add("To Procedure Location");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
return t;
}
PdfContentByte cb;
@ -210,17 +264,17 @@ namespace Volian.Print.Library
levels.Add(4, "Outside From Transitions");
levels.Add(5, "Outside To Transitions");
Dictionary<int, iTextSharp.text.Font> fonts = new Dictionary<int, Font>();
fonts.Add(1, pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK));
fonts.Add(2, pdf.GetFont("Arial Unicode MS", 8, 0, Color.BLACK));
fonts.Add(3, pdf.GetFont("Arial Unicode MS", 6, 0, Color.BLACK));
fonts.Add(4, pdf.GetFont("Arial Unicode MS", 4, 0, Color.BLACK));
fonts.Add(1, pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK));
fonts.Add(2, pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK));
fonts.Add(3, pdf.GetFont("Arial Unicode MS", 8, 0, Color.BLACK));
fonts.Add(4, pdf.GetFont("Arial Unicode MS", 8, 0, Color.BLACK));
int lastLevel = transitionInfoList.Count > 0 ? transitionInfoList[0].Level : 0; //set level to first transition level
#region buildtable
int cols = 3;
int paddingBottom = 6;
if (folderInfo != null)
doc.NewPage();
PdfPTable t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel);
PdfPTable t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel, doc);
#endregion
//gather data
if (transitionInfoList.Count == 0)
@ -247,7 +301,7 @@ namespace Volian.Print.Library
doc.Add(t);
doc.NewPage();
lastLevel = ti.Level;
t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel);
t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel, doc);
}
}
//add from path
@ -364,6 +418,7 @@ namespace Volian.Print.Library
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
writer.PageEvent = new MyPageEvent(this);
document.SetMargins(36, 36, 36, 36);
document.Open();
cb = writer.DirectContent;
@ -411,5 +466,29 @@ namespace Volian.Print.Library
c.Border = 0;
return c;
}
private PdfPCell BuildCell(int colspan, string txt, Font f, iTextSharp.text.Color clr)
{
Phrase h = new Phrase();
h.Font = f;
h.Add(txt);
PdfPCell c = new PdfPCell(h);
c.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
c.Colspan = colspan;
c.BackgroundColor = clr;
return c;
}
}
public class MyPageEvent : PdfPageEventHelper
{
private PDFTransitionReport _rpt = null;
public MyPageEvent(PDFTransitionReport rpt)
{
_rpt = rpt;
}
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document)
{
base.OnEndPage(writer, document);
_rpt.CurrentPageNumber = writer.PageNumber + 1;
}
}
}