Adding Templates to PDFs
Adding a template to add page elements to all pages at once in a PDF document or section is a breeze when using DynamicPDF Core Suite for .NET. The following C# examples illustrate.
How to Add Template to PDF
The following steps and C# sample code illustrate adding a Template
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding Template to a PDF Document
- Create a
Document
object. - Create a
Template
object. - Add the required page elements to the
Template
instance. - Assign the
Template
instance to theDocument
instance. - Add the
Draw
method to output the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Template template = new Template();
template.Elements.Add(new Label("Header", 0, 0, 200, 12));
template.Elements.Add(new Image("DPDFLogo.png"), 100, 0));
document.Template = template;
document.Draw("Output.pdf");
How to Add EvenOddTemplate to PDF
The following steps and C# sample code illustrate adding an EvenOddTemplate to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding EvenOddTemplate to a PDF Document
- Create a
Document
object. - Create a
EvenOddTemplate
object. - Add the required page elements to the
EvenOddTemplate
instance. - Assign the
EvenOddTemplate
instance to theDocument
instance. - Add the
Draw
method to output the PDF document.
Sample Code - C#
Document myDoc = new();
myDoc.Pages.Add(new Page());
myDoc.Pages.Add(new Page());
myDoc.Pages.Add(new Page());
EvenOddTemplate tmp = new EvenOddTemplate();
tmp.EvenElements.Add(new Label("ODD", 0, 0, 200, 12));
tmp.OddElements.Add(new Label("EVEN", 0, 0, 200, 12));
myDoc.Template = tmp;
myDoc.Draw("Output.pdf");
How to Add HeaderFooterTemplate to PDF
The following steps and C# sample code illustrate adding an HeaderFooterTemplate to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding HeaderFooterTemplate to a PDF Document
- Create a
Document
object. - Create a
HeaderFooterTemplate
object. - Add the required page elements to the
HeaderFooterTemplate
instance. - Assign the
HeaerFooterTemplate
instance to theDocument
instance. - Add the
Draw
method to output the PDF document.
Sample Code - C#
Document myDoc = new();
myDoc.Pages.Add(new Page());
HeaderFooterTemplate header = new HeaderFooterTemplate("Header text", "Footer text");
HeaderFooterText leftText = new HeaderFooterText("Example Header");
header.HeaderLeft = leftText;
myDoc.Template = header;
header.FooterLeft = header.FooterCenter;
myDoc.Draw("output.pdf");
GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - TemplateExample.cs
- VB.NET - TemplateExample.vb
- C# - EvenOddTemplateExample.cs
- VB.NET - EvenOddTemplateExample.vb
- C# - HeaderFooterTemplateExample.cs
- VB.NET - HeaderFooterTemplateExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Templates
- Refer to the Adding Templates documentation topic, or
- Chapter 3, Templates and Sections, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX