Class PdfPageTemplateElement
Describes a page template object that can be used as header/footer, watermark or stamp.
Inheritance
Namespace: Syncfusion.Pdf
Assembly: Syncfusion.Pdf.Portable.dll
Syntax
public class PdfPageTemplateElement : Object
Remarks
To know more about refer this link .
Examples
//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
//Add a page to the PDF document.
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create a header and draw the image.
RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
PdfPageTemplateElement header = new PdfPageTemplateElement(bounds);
PdfImage image = new PdfBitmap(@"Logo.png");
//Draw the image in the header.
header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50));
//Add the header at the top.
pdfDocument.Template.Top = header;
//Create a Page template that can be used as footer.
PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
//Create new instance for PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
//Create new brush for PDF brush.
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(font, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);
compositeField.Bounds = footer.Bounds;
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new PointF(470, 40));
//Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer;
//Save and close the document.
pdfDocument.Save("Output.pdf");
pdfDocument.Close(true);
'Create new document.
Dim pdfDocument As PdfDocument = New PdfDocument()
'Add a page to the PDF document.
Dim pdfPage As PdfPage = pdfDocument.Pages.Add()
'Create a header and draw the image.
Dim header As PdfPageTemplateElement = New PdfPageTemplateElement(0, 0, pdfDocument.Pages(0).GetClientSize().Width, 50)
Dim image As PdfImage = New PdfBitmap("in.png")
'Draw the image in the header.
header.Graphics.DrawImage(image, New PointF(0, 0), New SizeF(100, 50))
'Add the header at the top.
pdfDocument.Template.Top = header
Dim footer As PdfPageTemplateElement = New PdfPageTemplateElement(0, 0, pdfDocument.Pages(0).GetClientSize().Width, 50)
'Create new instance for PDF font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 7)
'Create new instance for PDF brush.
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
'Create page number field.
Dim pageNumber As PdfPageNumberField = New PdfPageNumberField(font, brush)
'Create page count field.
Dim count As PdfPageCountField = New PdfPageCountField(font, brush)
'Add the fields in composite fields.
Dim compositeField As PdfCompositeField = New PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count)
compositeField.Bounds = footer.Bounds
'Draw the composite field in footer.
compositeField.Draw(footer.Graphics, New PointF(470, 40))
'Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer
'Save and close the document.
pdfDocument.Save("Output.pdf")
pdfDocument.Close(True)
Constructors
PdfPageTemplateElement(PointF, SizeF)
Creates a new page template.
Declaration
public PdfPageTemplateElement(PointF location, SizeF size)
Parameters
Type | Name | Description |
---|---|---|
PointF | location | Location of the template. |
SizeF | size | Size of the template. |
PdfPageTemplateElement(PointF, SizeF, PdfPage)
Initializes a new instance of the PdfPageTemplateElement class.
Declaration
public PdfPageTemplateElement(PointF location, SizeF size, PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
PointF | location | The location. |
SizeF | size | The size. |
PdfPage | page | The page. |
PdfPageTemplateElement(RectangleF)
Initializes a new instance of the PdfPageTemplateElement class with specified RectangleF value.
Declaration
public PdfPageTemplateElement(RectangleF bounds)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | bounds | Bounds of the template. |
Examples
//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
//Add a page to the PDF document.
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create a header and draw the image.
RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
PdfPageTemplateElement header = new PdfPageTemplateElement(bounds);
PdfImage image = new PdfBitmap(@"Logo.png");
//Draw the image in the header.
header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50));
//Add the header at the top.
pdfDocument.Template.Top = header;
//Create a Page template that can be used as footer.
PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
//Create new instance for PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
//Create new brush for PDF brush.
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(font, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);
compositeField.Bounds = footer.Bounds;
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new PointF(470, 40));
//Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer;
//Save and close the document.
pdfDocument.Save("Output.pdf");
pdfDocument.Close(true);
'Create new document.
Dim pdfDocument As PdfDocument = New PdfDocument()
'Add a page to the PDF document.
Dim pdfPage As PdfPage = pdfDocument.Pages.Add()
Dim bounds As RectangleF = New RectangleF(0, 0, pdfDocument.Pages(0).GetClientSize().Width, 50)
'Create a header and draw the image.
Dim header As PdfPageTemplateElement = New PdfPageTemplateElement(bounds)
Dim image As PdfImage = New PdfBitmap("in.png")
'Draw the image in the header.
header.Graphics.DrawImage(image, New PointF(0, 0), New SizeF(100, 50))
'Add the header at the top.
pdfDocument.Template.Top = header
Dim footer As PdfPageTemplateElement = New PdfPageTemplateElement(bounds)
'Create new instance for PDF font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 7)
'Create new instance for PDF brush.
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
'Create page number field.
Dim pageNumber As PdfPageNumberField = New PdfPageNumberField(font, brush)
'Create page count field.
Dim count As PdfPageCountField = New PdfPageCountField(font, brush)
'Add the fields in composite fields.
Dim compositeField As PdfCompositeField = New PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count)
compositeField.Bounds = footer.Bounds
'Draw the composite field in footer.
compositeField.Draw(footer.Graphics, New PointF(470, 40))
'Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer
'Save and close the document.
pdfDocument.Save("Output.pdf")
pdfDocument.Close(True)
See Also
PdfPageTemplateElement(RectangleF, PdfPage)
Initializes a new instance of the PdfPageTemplateElement class with specified RectangleF value and PdfPage .
Declaration
public PdfPageTemplateElement(RectangleF bounds, PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
RectangleF | bounds | The bounds. |
PdfPage | page | The page. |
PdfPageTemplateElement(SizeF)
Creates new page template object.
Declaration
public PdfPageTemplateElement(SizeF size)
Parameters
Type | Name | Description |
---|---|---|
SizeF | size | Size of the template. |
PdfPageTemplateElement(Single, Single)
Creates a new page template.
Declaration
public PdfPageTemplateElement(float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | Width of the template. |
System.Single | height | Height of the template. |
PdfPageTemplateElement(Single, Single, PdfPage)
Creates a new page template.
Declaration
public PdfPageTemplateElement(float width, float height, PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | Width of the template. |
System.Single | height | Height of the template. |
PdfPage | page | The Current Page object. |
PdfPageTemplateElement(Single, Single, Single, Single)
Creates a new page template.
Declaration
public PdfPageTemplateElement(float x, float y, float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | X co-ordinate of the template. |
System.Single | y | Y co-ordinate of the template. |
System.Single | width | Width of the template. |
System.Single | height | Height of the template. |
Examples
//Create a new PDF document.
PdfDocument pdfDocument = new PdfDocument();
//Add a page to the PDF document.
PdfPage pdfPage = pdfDocument.Pages.Add();
//Create a header and draw the image.
PdfPageTemplateElement header = new PdfPageTemplateElement(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
PdfImage image = new PdfBitmap(@"Logo.png");
//Draw the image in the header.
header.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(100, 50));
//Add the header at the top.
pdfDocument.Template.Top = header;
//Create a Page template that can be used as footer.
PdfPageTemplateElement footer = new PdfPageTemplateElement(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);
//Create new instance for PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7);
//Create new brush for PDF brush.
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(font, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count);
compositeField.Bounds = footer.Bounds;
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new PointF(470, 40));
//Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer;
//Save and close the document.
pdfDocument.Save("Output.pdf");
pdfDocument.Close(true);
'Create new document.
Dim pdfDocument As PdfDocument = New PdfDocument()
'Add a page to the PDF document.
Dim pdfPage As PdfPage = pdfDocument.Pages.Add()
'Create a header and draw the image.
Dim header As PdfPageTemplateElement = New PdfPageTemplateElement(0, 0, pdfDocument.Pages(0).GetClientSize().Width, 50)
Dim image As PdfImage = New PdfBitmap("in.png")
'Draw the image in the header.
header.Graphics.DrawImage(image, New PointF(0, 0), New SizeF(100, 50))
'Add the header at the top.
pdfDocument.Template.Top = header
Dim footer As PdfPageTemplateElement = New PdfPageTemplateElement(0, 0, pdfDocument.Pages(0).GetClientSize().Width, 50)
'Create new instance for PDF font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 7)
'Create new instance for PDF brush.
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
'Create page number field.
Dim pageNumber As PdfPageNumberField = New PdfPageNumberField(font, brush)
'Create page count field.
Dim count As PdfPageCountField = New PdfPageCountField(font, brush)
'Add the fields in composite fields.
Dim compositeField As PdfCompositeField = New PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count)
compositeField.Bounds = footer.Bounds
'Draw the composite field in footer.
compositeField.Draw(footer.Graphics, New PointF(470, 40))
'Add the footer template at the bottom.
pdfDocument.Template.Bottom = footer
'Save and close the document.
pdfDocument.Save("Output.pdf")
pdfDocument.Close(True)
See Also
PdfPageTemplateElement(Single, Single, Single, Single, PdfPage)
Creates a new page template.
Declaration
public PdfPageTemplateElement(float x, float y, float width, float height, PdfPage page)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | X co-ordinate of the template. |
System.Single | y | Y co-ordinate of the template. |
System.Single | width | Width of the template. |
System.Single | height | Height of the template. |
PdfPage | page | The Current Page object. |
Properties
Alignment
Gets or sets alignment of the page template element.
Declaration
public PdfAlignmentStyle Alignment { get; set; }
Property Value
Type |
---|
PdfAlignmentStyle |
Examples
//Create new document.
PdfDocument document = new PdfDocument();
//Set margin for document.
document.PageSettings.SetMargins(25f);
//Add new page.
PdfPage page = document.Pages.Add();
RectangleF rect = new RectangleF(0, 0, 100, 100);
//Create new instance of PDF solid brush.
PdfSolidBrush brush = new PdfSolidBrush(Color.LightBlue);
//Create new instance of PDF pen.
PdfPen pen = new PdfPen(Color.Orange, 3f);
//Create new instance for PDF page template element.
PdfPageTemplateElement custom = new PdfPageTemplateElement(rect);
document.Template.Stamps.Add(custom);
//Set alignment style
custom.Alignment = PdfAlignmentStyle.TopCenter;
//Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect);
//Save and close the document.
document.Save("Output.pdf");
document.Close(true);
'Create new document.
Dim document As PdfDocument = New PdfDocument()
'Set margin for document.
document.PageSettings.SetMargins(25.0F)
'Add new page.
Dim page As PdfPage = document.Pages.Add()
Dim rect As RectangleF = New RectangleF(0, 0, 100, 100)
'Create new instance of PDF solid brush.
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.LightBlue)
'Create new instance of PDF pen.
Dim pen As PdfPen = New PdfPen(Color.Orange, 3.0F)
'Create new instance for PDF page template element.
Dim custom As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
document.Template.Stamps.Add(custom)
'Set alignment style
custom.Alignment = PdfAlignmentStyle.TopCenter
'Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect)
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Background
Indicates whether the page template is located behind of the page layers or in front of it.
Declaration
public bool Background { get; set; }
Property Value
Type |
---|
System.Boolean |
Bounds
Gets or sets bounds of the page template element.
Declaration
public RectangleF Bounds { get; set; }
Property Value
Type |
---|
RectangleF |
Dock
Gets or sets the dock style of the page template element.
Declaration
public PdfDockStyle Dock { get; set; }
Property Value
Type |
---|
PdfDockStyle |
Examples
//Create new document.
PdfDocument document = new PdfDocument();
//Set margin for document.
document.PageSettings.SetMargins(25f);
//Add new page.
PdfPage page = document.Pages.Add();
RectangleF rect = new RectangleF(0, 0, 100, 100);
//Create new instance of PDF solid brush.
PdfSolidBrush brush = new PdfSolidBrush(Color.LightBlue);
//Create new instance of PDF pen.
PdfPen pen = new PdfPen(Color.Orange, 3f);
//Create new instance for PDF page template element.
PdfPageTemplateElement custom = new PdfPageTemplateElement(rect);
document.Template.Stamps.Add(custom);
//Set dock style
custom.Dock = PdfDockStyle.Right;
//Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect);
//Save and close the document.
document.Save("Output.pdf");
document.Close(true);
'Create new document.
Dim document As PdfDocument = New PdfDocument()
'Set margin for document.
document.PageSettings.SetMargins(25.0F)
'Add new page.
Dim page As PdfPage = document.Pages.Add()
Dim rect As RectangleF = New RectangleF(0, 0, 100, 100)
'Create new instance of PDF solid brush.
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.LightBlue)
'Create new instance of PDF pen.
Dim pen As PdfPen = New PdfPen(Color.Orange, 3.0F)
'Create new instance for PDF page template element.
Dim custom As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
document.Template.Stamps.Add(custom)
'Set dock style
custom.Dock = PdfDockStyle.Right
'Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect)
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Foreground
Indicates whether the page template is located in front of the page layers or behind of it. If false, the page template will be located behind of page layer.
Declaration
public bool Foreground { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
//Create new document.
PdfDocument document = new PdfDocument();
//Set margin for document.
document.PageSettings.SetMargins(25f);
//Add new page.
PdfPage page = document.Pages.Add();
RectangleF rect = new RectangleF(0, 0, 100, 100);
//Create new instance of PDF solid brush.
PdfSolidBrush brush = new PdfSolidBrush(Color.LightBlue);
//Create new instance of PDF pen.
PdfPen pen = new PdfPen(Color.Orange, 3f);
//Create new instance for PDF page template element.
PdfPageTemplateElement custom = new PdfPageTemplateElement(rect);
document.Template.Stamps.Add(custom);
//Set alignment style
custom.Dock = PdfDockStyle.Left;
//Set foreground
custom.Foreground = false;
//Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect);
//Save and close the document.
document.Save("Output.pdf");
document.Close(true);
'Create new document.
Dim document As PdfDocument = New PdfDocument()
'Set margin for document.
document.PageSettings.SetMargins(25.0F)
'Add new page.
Dim page As PdfPage = document.Pages.Add()
Dim rect As RectangleF = New RectangleF(0, 0, 100, 100)
'Create new instance of PDF solid brush.
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.LightBlue)
'Create new instance of PDF pen.
Dim pen As PdfPen = New PdfPen(Color.Orange, 3.0F)
'Create new instance for PDF page template element.
Dim custom As PdfPageTemplateElement = New PdfPageTemplateElement(rect)
document.Template.Stamps.Add(custom)
'Set dock style
custom.Dock = PdfDockStyle.Left
'Set foreground
custom.Foreground = True
'Draw template into pdf page.
custom.Graphics.DrawRectangle(pen, brush, rect)
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Graphics
Gets graphics context of the page template element.
Declaration
public PdfGraphics Graphics { get; }
Property Value
Type |
---|
PdfGraphics |
Height
Gets or sets height of the page template element.
Declaration
public float Height { get; set; }
Property Value
Type |
---|
System.Single |
Location
Gets or sets location of the page template element.
Declaration
public PointF Location { get; set; }
Property Value
Type |
---|
PointF |
PdfTag
Gets or sets the tag for the element
Declaration
public PdfTag PdfTag { get; set; }
Property Value
Type |
---|
PdfTag |
Size
Gets or sets size of the page template element.
Declaration
public SizeF Size { get; set; }
Property Value
Type |
---|
SizeF |
Width
Gets or sets width of the page template element.
Declaration
public float Width { get; set; }
Property Value
Type |
---|
System.Single |
X
Gets or sets X co-ordinate of the template element on the page.
Declaration
public float X { get; set; }
Property Value
Type |
---|
System.Single |
Y
Gets or sets Y co-ordinate of the template element on the page.
Declaration
public float Y { get; set; }
Property Value
Type |
---|
System.Single |