/// <summary> /// Sets visual border style for specified <see cref="Image"/>. /// </summary> /// <param name="image">Horizontal alignment.</param> /// <param name="style">Style to apply.</param> /// <returns> /// A <see cref="int"/> value that represents the alignment. /// </returns> public static Image SetVisualStyle(this Image image, PdfImageStyle style) { if (!string.IsNullOrEmpty(style.Content.Color)) { image.BackgroundColor = new BaseColor(style.Content.GetColor()); } BordersCollection borders = style.Borders; image.BorderWidthLeft = 0.0f; BaseBorder leftBorder = borders.GetBy(KnownBorderPosition.Left); if (leftBorder != null) { if (leftBorder.Show.AsBoolean()) { image.BorderWidthLeft = leftBorder.Width; image.BorderColorLeft = new BaseColor(leftBorder.GetColor()); } } image.BorderWidthTop = 0.0f; BaseBorder topBorder = borders.GetBy(KnownBorderPosition.Top); if (topBorder != null) { if (topBorder.Show.AsBoolean()) { image.BorderWidthTop = topBorder.Width; image.BorderColorTop = new BaseColor(topBorder.GetColor()); } } image.BorderWidthRight = 0.0f; BaseBorder rightBorder = borders.GetBy(KnownBorderPosition.Right); if (rightBorder != null) { if (rightBorder.Show.AsBoolean()) { image.BorderWidthRight = rightBorder.Width; image.BorderColorRight = new BaseColor(rightBorder.GetColor()); } } image.BorderWidthBottom = 0.0f; BaseBorder bottomBorder = borders.GetBy(KnownBorderPosition.Bottom); if (bottomBorder != null) { if (bottomBorder.Show.AsBoolean()) { image.BorderWidthBottom = bottomBorder.Width; image.BorderColorBottom = new BaseColor(bottomBorder.GetColor()); } } return(image); }
/// <summary> /// Creates a new empty cell. /// </summary> /// <param name="useTestMode">Indicates if draw a border in testmode.</param> /// <param name="borders">The borders color, it allows defining the background color so as not to draw a border when we do not use test mode.</param> /// <returns> /// A new <see cref="PdfPCell"/> with visual style defined in the model. /// </returns> public static PdfPCell CreateEmptyCell(YesNo useTestMode = YesNo.No, BordersCollection borders = null) { return(useTestMode.AsBoolean() ? CreateEmptyWithBorderCell(BordersCollection.FromKnownColor(KnownBorderColor.Red)) : borders == null ? CreateEmptyWithoutBorderCell() : CreateEmptyWithBorderCell(borders)); }
/// <summary> /// Sets visual border style for specified cell. /// </summary> /// <param name="cell">Cell which receives visual style.</param> /// <param name="borders">Border collection definition to apply.</param> /// <returns> /// A <see cref="PdfPCell"/> object which contains specified visual style. /// </returns> public static PdfPCell SetBordersVisualStyle(this PdfPCell cell, BordersCollection borders) { cell.BorderWidthLeft = 0.0f; BaseBorder leftBorder = borders.GetBy(KnownBorderPosition.Left); if (leftBorder != null) { if (leftBorder.Show.AsBoolean()) { cell.BorderWidthLeft = leftBorder.Width; cell.BorderColorLeft = new BaseColor(leftBorder.GetColor()); } } cell.BorderWidthTop = 0.0f; BaseBorder topBorder = borders.GetBy(KnownBorderPosition.Top); if (topBorder != null) { if (topBorder.Show.AsBoolean()) { cell.BorderWidthTop = topBorder.Width; cell.BorderColorTop = new BaseColor(topBorder.GetColor()); } } cell.BorderWidthRight = 0.0f; BaseBorder rightBorder = borders.GetBy(KnownBorderPosition.Right); if (rightBorder != null) { if (rightBorder.Show.AsBoolean()) { cell.BorderWidthRight = rightBorder.Width; cell.BorderColorRight = new BaseColor(rightBorder.GetColor()); } } cell.BorderWidthBottom = 0.0f; BaseBorder bottomBorder = borders.GetBy(KnownBorderPosition.Bottom); if (bottomBorder != null) { if (bottomBorder.Show.AsBoolean()) { cell.BorderWidthBottom = bottomBorder.Width; cell.BorderColorBottom = new BaseColor(bottomBorder.GetColor()); } } return(cell); }
/// <summary> /// Creates a new empty cell with border(s). /// </summary> /// <param name="borders">Borders definition.</param> /// <returns> /// A new <see cref="PdfPCell"/> with visual style defined in the model. /// </returns> public static PdfPCell CreateEmptyWithBorderCell(BordersCollection borders) => new PdfPCell().SetBordersVisualStyle(borders);