Some sample code:
Code:
struct RowItem
{
public int R, G, B;
public string Text;
}
static void Demo()
{
var data = new[]
{
new RowItem{R = 255, G = 0, B = 0, Text = "Red row"},
new RowItem{R = 0, G = 255, B = 0, Text = "Green row"},
new RowItem{R = 255, G = 255, B = 0, Text = "Yellow row"},
new RowItem{R = 0, G = 0, B = 255, Text = "Blue row"},
new RowItem{R = 255, G = 0, B = 255, Text = "Purple row"},
new RowItem{R = 0, G = 255, B = 255, Text = "Cyan row"},
new RowItem{R = 0, G = 0, B = 0, Text = "Black row"}
};
var document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
var textformater = new XTextFormatter(gfx);
XFont font = new XFont("Segoe UI", 20, XFontStyle.Regular);
int y = 50;
textformater.DrawString(" Color", font, XBrushes.Black, new XRect(35, y, 70, 25));
textformater.DrawString(" Subdivision Name", font, XBrushes.Black, new XRect(100, y, 250, 25));
foreach (var item in data)
{
y = y + 30;
XRect snoColumnVal = new XRect(35, y, 60, 25);
XRect snoStudentNameVal = new XRect(100, y, 250, 25);
var brush = new XSolidBrush(XColor.FromArgb(255, item.R, item.G, item.B));
//gfx.DrawRectangle(XPens.Black, brush, snoColumnVal);
gfx.DrawRectangle(brush, snoColumnVal);
textformater.DrawString(item.Text, font, XBrushes.Black, snoStudentNameVal);
}
const string filename = "HelloWorld_tempfile.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}