Skip to content

Commit 060dc7e

Browse files
authored
Merge pull request #234 from SyncfusionExamples/1004234
1004234: Updated the proper code in Playground sample.
2 parents c4b400a + 914f1f7 commit 060dc7e

File tree

4 files changed

+36
-28
lines changed
  • 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

4 files changed

+36
-28
lines changed

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

Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Path.GetFullPath
2525
{
2626
// Create a new PdfCompressionOptions object
2727
PdfCompressionOptions options = new PdfCompressionOptions();
28-
//Enable the compress image
29-
options.CompressImages = true;
3028
//Set the image quality
3129
options.ImageQuality = 50;
3230
// 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: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
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", Department = "HR" },
16+
new { ID = "E02", Name = "Thomas", Department = "Finance" },
17+
new { ID = "E03", Name = "John", Department = "IT" },
18+
new { ID = "E04", Name = "Emma", Department = "Marketing" },
19+
new { ID = "E05", Name = "Sophia", Department = "Operations" }
20+
};
21+
// Assign the data source to the grid (auto-generates a header row)
2022
pdfGrid.DataSource = data;
21-
// Draw the grid on the PDF page
22-
pdfGrid.Draw(page, new PointF(10, 10));
23+
//Apply built-in table style
24+
pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent6);
25+
// Apply padding and font style to body cells
26+
pdfGrid.Style.CellPadding = new PdfPaddings(10, 6, 10, 6);
27+
// Draw the grid on the PDF page at specified position (with margin)
28+
pdfGrid.Draw(page, new PointF(20, 40));
2329
// Save the PDF document
2430
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
2531
}

Table/PdfGrid/Create-table-from-data-source-in-a-PDF/.NET/Create-table-from-data-source-in-a-PDF/README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,27 @@ Step 4: **Add a table to the PDF**: Use the following code in **Program.cs** to
2222
// Create a new PDF document
2323
using (PdfDocument document = new PdfDocument())
2424
{
25-
//Add a page to the document
25+
// Add a new page to the PDF document
2626
PdfPage page = document.Pages.Add();
27-
// Create a PdfGrid
27+
// Create a PdfGrid to display tabular data
2828
PdfGrid pdfGrid = new PdfGrid();
29-
// Add values to the list
30-
List<object> data = new List<object>
31-
{
32-
new { ID = "E01", Name = "Clay" },
33-
new { ID = "E02", Name = "Thomas" },
34-
new { ID = "E03", Name = "John" }
35-
};
36-
// Assign the data source to the grid
29+
// Prepare sample data for the grid
30+
object data = new List<object>
31+
{
32+
new { ID = "E01", Name = "Clay", Department = "HR" },
33+
new { ID = "E02", Name = "Thomas", Department = "Finance" },
34+
new { ID = "E03", Name = "John", Department = "IT" },
35+
new { ID = "E04", Name = "Emma", Department = "Marketing" },
36+
new { ID = "E05", Name = "Sophia", Department = "Operations" }
37+
};
38+
// Assign the data source to the grid (auto-generates a header row)
3739
pdfGrid.DataSource = data;
38-
// Draw the grid on the PDF page
39-
pdfGrid.Draw(page, new PointF(10, 10));
40+
//Apply built-in table style
41+
pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent6);
42+
// Apply padding and font style to body cells
43+
pdfGrid.Style.CellPadding = new PdfPaddings(10, 6, 10, 6);
44+
// Draw the grid on the PDF page at specified position (with margin)
45+
pdfGrid.Draw(page, new PointF(20, 40));
4046
// Save the PDF document
4147
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
4248
}

0 commit comments

Comments
 (0)