Class PdfFont
Defines a particular format for text, including font face, size, and style attributes.
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public abstract class PdfFont : Object, IPdfWrapper, IPdfCache
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Constructors
PdfFont(Single)
Initializes a new instance of the PdfFont class.
Declaration
protected PdfFont(float size)
Parameters
Type | Name | Description |
---|---|---|
System.Single | size | The size. |
PdfFont(Single, PdfFontStyle)
Initializes a new instance of the PdfFont class.
Declaration
protected PdfFont(float size, PdfFontStyle style)
Parameters
Type | Name | Description |
---|---|---|
System.Single | size | The size. |
PdfFontStyle | style | The style. |
Fields
s_syncObject
Synchronization object.
Declaration
protected static object s_syncObject
Field Value
Type |
---|
System.Object |
Properties
Bold
Gets a value indicating whether this PdfFont is bold.
Declaration
public bool Bold { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
builder.AppendLine("Bold: " + font.Bold.ToString());
builder.AppendLine("Italic: " + font.Italic.ToString());
builder.AppendLine("Underline: " + font.Underline.ToString());
builder.AppendLine("Strikeout: " + font.Strikeout.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
builder.AppendLine("Bold: " + font.Bold.ToString())
builder.AppendLine("Italic: " + font.Italic.ToString())
builder.AppendLine("Underline: " + font.Underline.ToString())
builder.AppendLine("Strikeout: " + font.Strikeout.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Height
Gets the height of the font in points.
Declaration
public float Height { get; }
Property Value
Type |
---|
System.Single |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Italic
Gets a value indicating whether this PdfFont has the italic style applied.
Declaration
public bool Italic { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
builder.AppendLine("Bold: " + font.Bold.ToString());
builder.AppendLine("Italic: " + font.Italic.ToString());
builder.AppendLine("Underline: " + font.Underline.ToString());
builder.AppendLine("Strikeout: " + font.Strikeout.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
builder.AppendLine("Bold: " + font.Bold.ToString())
builder.AppendLine("Italic: " + font.Italic.ToString())
builder.AppendLine("Underline: " + font.Underline.ToString())
builder.AppendLine("Strikeout: " + font.Strikeout.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Name
Gets the face name of this Font.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String | A string representation of the face name of this PdfFont. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Size
Gets the size of this font.
Declaration
public float Size { get; }
Property Value
Type | Description |
---|---|
System.Single | The em-size of this Font. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Strikeout
Gets a value indicating whether this PdfFont is strikeout.
Declaration
public bool Strikeout { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
builder.AppendLine("Bold: " + font.Bold.ToString());
builder.AppendLine("Italic: " + font.Italic.ToString());
builder.AppendLine("Underline: " + font.Underline.ToString());
builder.AppendLine("Strikeout: " + font.Strikeout.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
builder.AppendLine("Bold: " + font.Bold.ToString())
builder.AppendLine("Italic: " + font.Italic.ToString())
builder.AppendLine("Underline: " + font.Underline.ToString())
builder.AppendLine("Strikeout: " + font.Strikeout.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Style
Gets the style information for this font.
Declaration
public PdfFontStyle Style { get; }
Property Value
Type |
---|
PdfFontStyle |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Underline
Gets a value indicating whether this PdfFont is underline.
Declaration
public bool Underline { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
//Get font Name.
string fontName = font.Name;
//Get font size.
float fontSize = font.Size;
//Get font height.
float fontHeight = font.Height;
//Get the font style.
PdfFontStyle style = font.Style;
StringBuilder builder = new StringBuilder();
builder.AppendLine("Font Name: " + fontName);
builder.AppendLine("Font Size: " + fontSize);
builder.AppendLine("Font Height: " + FontHeight);
builder.AppendLine("Font Style: " + style.ToString());
builder.AppendLine("Bold: " + font.Bold.ToString());
builder.AppendLine("Italic: " + font.Italic.ToString());
builder.AppendLine("Underline: " + font.Underline.ToString());
builder.AppendLine("Strikeout: " + font.Strikeout.ToString());
//Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
'Get font Name.
Dim fontName As String = font.Name
'Get font size.
Dim fontSize As Single = font.Size
'Get font height.
Dim fontHeight As Single = font.Height
'Get the font style.
Dim style As PdfFontStyle = font.Style
Dim builder As New StringBuilder()
builder.AppendLine("Font Name: " + fontName)
builder.AppendLine("Font Size: " + fontSize)
builder.AppendLine("Font Height: " + fontHeight)
builder.AppendLine("Font Style: " + style.ToString())
builder.AppendLine("Bold: " + font.Bold.ToString())
builder.AppendLine("Italic: " + font.Italic.ToString())
builder.AppendLine("Underline: " + font.Underline.ToString())
builder.AppendLine("Strikeout: " + font.Strikeout.ToString())
'Draw string to PDF page.
graphics.DrawString(builder.ToString(), font, PdfBrushes.Black, PointF.Empty)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
Methods
ApplyFormatSettings(String, PdfStringFormat, Single)
Applies settings to the default line width.
Declaration
protected float ApplyFormatSettings(string line, PdfStringFormat format, float width)
Parameters
Type | Name | Description |
---|---|---|
System.String | line | Text line. |
PdfStringFormat | format | String format. |
System.Single | width | Default line width. |
Returns
Type | Description |
---|---|
System.Single | Line width with settings applied. |
EqualsToFont(PdfFont)
Checks whether fonts are equals.
Declaration
protected abstract bool EqualsToFont(PdfFont font)
Parameters
Type | Name | Description |
---|---|---|
PdfFont | font | Font to compare. |
Returns
Type | Description |
---|---|
System.Boolean | True if fonts are equal, False otherwise. |
GetCharWidth(Char, PdfStringFormat)
Returns width of the char.
Declaration
protected abstract float GetCharWidth(char charCode, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Char | charCode | Char symbol. |
PdfStringFormat | format | String format. |
Returns
Type | Description |
---|---|
System.Single | Width of the symbol. |
GetLineWidth(String, PdfStringFormat)
Returns width of the line.
Declaration
protected abstract float GetLineWidth(string line, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.String | line | Text line. |
PdfStringFormat | format | String format. |
Returns
Type | Description |
---|---|
System.Single | Width of the line. |
MeasureString(String)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size));
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size))
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, PdfStringFormat)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text, format);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text, format)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, PdfStringFormat, out Int32, out Int32)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, PdfStringFormat format, out int charactersFitted, out int linesFilled)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
System.Int32 | charactersFitted | Number of characters in the string. |
System.Int32 | linesFilled | Number of text lines in the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
int charactersFilled, linesFilled;
//Measure the text.
SizeF size = font.MeasureString(text, format , out charactersFilled, linesFilled);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
Dim charactersFilled As Integer, linesFilled As Integer
'Measure the text.
Dim size As SizeF = font.MeasureString(text, format, charactersFilled, linesFilled)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, SizeF)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, SizeF layoutArea)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Drawing.SizeF | layoutArea | SizeF structure that specifies the maximum layout area for the text in points. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text, new SizeF(100,100));
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text, New SizeF(100,100))
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, SizeF, PdfStringFormat)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, SizeF layoutArea, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Drawing.SizeF | layoutArea | SizeF structure that specifies the maximum layout area for the text in points. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text, new SizeF(100,100) , format);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text, New SizeF(100,100), format)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, SizeF, PdfStringFormat, out Int32, out Int32)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, SizeF layoutArea, PdfStringFormat format, out int charactersFitted, out int linesFilled)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Drawing.SizeF | layoutArea | SizeF structure that specifies the maximum layout area for the text in points. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
System.Int32 | charactersFitted | Number of characters in the string. |
System.Int32 | linesFilled | Number of text lines in the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
int charactersFilled, linesFilled;
//Measure the text.
SizeF size = font.MeasureString(text, new SizeF(100, 100), format , out charactersFilled, linesFilled);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
Dim charactersFilled As Integer, linesFilled As Integer
'Measure the text.
Dim size As SizeF = font.MeasureString(text, New SizeF(100,100), format, charactersFilled, linesFilled)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, Single)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, float width)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Single | width | Maximum width of the string in points. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text, 100);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text, 100)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, Single, PdfStringFormat)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, float width, PdfStringFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Single | width | Maximum width of the string in points. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
//Measure the text.
SizeF size = font.MeasureString(text, 100, format);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
'Measure the text.
Dim size As SizeF = font.MeasureString(text, 100, format)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
MeasureString(String, Single, PdfStringFormat, out Int32, out Int32)
Measures a string by using this font.
Declaration
public SizeF MeasureString(string text, float width, PdfStringFormat format, out int charactersFitted, out int linesFilled)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to measure. |
System.Single | width | Maximum width of the string in points. |
PdfStringFormat | format | PdfStringFormat that represents formatting information, such as line spacing, for the string. |
System.Int32 | charactersFitted | Number of characters in the string. |
System.Int32 | linesFilled | Number of text lines in the string. |
Returns
Type | Description |
---|---|
System.Drawing.SizeF | Size of the text. |
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a page to the document.
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Create a new PDF font instance.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
PdfStringFormat format = new Syncfusion.Pdf.Graphics.PdfStringFormat();
format.Alignment = PdfTextAlignment.Center;
format.LineAlignment = PdfVerticalAlignment.Middle;
string text = "Hello World!";
int charactersFilled, linesFilled;
//Measure the text.
SizeF size = font.MeasureString(text, format, 100, out charactersFilled, linesFilled);
//Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(PointF.Empty, size), format);
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new PDF document.
Dim document As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = document.Pages.Add()
'Create PDF graphics for the page.
Dim graphics As PdfGraphics = page.Graphics
'Create a new PDF font instance.
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
Dim format As PdfStringFormat = New Syncfusion.Pdf.Graphics.PdfStringFormat()
format.Alignment = PdfTextAlignment.Center
format.LineAlignment = PdfVerticalAlignment.Middle
Dim text As String = "Hello World!"
Dim charactersFilled As Integer, linesFilled As Integer
'Measure the text.
Dim size As SizeF = font.MeasureString(text, 100, format, charactersFilled, linesFilled)
'Draw string to PDF page.
graphics.DrawString(text, font, PdfBrushes.Black, New RectangleF(PointF.Empty, size), format)
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
SetStyle(PdfFontStyle)
Sets the style.
Declaration
protected void SetStyle(PdfFontStyle style)
Parameters
Type | Name | Description |
---|---|---|
PdfFontStyle | style | The style. |