New to Telerik Document Processing? Download free 30-day trial

Creating a Dashed Line Border for a Table in RadPdfProcessing

Environment

Version Product Author
2024.1.124 RadPdfProcessing Desislava Yordanova

Description

Learn how to add a dashed line border in a table using RadPdfProcessing.

Solution

To create a dashed line border for a Table in RadPdfProcessing, you can follow these steps:

  1. Set the desired font style properties for the table.
  2. Create a Border object with the desired thickness, style, and color.
  3. Set the Borders property of the table's DefaultCellProperties to the created Border object.
  4. Set the Padding property of the table's DefaultCellProperties to the desired padding values.
  5. Add rows and cells to the table and set the preferred width for each cell.
  6. Insert text into each cell using the desired font style properties.
  7. Use a FixedContentEditor to draw the table on the document page.
  8. Specify the desired dashed line style by setting the StrokeDashArray property of the GraphicProperties of the FixedContentEditor.

Here is a sample code snippet that demonstrates how to create a dashed line border for a table in RadPdfProcessing:

Dashed Table Border

FontFamily fFamily = new FontFamily("Verdana");
RadFixedDocument fixedDocument = new RadFixedDocument();
Table table = new Table();
int thickness = 1;
RgbColor borderColor = new RgbColor(255, 0, 0);
Border b = new Border(thickness, BorderStyle.Single, borderColor);    
table.DefaultCellProperties.Borders = new TableCellBorders(b,b,b,b);
table.DefaultCellProperties.Padding = new Thickness(2, 2, 2, 2);        
TableRow r1 = table.Rows.AddTableRow();
TableCell firstCell = r1.Cells.AddTableCell();
firstCell.PreferredWidth = 200;
firstCell.Blocks.AddBlock().InsertText(fFamily, FontStyles.Normal, FontWeights.ExtraBold, "Telerik");
TableCell secondCell = r1.Cells.AddTableCell();
secondCell.PreferredWidth = 150;
secondCell.Blocks.AddBlock().InsertText(fFamily, FontStyles.Normal, FontWeights.Regular, "Document");
TableCell thirdCell = r1.Cells.AddTableCell();
thirdCell.PreferredWidth = 100;
thirdCell.Blocks.AddBlock().InsertText(fFamily, FontStyles.Normal, FontWeights.Bold, "Processing");

FixedContentEditor fixedEditor = new FixedContentEditor(fixedDocument.Pages.AddPage());
fixedEditor.GraphicProperties.IsFilled = true;
fixedEditor.GraphicProperties.StrokeDashArray = new double[] { 2,2};
fixedEditor.Position.Translate(10, 100);
fixedEditor.DrawTable(table);

string outputFilePath = @"..\..\output.pdf";
File.Delete(outputFilePath);
PdfFormatProvider provider = new PdfFormatProvider();
using (Stream output = File.OpenWrite(outputFilePath))
{
    provider.Export(fixedDocument, output);
}
Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });

Please note that you can modify the Borders property of the DefaultCellProperties to specify different border styles for each side of the cell or render a border only at the bottom: Bottom Dashed Table Border

table.DefaultCellProperties.Borders = new TableCellBorders(null, null, null,b);

As of Q3 2024 RadPdfProcessing offers Dotted, Dashed, and DashSmallGap border styles out-of-the-box without the necessity to play with the StrokeDashArray of the FixedContentEditor. With this update, the Dotted, Dashed, DashSmallGap, and Thick border lines are now exported from RadFlowDocument to RadFixedDocument as well.

See Also

In this article