Class PdfPageTemplateElement
- Namespace
- Syncfusion.Pdf
- Assembly
- Syncfusion.Pdf.Portable.dll
Describes a page template object that can be used as header/footer, watermark or stamp.
public class PdfPageTemplateElement
- Inheritance
-
PdfPageTemplateElement
- Inherited Members
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)
Remarks
To know more about refer this link .
Constructors
PdfPageTemplateElement(PointF, SizeF)
Creates a new page template.
public PdfPageTemplateElement(PointF location, SizeF size)
Parameters
location
PointFLocation of the template.
size
SizeFSize of the template.
- See Also
PdfPageTemplateElement(PointF, SizeF, PdfPage)
Initializes a new instance of the PdfPageTemplateElement class.
public PdfPageTemplateElement(PointF location, SizeF size, PdfPage page)
Parameters
location
PointFThe location.
size
SizeFThe size.
page
PdfPageThe page.
- See Also
PdfPageTemplateElement(RectangleF)
Initializes a new instance of the PdfPageTemplateElement class with specified Syncfusion.Drawing.RectangleF value.
public PdfPageTemplateElement(RectangleF bounds)
Parameters
bounds
RectangleFBounds 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 Syncfusion.Drawing.RectangleF value and PdfPage .
public PdfPageTemplateElement(RectangleF bounds, PdfPage page)
Parameters
bounds
RectangleFThe bounds.
page
PdfPageThe page.
- See Also
PdfPageTemplateElement(SizeF)
Creates new page template object.
public PdfPageTemplateElement(SizeF size)
Parameters
size
SizeFSize of the template.
- See Also
PdfPageTemplateElement(float, float)
Creates a new page template.
public PdfPageTemplateElement(float width, float height)
Parameters
- See Also
PdfPageTemplateElement(float, float, PdfPage)
Creates a new page template.
public PdfPageTemplateElement(float width, float height, PdfPage page)
Parameters
width
floatWidth of the template.
height
floatHeight of the template.
page
PdfPageThe Current Page object.
- See Also
PdfPageTemplateElement(float, float, float, float)
Creates a new page template.
public PdfPageTemplateElement(float x, float y, float width, float height)
Parameters
x
floatX co-ordinate of the template.
y
floatY co-ordinate of the template.
width
floatWidth of the template.
height
floatHeight 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(float, float, float, float, PdfPage)
Creates a new page template.
public PdfPageTemplateElement(float x, float y, float width, float height, PdfPage page)
Parameters
x
floatX co-ordinate of the template.
y
floatY co-ordinate of the template.
width
floatWidth of the template.
height
floatHeight of the template.
page
PdfPageThe Current Page object.
- See Also
Properties
Alignment
Gets or sets alignment of the page template element.
public PdfAlignmentStyle Alignment { get; set; }
Property Value
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.
public bool Background { get; set; }
Property Value
- See Also
Bounds
Gets or sets bounds of the page template element.
public RectangleF Bounds { get; set; }
Property Value
- RectangleF
- See Also
Dock
Gets or sets the dock style of the page template element.
public PdfDockStyle Dock { get; set; }
Property Value
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.
public bool Foreground { get; set; }
Property Value
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.
public PdfGraphics Graphics { get; }
Property Value
- See Also
Height
Gets or sets height of the page template element.
public float Height { get; set; }
Property Value
- See Also
Location
Gets or sets location of the page template element.
public PointF Location { get; set; }
Property Value
- PointF
- See Also
PdfTag
Gets or sets the tag for the element
public PdfTag PdfTag { get; set; }
Property Value
- See Also
Size
Gets or sets size of the page template element.
public SizeF Size { get; set; }
Property Value
- SizeF
- See Also
Width
Gets or sets width of the page template element.
public float Width { get; set; }
Property Value
- See Also
X
Gets or sets X co-ordinate of the template element on the page.
public float X { get; set; }
Property Value
- See Also
Y
Gets or sets Y co-ordinate of the template element on the page.
public float Y { get; set; }
Property Value
- See Also