94 lines
4.5 KiB
C#
94 lines
4.5 KiB
C#
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<T>(this BlockElement<T> 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<T>(this BlockElement<T> 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<T>(this ElementPropertyContainer<T> 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<T>(this BlockElement<T> element, float height) where T : IElement {
|
|
return element.SetHeight(height * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetPaddingTopMM<T>(this BlockElement<T> element, float top) where T : IElement {
|
|
return element.SetPaddingTop(top * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetPaddingRightMM<T>(this BlockElement<T> element, float right) where T : IElement {
|
|
return element.SetPaddingRight(right * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetPaddingBottomMM<T>(this BlockElement<T> element, float bottom) where T : IElement {
|
|
return element.SetPaddingBottom(bottom * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetPaddingLeftMM<T>(this BlockElement<T> element, float left) where T : IElement {
|
|
return element.SetPaddingLeft(left * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetPaddingsMM<T>(this BlockElement<T> 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<T>(this BlockElement<T> element, float top) where T : IElement {
|
|
return element.SetMarginTop(top * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetMarginRightMM<T>(this BlockElement<T> element, float right) where T : IElement {
|
|
return element.SetMarginRight(right * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetMarginBottomMM<T>(this BlockElement<T> element, float bottom) where T : IElement {
|
|
return element.SetMarginBottom(bottom * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetMarginLeftMM<T>(this BlockElement<T> element, float left) where T : IElement {
|
|
return element.SetMarginLeft(left * Document.PtInMM);
|
|
}
|
|
|
|
public static T SetMarginsMM<T>(this BlockElement<T> 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;
|
|
}
|
|
}
|
|
}
|