Skip to content

Commit aae7bab

Browse files
Merge pull request #158 from SyncfusionExamples/929882
929882 Changing Margins from the Second Page onwards in a PDF Document
2 parents 8df4a8b + aef725a commit aae7bab

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Changing-Margins-from-the-Second-Page-onwards", "Changing-Margins-from-the-Second-Page-onwards\Changing-Margins-from-the-Second-Page-onwards.csproj", "{646D9954-C91D-4ACB-A104-9C9331EE1845}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{646D9954-C91D-4ACB-A104-9C9331EE1845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{646D9954-C91D-4ACB-A104-9C9331EE1845}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{646D9954-C91D-4ACB-A104-9C9331EE1845}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{646D9954-C91D-4ACB-A104-9C9331EE1845}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Changing_Margins_from_the_Second_Page_onwards</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Syncfusion.Pdf.Grid;
2+
using Syncfusion.Pdf;
3+
using Syncfusion.Drawing;
4+
5+
// Create PDF document
6+
PdfDocument document = new PdfDocument();
7+
8+
// Configure marginless page layout
9+
document.PageSettings.Margins.Top = 0;
10+
document.PageSettings.Margins.Bottom = 0;
11+
12+
// Add first page to the document
13+
PdfPage page = document.Pages.Add();
14+
15+
// Initialize grid component for data presentation
16+
PdfGrid pdfGrid = new PdfGrid();
17+
18+
// Generate sample data (300 rows)
19+
List<object> data = new List<object>();
20+
for (int i = 0; i < 100; i++)
21+
{
22+
// Create three unique rows per iteration
23+
data.Add(new { ID = "1", Name = "Clay", Price = "$10" });
24+
data.Add(new { ID = "2", Name = "Gray", Price = "$20" });
25+
data.Add(new { ID = "3", Name = "Ash", Price = "$30" });
26+
}
27+
28+
// Configure grid data binding
29+
pdfGrid.DataSource = data; // Automatic conversion to IEnumerable
30+
31+
// Set up grid layout with header space
32+
PdfGridLayoutFormat format = new PdfGridLayoutFormat
33+
{
34+
PaginateBounds = new RectangleF(0, 15,
35+
page.GetClientSize().Width,
36+
page.GetClientSize().Height - 15)
37+
};
38+
39+
// Render grid to page with automatic pagination
40+
pdfGrid.Draw(page, new RectangleF(0, 0,
41+
page.GetClientSize().Width,
42+
page.GetClientSize().Height), format);
43+
44+
//Create file stream.
45+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
46+
{
47+
//Save the PDF document to file stream.
48+
document.Save(outputFileStream);
49+
}
50+
51+
// Proper document cleanup
52+
document.Close(true);

0 commit comments

Comments
 (0)