Skip to content

Commit e29cdfa

Browse files
committed
1004234: Updated the proper code in Playground sample.
1 parent c4b400a commit e29cdfa

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

  • Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document
  • Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF

Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
{
77
// Create a new PdfCompressionOptions object
88
PdfCompressionOptions options = new PdfCompressionOptions();
9-
//Enable the compress image
10-
options.CompressImages = true;
119
//Set the image quality
1210
options.ImageQuality = 50;
1311
// Compress the PDF document

Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/Program.cs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@
55
// Create a new PDF document
66
using (PdfDocument document = new PdfDocument())
77
{
8-
//Add a page to the document
8+
// Add a new page to the PDF document
99
PdfPage page = document.Pages.Add();
10-
// Create a PdfGrid
10+
// Create a PdfGrid to display tabular data
1111
PdfGrid pdfGrid = new PdfGrid();
12-
// Add values to the list
13-
List<object> data = new List<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+
object data = new List<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)
2020
pdfGrid.DataSource = data;
21-
// Draw the grid on the PDF page
22-
pdfGrid.Draw(page, new PointF(10, 10));
21+
// Access the auto-generated header row and set custom column names
22+
PdfGridRow header = 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
26+
PdfPaddings paddings = new PdfPaddings(10, 8, 10, 8);
27+
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold);
28+
// Create header style with padding, white text, blue background, and bold font
29+
PdfGridCellStyle headerStyle = new PdfGridCellStyle
30+
{
31+
CellPadding = paddings,
32+
TextBrush = new PdfSolidBrush(Color.White),
33+
BackgroundBrush = new PdfSolidBrush(Color.Blue),
34+
Font = font
35+
};
36+
// Apply the header style to the header row
37+
pdfGrid.Headers[0].ApplyStyle(headerStyle);
38+
// Apply padding and font style to body cells
39+
pdfGrid.Style.CellPadding = paddings;
40+
pdfGrid.Style.Font = font;
41+
// Draw the grid on the PDF page at specified position (with margin)
42+
pdfGrid.Draw(page, new PointF(20, 40));
2343
// Save the PDF document
2444
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
2545
}

0 commit comments

Comments
 (0)