Class PdfTemplate
Represents Pdf Template object.
Inherited Members
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfTemplate : PdfShapeElement, IPdfWrapper
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Constructors
PdfTemplate(RectangleF)
Initializes a new instance of the PdfTemplate class.
Declaration
public PdfTemplate(RectangleF rect)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.RectangleF | rect | The rect - represents the rectangle bounds of the PDF template. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new RectangleF(0, 0, 200, 100));
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New RectangleF(0, 0, 200, 100))
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfTemplate(SizeF)
Initializes a new instance of the PdfTemplate class.
Declaration
public PdfTemplate(SizeF size)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.SizeF | size | The size of the PDF template |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfTemplate(Single, Single)
Initializes a new instance of the PdfTemplate class.
Declaration
public PdfTemplate(float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | width | The width of the template. |
System.Single | height | The height of the template. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(200, 100);
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(200, 100)
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
PdfTemplate(Single, Single, Single, Single)
Initializes a new instance of the PdfTemplate class.
Declaration
public PdfTemplate(float x, float y, float width, float height)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The X-coordinate of the template start point. |
System.Single | y | The Y-coordinate of the template start point. |
System.Single | width | The width of the template. |
System.Single | height | The height of the template. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(0, 0, 200, 100);
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(0, 0, 200, 100)
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Properties
Graphics
Gets graphics context of the template.
Declaration
public PdfGraphics Graphics { get; }
Property Value
Type |
---|
PdfGraphics |
Remarks
It will return null, if the template is read-only.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Get the template graphics.
PdfGraphics graphics = template.Graphics;
//Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, new PointF(0,0));
//Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Get the template graphics.
Dim graphics As PdfGraphics = template.Graphics
'Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, New PointF(0, 0))
'Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Height
Gets the height of the template.
Declaration
public float Height { get; }
Property Value
Type |
---|
System.Single |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Get the template graphics.
PdfGraphics graphics = template.Graphics;
//Get the template height.
float height = template.Height;
Console.Write("Template height: " + height);
//Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, new PointF(0,0));
//Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Get the template graphics.
Dim graphics As PdfGraphics = template.Graphics
'Get the template height.
Dim height As Single = template.Height
Console.Write("Template height: " + height)
'Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, New PointF(0, 0))
'Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
ReadOnly
Gets a value indicating whether the template is read-only.
Declaration
public bool ReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Remarks
Read-only templates does not expose graphics. They just return null.
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create PdfTemplate object.
PdfTemplate template = page.CreateTemplate();
//Get read-only
bool readOnlyTemplate = template.ReadOnly;
Console.Write("Read-Only template: " + readOnlyTemplate.ToString());
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create PdfTemplate object.
Dim template As PdfTemplate = page.CreateTemplate()
'Get read-only
Dim readOnlyTemplate As Boolean = template.ReadOnly
Console.Write("Read-Only template: " + readOnlyTemplate.ToString())
'Close the document.
doc.Close(True)
Size
Gets the size of the template.
Declaration
public SizeF Size { get; }
Property Value
Type |
---|
System.Drawing.SizeF |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Get the template graphics.
PdfGraphics graphics = template.Graphics;
//Get the template size.
SizeF templateSize = template.Size;
Console.Write("Template size: " + templateSize.Width + ", " + templateSize.Height);
//Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, new PointF(0,0));
//Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Get the template graphics.
Dim graphics As PdfGraphics = template.Graphics
'Get the template size.
Dim templateSize As SizeF = template.Size
Console.Write("Template size: " + templateSize.Width + ", " + templateSize.Height)
'Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, New PointF(0, 0))
'Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Width
Gets the width of the template.
Declaration
public float Width { get; }
Property Value
Type |
---|
System.Single |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Get the template graphics.
PdfGraphics graphics = template.Graphics;
//Get the template width.
float width = template.Width;
Console.Write("Template width: " + width);
//Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, new PointF(0,0));
//Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 50));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Get the template graphics.
Dim graphics As PdfGraphics = template.Graphics
'Get the template width.
Dim width As Single = template.Width
Console.Write("Template width: " + width)
'Draw the text to the template graphics.
graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, New PointF(0, 0))
'Draw a rectangle on the template graphics
graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 50))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Methods
Reset()
Resets an instance.
Declaration
public void Reset()
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Reset the template.
template.Reset();
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 150));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Reset the template.
template.Reset()
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 150))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)
Reset(SizeF)
Resets the template and sets the specified size.
Declaration
public void Reset(SizeF size)
Parameters
Type | Name | Description |
---|---|---|
System.Drawing.SizeF | size | The size. |
Examples
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create new PDF standard font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Create new PdfTemplate object.
PdfTemplate template = new PdfTemplate(new SizeF(200, 100));
//Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty);
//Reset the template.
template.Reset(new SizeF(300, 200));
//Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, new RectangleF(0, 20, 200, 150));
//Draw the template to PDF page.
template.Draw(page, PointF.Empty);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create new PDF standard font.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
'Create new PdfTemplate object.
Dim template As New PdfTemplate(New SizeF(200, 100))
'Draw the text to the template graphics.
template.Graphics.DrawString("This is PDF template.", font, PdfBrushes.Black, PointF.Empty)
'Reset the template.
template.Reset(New SizeF(300, 200))
'Draw a rectangle on the template graphics
template.Graphics.DrawRectangle(PdfBrushes.BurlyWood, New RectangleF(0, 20, 200, 150))
'Draw the template to PDF page.
template.Draw(page, PointF.Empty)
'Save the document.
doc.Save("Output.pdf")
'Close the document.
doc.Close(True)