Class PdfTemplate
- Namespace
- Syncfusion.Pdf.Graphics
- Assembly
- Syncfusion.Pdf.Portable.dll
Represents Pdf Template object.
public class PdfTemplate : PdfShapeElement
- Inheritance
-
PdfTemplate
- Inherited Members
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.
public PdfTemplate(RectangleF rect)
Parameters
rectRectangleFThe 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.
public PdfTemplate(SizeF size)
Parameters
sizeSizeFThe 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(float, float)
Initializes a new instance of the PdfTemplate class.
public PdfTemplate(float width, float height)
Parameters
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(float, float, float, float)
Initializes a new instance of the PdfTemplate class.
public PdfTemplate(float x, float y, float width, float height)
Parameters
xfloatThe X-coordinate of the template start point.
yfloatThe Y-coordinate of the template start point.
widthfloatThe width of the template.
heightfloatThe 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.
public PdfGraphics Graphics { get; }
Property Value
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)
Remarks
It will return null, if the template is read-only.
Height
Gets the height of the template.
public float Height { get; }
Property Value
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.
public bool ReadOnly { get; }
Property Value
- bool
trueif the template is read-only; otherwise,false.
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)
Remarks
Read-only templates does not expose graphics. They just return null.
Size
Gets the size of the template.
public SizeF Size { get; }
Property Value
- 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.
public float Width { get; }
Property Value
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
DrawInternal(PdfGraphics)
Draws an element on the Graphics.
protected override void DrawInternal(PdfGraphics graphics)
Parameters
graphicsPdfGraphicsGraphics context where the element should be printed.
GetBoundsInternal()
Returns a rectangle that bounds this element.
protected override RectangleF GetBoundsInternal()
Returns
- RectangleF
Returns a rectangle that bounds this element.
Remarks
This method doesn't take into consideration a rotation of the element.
Reset()
Resets an instance.
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.
public void Reset(SizeF size)
Parameters
sizeSizeFThe 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)