using System; using iTextSharp.text; using iTextSharp.text.html; using iTextSharp.text.pdf; using Spring.Objects; using Sleis.Utility; using System.Collections.Generic; namespace Sleis.Pdf { public class ColumnObjectElementWriter : ElementWriter { public List Elements { get; set; } public int Columns { get; set; } public override void Init() { ArgumentValidationUtility.ThrowOnEmpty(Elements, "Elements"); if (Columns < 1) { Columns = 2; } } public override void Write(Document pdf, ObjectWrapper context) { LOG.Debug("Init Write"); BeforeWrite(pdf, context); MultiColumnText columns = new MultiColumnText(); columns.AddRegularColumns(36f, pdf.PageSize.Width - 36f, 24f, Columns); foreach (ObjectElementWriter ew in Elements) { object selectionValue = null; try { selectionValue = context.GetPropertyValue(ew.Select); } catch(Exception err) { LOG.Debug(String.Format("Error getting accessing {0} : {1}", Select, err.Message)); }//swallowed if (selectionValue != null || !ew.SkipNulls) { Paragraph colParagraph = new Paragraph(String.Format(ew.Format, selectionValue), Font); if (ew.SpaceBefore.HasValue) { colParagraph.SpacingBefore = ew.SpaceBefore.Value; } if (ew.SpaceAfter.HasValue) { colParagraph.SpacingAfter = ew.SpaceAfter.Value; } colParagraph.Add(new Paragraph(ew.Label, LabelFont)); colParagraph.Add(new Paragraph(String.Format(ew.Format, selectionValue), Font)); columns.AddElement(colParagraph); } } pdf.Add(columns); } } }