diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF.sln b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF.sln new file mode 100644 index 00000000..9b395286 --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Custom-Headers-and-Footers-in-PDF", "Custom-Headers-and-Footers-in-PDF\Custom-Headers-and-Footers-in-PDF.csproj", "{6A94ADAE-5F1B-42A5-9F82-2CBB511B2F82}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6A94ADAE-5F1B-42A5-9F82-2CBB511B2F82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A94ADAE-5F1B-42A5-9F82-2CBB511B2F82}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A94ADAE-5F1B-42A5-9F82-2CBB511B2F82}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A94ADAE-5F1B-42A5-9F82-2CBB511B2F82}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj new file mode 100644 index 00000000..0453a4ad --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj @@ -0,0 +1,16 @@ + + + + WinExe + net8.0-windows + Custom_Headers_and_Footers_in_PDF + enable + true + enable + + + + + + + \ No newline at end of file diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj.user b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj.user new file mode 100644 index 00000000..7814ea24 --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Custom-Headers-and-Footers-in-PDF.csproj.user @@ -0,0 +1,8 @@ + + + + + Form + + + diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.Designer.cs b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.Designer.cs new file mode 100644 index 00000000..40fcadfa --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.Designer.cs @@ -0,0 +1,63 @@ +using Syncfusion.Pdf.Graphics; +using Syncfusion.Pdf; + +namespace Custom_Headers_and_Footers_in_PDF +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + btnCreate = new Button(); + label = new Label(); + + //Label + label.Location = new System.Drawing.Point(0, 40); + label.Size = new System.Drawing.Size(426, 35); + label.Text = "Click the button to generate PDF document"; + label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + + //Button + btnCreate.Location = new System.Drawing.Point(180, 110); + btnCreate.Size = new System.Drawing.Size(85, 26); + btnCreate.Text = "Create PDF"; + btnCreate.Click += new EventHandler(btnCreate_Click); + + //Create PDF + ClientSize = new System.Drawing.Size(450, 150); + Controls.Add(label); + Controls.Add(btnCreate); + Text = "Create PDF"; + } + private Button btnCreate; + private Label label; + + #endregion + } +} diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.cs b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.cs new file mode 100644 index 00000000..e87d6745 --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.cs @@ -0,0 +1,71 @@ +using Syncfusion.Pdf; +using Syncfusion.Pdf.Graphics; + +namespace Custom_Headers_and_Footers_in_PDF +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void btnCreate_Click(object sender, EventArgs e) + { + // Create a new PDF document + PdfDocument document = new PdfDocument(); + + // Paragraph content to display on each page + string paragraph = @"The page tree serves as the root of the document. In the simplest case, it is just a list of the pages in the document. Each page is defined as an independent entity with metadata (e.g., page dimensions) and a reference to its resources and content, which are defined separately. Together, the page tree and page objects create the “paper” that composes the document. +Resources are objects that are required to render a page. For example, a single font is typically used across several pages, so storing the font information in an external resource is much more efficient. A content object defines the text and graphics that actually show up on the page. Together, content objects and resources define the appearance of an individual page. +Finally, the document’s catalog tells applications where to start reading the document. Often, this is just a pointer to the root page tree."; + + // ===== Section 1 ===== + AddSectionWithHeaderFooter(document, "Header - Section 1", "Footer - Section 1", 1, paragraph); + + // ===== Section 2 ===== + AddSectionWithHeaderFooter(document, "Header - Section 2", "Footer - Section 2", 1, paragraph); + + // Save and close the document + document.Save("Output.pdf"); + // Close and dispose of the PDF document + document.Close(true); + } + + // Adds a specified number of pages to the document, each with a unique header, footer, and paragraph content. + static void AddSectionWithHeaderFooter(PdfDocument document, string headerText, string footerText, int numberOfPages, string pageContent) + { + // Define fonts and brush + PdfFont headerFooterFont = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold); + PdfFont bodyFont = new PdfStandardFont(PdfFontFamily.Helvetica, 11); + PdfBrush brush = PdfBrushes.Black; + + for (int i = 0; i < numberOfPages; i++) + { + // Add a new page + PdfPage page = document.Pages.Add(); + + // Draw Header + page.Graphics.DrawString(headerText, headerFooterFont, brush, new PointF(10, 10)); + + // Draw Footer + float footerY = page.GetClientSize().Height - 20; + page.Graphics.DrawString(footerText, headerFooterFont, brush, new PointF(10, footerY)); + + // Draw the paragraph content using PdfTextElement for proper layout and wrapping + RectangleF contentBounds = new RectangleF(20, 40, page.GetClientSize().Width - 40, page.GetClientSize().Height - 80); + PdfTextElement textElement = new PdfTextElement(pageContent, bodyFont, brush) + { + StringFormat = new PdfStringFormat() + { + Alignment = PdfTextAlignment.Left, + LineSpacing = 5f + } + }; + // Draw the paragraph text within the defined rectangle area on the page + textElement.Draw(page, contentBounds); + } + } + + } +} diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.resx b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Program.cs b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Program.cs new file mode 100644 index 00000000..a58a7659 --- /dev/null +++ b/Header and Footer/Custom-Headers-and-Footers-in-PDF/.NET Framework/Custom-Headers-and-Footers-in-PDF/Program.cs @@ -0,0 +1,17 @@ +namespace Custom_Headers_and_Footers_in_PDF +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file