using iText.Kernel.Geom; using iText.Layout; using iText.Layout.Element; using iText.Layout.Properties; namespace Elwig.Documents { public static class Extensions { public static T SetFixedPositionMM(this BlockElement element, float left, float top, float width, Rectangle pageSize) where T : IElement { element.SetVerticalAlignment(VerticalAlignment.TOP); return element.SetFixedPosition(left * Document.PtInMM, pageSize.GetTop() - top * Document.PtInMM, width * Document.PtInMM); } public static T SetFixedPositionMM(this BlockElement element, float left, float top, float width, float height, Rectangle pageSize) where T : IElement { element.SetHeight(height * Document.PtInMM); return element.SetFixedPosition(left * Document.PtInMM, pageSize.GetTop() - (top + height) * Document.PtInMM, width * Document.PtInMM); } public static T SetFixedPositionMM(this ElementPropertyContainer element, float left, float bottom, float width) where T : IPropertyContainer { return element.SetFixedPosition(left * Document.PtInMM, bottom * Document.PtInMM, width * Document.PtInMM); } public static T SetHeightMM(this BlockElement element, float height) where T : IElement { return element.SetHeight(height * Document.PtInMM); } public static T SetPaddingTopMM(this BlockElement element, float top) where T : IElement { return element.SetPaddingTop(top * Document.PtInMM); } public static T SetPaddingRightMM(this BlockElement element, float right) where T : IElement { return element.SetPaddingRight(right * Document.PtInMM); } public static T SetPaddingBottomMM(this BlockElement element, float bottom) where T : IElement { return element.SetPaddingBottom(bottom * Document.PtInMM); } public static T SetPaddingLeftMM(this BlockElement element, float left) where T : IElement { return element.SetPaddingLeft(left * Document.PtInMM); } public static T SetPaddingsMM(this BlockElement element, float top, float right, float bottom, float left) where T : IElement { return element.SetPaddings(top * Document.PtInMM, right * Document.PtInMM, bottom * Document.PtInMM, left * Document.PtInMM); } public static T SetMarginTopMM(this BlockElement element, float top) where T : IElement { return element.SetMarginTop(top * Document.PtInMM); } public static T SetMarginRightMM(this BlockElement element, float right) where T : IElement { return element.SetMarginRight(right * Document.PtInMM); } public static T SetMarginBottomMM(this BlockElement element, float bottom) where T : IElement { return element.SetMarginBottom(bottom * Document.PtInMM); } public static T SetMarginLeftMM(this BlockElement element, float left) where T : IElement { return element.SetMarginLeft(left * Document.PtInMM); } public static T SetMarginsMM(this BlockElement element, float top, float right, float bottom, float left) where T : IElement { return element.SetMargins(top * Document.PtInMM, right * Document.PtInMM, bottom * Document.PtInMM, left * Document.PtInMM); } public static void SetTopMarginMM(this iText.Layout.Document element, float top) { element.SetTopMargin(top * Document.PtInMM); } public static void SetRightMarginMM(this iText.Layout.Document element, float right) { element.SetRightMargin(right * Document.PtInMM); } public static void SetBottomMarginMM(this iText.Layout.Document element, float bottom) { element.SetBottomMargin(bottom * Document.PtInMM); } public static void SetLeftMarginMM(this iText.Layout.Document element, float left) { element.SetLeftMargin(left * Document.PtInMM); } public static void SetMarginsMM(this iText.Layout.Document element, float top, float right, float bottom, float left) { element.SetMargins(top * Document.PtInMM, right * Document.PtInMM, bottom * Document.PtInMM, left * Document.PtInMM); } public static Table AddCells(this Table table, params Cell[] cells) { foreach (var cell in cells) table.AddCell(cell); return table; } } }