Is it possible to use row shading in the .pdf's? I am trying to change the background color of every other row in a report to either gray or some other color.
Thanks in advance.
Is it possible to use row shading in the .pdf's? I am trying to change the background color of every other row in a report to either gray or some other color.
Thanks in advance.
Hello Shane,
Thanks for considering Aspose.
You can set the background color of table row using Row.BackgroundColor property. Please take a look over the following code snippet in which over every iteration of the loop, background color of the row is changed.
[C#]
Pdf pdf = new Pdf();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
//Instantiate a table object
Table tab1 = new Table();
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = "50 50 50";
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);
//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo((int)BorderSide.All, 1F);
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
for (int i = 0; i <= 10; i++)
{
//Create rows in the table and then cells in the rows
Row row1 = tab1.Rows.Add();
if (i % 2 == 0)
// set background color of row as Gray
row1.BackgroundColor = new Aspose.Pdf.Color("Gray");
else
row1.BackgroundColor = new Aspose.Pdf.Color("Yellow");
row1.Cells.Add("col1");
row1.Cells.Add("col2");
row1.Cells.Add("col3");
}
// save the document
pdf.Save(@"d:/pdftest/AlternateBackground.pdf");
For your reference, I've also attached the resultant PDF generated through above code snippet. In case it does not satisfy your requirement or you've any further query, please feel free to contact.