Skip to main content

Templates

Version: 8.0

Templates

Templates are used to automatically add Page Elements to all pages in a document or section. This is useful for headers and footers. There are two types of templates, document wide templates and section wide templates. By default, a page will use both the document and section template if they are set. Disabling either template for an individual page can be done with the page's ApplyDocumentTemplate or ApplySectionTemplate property. For information on how to break a document into sections and apply a section template, see the Document Sectioning topic.

DynamicPDF Generator for .NET includes two template classes:

Template : The Template class is used to add Page Element to all pages in the section or document.

Even / Odd Template : The EvenOddTemplate class is used to add different Page Elements to even or odd pages in the section or document.

Document Templates​

Document templates are applied by creating a Template class, adding Page Elements to it, then setting it to the Document's Template property. All page elements within this template will appear in the background of the other contents of the PDF.

Template template = new Template();
template.Elements.Add( new Label( "Header", 0, 0, 200, 12 ) );
document.Template = template;
Dim MyTemplate As Template = New Template()
MyTemplate.Elements.Add( New Label( "Header", 0, 0, 200, 12 ) )
MyDocument.Template = MyTemplate

Even / Odd Templates​

Even / Odd templates are applied by adding separate elements to both Odd and Even pages. All page elements within the Odd template and Even template will appear in the background on Odd pages and Even pages respectively.  

EvenOddTemplate template = new EvenOddTemplate();
template.EvenElements.Add( new Label( "Even Header", 0, 0, 200, 12 ) );
template.OddElements.Add( new Label( "Odd Header", 0, 0, 200, 12 ) );
template.Elements.Add( new Label( "Footer", 0, 680, 200, 12 ) );
document.Template = template;
Dim MyTemplate As EvenOddTemplate = New EvenOddTemplate()
MyTemplate.EvenElements.Add( New Label( "Even Header", 0, 0, 200, 12 ) )
MyTemplate.OddElements.Add( New Label( "Odd Header", 0, 0, 200, 12 ) )
MyTemplate.Elements.Add( New Label( "Footer", 0, 680, 200, 12 ) )
MyDocument.Template = MyTemplate

Stamp Templates​

All page elements within this Template will appear in the foreground of the other contents of the PDF.

Template template = new Template();
template.Elements.Add( new Label( "Header", 0, 0, 200, 12 ) );
document.StampTemplate = template;
Dim MyTemplate As Template = New Template()
MyTemplate.Elements.Add( New Label( "Header", 0, 0, 200, 12 ) )
MyDocument.StampTemplate = MyTemplate