PdfDocument pdfDocument = new PdfDocument(); PdfPage pdfPage = pdfDocument.Pages.Add();
PdfGraphics graphics = pdfPage.Graphics;
//Create a new PdfGrid. PdfGrid pdfGrid = new PdfGrid();
pdfGrid.BeginCellLayout += PdfGrid_BeginCellLayout;
//Add three columns. pdfGrid.Columns.Add(3); //Add header. pdfGrid.Headers.Add(1); pdfGrid.RepeatHeader = true; PdfGridRow pdfGridHeader = pdfGrid.Headers[0];
pdfGridHeader.Cells[0].Value = "Employee ID"; pdfGridHeader.Cells[1].Value = "Employee Name"; pdfGridHeader.Cells[2].Value = "Salary"; for (int i = 0; i < 850; i++) { //Add rows. PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Cells[0].Value = "Employe 1 "; pdfGridRow.Cells[1].Value = "John"; pdfGridRow.Cells[2].Value = "$10,000"; }
//Draw the PdfGrid. pdfGrid.Draw(pdfPage, PointF.Empty);
MemoryStream ms = new MemoryStream();
//Save the document. pdfDocument.Save(ms);
//Console.Read(); ms.Position = 0;
File.WriteAllBytes("Output.pdf", ms.ToArray());
//Close the document pdfDocument.Close(true);
static void PdfGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args) { //Draw multiple fonts for a particular table cell. if (args.CellIndex == 2 && args.RowIndex==0) { args.Graphics.DrawRectangle(PdfBrushes.Red, new RectangleF(args.Bounds.X, args.Bounds.Y, args.Bounds.Width, args.Bounds.Height)); } if (args.CellIndex == 0 && args.RowIndex==1) {
args.Style.BackgroundBrush = PdfBrushes.Green; args.Style.TextBrush = PdfBrushes.White; } if (args.CellIndex == 1) { args.Style.TextBrush = PdfBrushes.Blue; } }
|