You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs
+32-12Lines changed: 32 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,41 @@
5
5
// Create a new PDF document
6
6
using(PdfDocumentdocument=newPdfDocument())
7
7
{
8
-
//Add a page to the document
8
+
//Add a new page to the PDF document
9
9
PdfPagepage=document.Pages.Add();
10
-
// Create a PdfGrid
10
+
// Create a PdfGrid to display tabular data
11
11
PdfGridpdfGrid=newPdfGrid();
12
-
// Add values to the list
13
-
List<object>data=newList<object>
14
-
{
15
-
new{ID="E01",Name="Clay"},
16
-
new{ID="E02",Name="Thomas"},
17
-
new{ID="E03",Name="John"}
18
-
};
19
-
// Assign the data source to the grid
12
+
// Prepare sample data for the grid
13
+
objectdata=newList<object>
14
+
{
15
+
new{ID="E01",Name="Clay"},
16
+
new{ID="E02",Name="Thomas"},
17
+
new{ID="E03",Name="John"}
18
+
};
19
+
// Assign the data source to the grid (auto-generates a header row)
20
20
pdfGrid.DataSource=data;
21
-
// Draw the grid on the PDF page
22
-
pdfGrid.Draw(page,newPointF(10,10));
21
+
// Access the auto-generated header row and set custom column names
22
+
PdfGridRowheader=pdfGrid.Headers[0];
23
+
header.Cells[0].Value="ID";
24
+
header.Cells[1].Value="Name";
25
+
// Define padding and font for header and body cells
0 commit comments