Skip to content

Commit 088fa3f

Browse files
Merge pull request #223 from SyncfusionExamples/994136-1
994136-1: Resolved playground issue.
2 parents 06d309d + 6c5277b commit 088fa3f

File tree

1 file changed

+25
-30
lines changed
  • Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF

1 file changed

+25
-30
lines changed

Header and Footer/Adding-dynamic-headers-and-footers-in-PDF/.NET/Adding-dynamic-headers-and-footers-in-PDF/Program.cs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
using Syncfusion.Pdf;
33
using Syncfusion.Pdf.Graphics;
44

5-
class Program
6-
{
7-
static void Main(string[] args)
8-
{
9-
//Create a new PDF document.
5+
//Create a new PDF document.
106
using (PdfDocument document = new PdfDocument())
117
{
128
// Subscribe to the PageAdded event to add header and footer for every page.
@@ -72,29 +68,28 @@ static void Main(string[] args)
7268
document.Save(Path.GetFullPath(@"Output/Output.pdf"));
7369
}
7470

75-
// Add header and footer to every page.
76-
static void PageAddedHandler(object sender, PageAddedEventArgs e)
77-
{
78-
PdfPage page = e.Page;
79-
int currentPage = page.Section.Pages.IndexOf(page) + 1;
80-
81-
// Draw header at the top (within reserved header bounds).
82-
string headerText = $"This is the header - Page {currentPage}";
83-
page.Graphics.DrawString(
84-
headerText,
85-
new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold),
86-
new PdfSolidBrush(Color.DimGray),
87-
new PointF(10, 10) // Within header area
88-
);
89-
90-
// Draw footer at the bottom (within reserved footer area).
91-
string timestamp = DateTime.Now.ToString("'Date:' yyyy-MM-dd 'Time:' HH:mm:ss");
92-
string footerText = $"Page {currentPage} {timestamp}";
93-
page.Graphics.DrawString(
94-
footerText,
95-
new PdfStandardFont(PdfFontFamily.Helvetica, 12),
96-
new PdfSolidBrush(Color.Black),
97-
new PointF(10, page.GetClientSize().Height - 30)
98-
);
99-
}
71+
// Add header and footer to every page.
72+
static void PageAddedHandler(object sender, PageAddedEventArgs e)
73+
{
74+
PdfPage page = e.Page;
75+
int currentPage = page.Section.Pages.IndexOf(page) + 1;
76+
77+
// Draw header at the top (within reserved header bounds).
78+
string headerText = $"This is the header - Page {currentPage}";
79+
page.Graphics.DrawString(
80+
headerText,
81+
new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold),
82+
new PdfSolidBrush(Color.DimGray),
83+
new PointF(10, 10) // Within header area
84+
);
85+
86+
// Draw footer at the bottom (within reserved footer area).
87+
string timestamp = DateTime.Now.ToString("'Date:' yyyy-MM-dd 'Time:' HH:mm:ss");
88+
string footerText = $"Page {currentPage} {timestamp}";
89+
page.Graphics.DrawString(
90+
footerText,
91+
new PdfStandardFont(PdfFontFamily.Helvetica, 12),
92+
new PdfSolidBrush(Color.Black),
93+
new PointF(10, page.GetClientSize().Height - 30)
94+
);
10095
}

0 commit comments

Comments
 (0)