Table of Contents

Class PdfStringFormat

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

Represents the text layout information on PDF

public sealed class PdfStringFormat : ICloneable
Inheritance
PdfStringFormat
Implements
Inherited Members

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Constructors

PdfStringFormat()

Initializes a new instance of the PdfStringFormat class.

public PdfStringFormat()

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

PdfStringFormat(PdfTextAlignment)

Initializes a new instance of the PdfStringFormat class with horizontal alignment of a text

public PdfStringFormat(PdfTextAlignment alignment)

Parameters

alignment PdfTextAlignment

The PdfTextAlignment represents the horizontal alignment of a text in PDF .

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);     
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat(PdfTextAlignment.Center)     
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

PdfStringFormat(PdfTextAlignment, PdfVerticalAlignment)

Initializes a new instance of the PdfStringFormat class with horizontal and vertical alignment

public PdfStringFormat(PdfTextAlignment alignment, PdfVerticalAlignment lineAlignment)

Parameters

alignment PdfTextAlignment

The PdfTextAlignment represents the horizontal alignment of a text in PDF .

lineAlignment PdfVerticalAlignment

The PdfVerticalAlignment represents the vertical alignment of a text in PDF

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);       
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle)    
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

PdfStringFormat(string)

Initializes a new instance of the PdfStringFormat class with column format

public PdfStringFormat(string columnFormat)

Parameters

columnFormat string

The column format.

Properties

Alignment

Gets or sets the horizontal text alignment

public PdfTextAlignment Alignment { get; set; }

Property Value

PdfTextAlignment

The PdfTextAlignment represents the horizontal alignment of a text in PDF

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

Default value: PdfTextAlignment.Left

CharacterSpacing

Gets or sets value that indicates a size among the characters in the text. When the glyph for each character in the string is rendered, this value is added to the glyph�s displacement.

public float CharacterSpacing { get; set; }

Property Value

float

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;       
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1       
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

Default value is 0.

ClipPath

Gets or sets a value indicating whether the text should be a part of the clipping path.

public bool ClipPath { get; set; }

Property Value

bool

true if ClipPath; otherwise, false.

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;
//Set clip path.
format.ClipPath = true;      
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1
'Set clip path.
format.ClipPath = True       
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

ComplexScript

Gets or sets the complex text layout rendering.

public bool ComplexScript { get; set; }

Property Value

bool

EnableBaseline

Gets or sets the baseline for line alignment.

public bool EnableBaseline { get; set; }

Property Value

bool

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 PdfTrueTypeFont(new Font("Tahoma",8), 8);
PdfFont font1 = new PdfTrueTypeFont(new Font("Calibri",20), 20);
PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica,16);
PdfFont font3 = new PdfTrueTypeFont(new Font("Arial",25), 25);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();           
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Bottom;
//Set baseline for line alignment
format.EnableBaseline = true;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new PointF(0, 50), format);
graphics.DrawString("Hello World!", font1, PdfBrushes.Black, new PointF(65, 50), format);
graphics.DrawString("Hello World!", font2, PdfBrushes.Black, new PointF(220, 50), format);
graphics.DrawString("Hello World!", font3, PdfBrushes.Black, new PointF(320, 50), 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 PdfTrueTypeFont(new Font("Tahoma",8), 8);
Dim font1 As PdfFont = New PdfTrueTypeFont(new Font("Calibri",20), 20);
Dim font2 As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica,16);
Dim font3 As PdfFont = New PdfTrueTypeFont(new Font("Arial",25), 25);
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Bottom;
'Set baseline for line alignment
format.EnableBaseline = true;
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New PointF(0, 50), format);
graphics.DrawString("Hello World!", font1, PdfBrushes.Black, New PointF(65, 50), format);
graphics.DrawString("Hello World!", font2, PdfBrushes.Black, New PointF(220, 50), format);
graphics.DrawString("Hello World!", font3, PdfBrushes.Black, New PointF(320, 50), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

EnableNewLineIndent

Gets or sets whether the new line indent is enabled or not.

public bool EnableNewLineIndent { get; set; }

Property Value

bool

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
//Set paragraph indent.
format.ParagraphIndent = 2.1f;
//Enable/Diable new line indent.
format.EnableNewLineIndent = false;     
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;      
'Set paragraph indent.
format.ParagraphIndent = 2.1F     
'Enable/Diable new line indent.
format.EnableNewLineIndent = False    
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

LineAlignment

Gets or sets the vertical text alignment.

public PdfVerticalAlignment LineAlignment { get; set; }

Property Value

PdfVerticalAlignment

The PdfVerticalAlignment represents the vertical alignment of a text in PDF

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

Default Value: PdfVerticalAlignment.Top

LineLimit

Gets or sets a value indicating whether [line limit].

public bool LineLimit { get; set; }

Property Value

bool

true if [line limit]; otherwise, false.

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;
//Set clip path.
format.ClipPath = true;
//Set line limit.
format.LineLimit = true;
//Set line spacing.
format.LineSpacing = 1.1f;
//Set measure trailing spaces.
format.MeasureTrailingSpaces = true;
//Set no clip
format.NoClip = true;
//Set paragraph indent.
format.ParagraphIndent = 2.1f;
//Set right to left.
format.RightToLeft = false;
//Set word spacing.
format.WordSpacing = 1.5f;
//Set word wrap type.
format.WordWrap = PdfWordWrapType.Word;
//Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1
'Set clip path.
format.ClipPath = True
'Set line limit.
format.LineLimit = True
'Set line spacing.
format.LineSpacing = 1.1F
'Set measure trailing spaces.
format.MeasureTrailingSpaces = True
'Set no clip
format.NoClip = True
'Set paragraph indent.
format.ParagraphIndent = 2.1F
'Set right to left.
format.RightToLeft = False
'Set word spacing.
format.WordSpacing = 1.5F
'Set word wrap type.
format.WordWrap = PdfWordWrapType.Word
'Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

LineSpacing

Gets or sets value that indicates the vertical distance between the baselines of adjacent lines of text.

public float LineSpacing { get; set; }

Property Value

float

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
//Set line spacing.
format.LineSpacing = 1.1f;      
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
'Set line spacing.
format.LineSpacing = 1.1F       
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

Default value is 0.

MeasureTiltingSpace

Gets or sets a value indicating whether [measure tilting space].

public bool MeasureTiltingSpace { get; set; }

Property Value

bool

true if [measure tilting space]; otherwise, false.

Examples

//Create the new PDF document
PdfDocument document = new PdfDocument();
//Add a page to the document
PdfPage page = document.Pages.Add();
// Load the font file from the stream
FileStream fontStream = new FileStream(@"font.ttf", FileMode.Open, FileAccess.Read);
//Create a new PDF font instance
PdfFont font = new PdfTrueTypeFont(fontStream, 14, PdfFontStyle.Italic);
//Create a new PDF string format instance
PdfStringFormat format = new PdfStringFormat();
//Enable a measure tilting space     
format.MeasureTiltingSpace = true;
string text = "Hello World!";
//Measure the tilted text
SizeF size = font.MeasureString(text, format);
//Creating the stream object
MemoryStream stream = new MemoryStream();
//Save the document as stream
document.Save(stream);
//Close the document
document.Close(true);
'Create the new PDF document
Dim document As PdfDocument = New PdfDocument()
'Add a page to the document
Dim page As PdfPage = document.Pages.Add()
'Load the font file from the stream
Dim fontStream As FileStream = New FileStream("font.ttf", FileMode.Open, FileAccess.Read)
'Create a new PDF font instance
Dim font As PdfFont = New PdfTrueTypeFont(fontStream, 14, PdfFontStyle.Italic)
'Create a new PDF string format instance
Dim format As PdfStringFormat = New PdfStringFormat()
'Enable a measure tilting space 
format.MeasureTiltingSpace = True
Dim text As String = "Hello World!"
'Measure the tilted text
Dim size As SizeF = font.MeasureString(text, format)
Dim stream As MemoryStream = New MemoryStream()
Save the document as stream
document.Save(stream)
Close the document
document.Close(True)

MeasureTrailingSpaces

Gets or sets a value indicating whether [measure trailing spaces].

public bool MeasureTrailingSpaces { get; set; }

Property Value

bool

true if [measure trailing spaces]; otherwise, false.

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;
//Set clip path.
format.ClipPath = true;
//Set line limit.
format.LineLimit = true;
//Set line spacing.
format.LineSpacing = 1.1f;
//Set measure trailing spaces.
format.MeasureTrailingSpaces = true;
//Set no clip
format.NoClip = true;
//Set paragraph indent.
format.ParagraphIndent = 2.1f;
//Set right to left.
format.RightToLeft = false;
//Set word spacing.
format.WordSpacing = 1.5f;
//Set word wrap type.
format.WordWrap = PdfWordWrapType.Word;
//Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1
'Set clip path.
format.ClipPath = True
'Set line limit.
format.LineLimit = True
'Set line spacing.
format.LineSpacing = 1.1F
'Set measure trailing spaces.
format.MeasureTrailingSpaces = True
'Set no clip
format.NoClip = True
'Set paragraph indent.
format.ParagraphIndent = 2.1F
'Set right to left.
format.RightToLeft = False
'Set word spacing.
format.WordSpacing = 1.5F
'Set word wrap type.
format.WordWrap = PdfWordWrapType.Word
'Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

NoClip

Gets or sets a value indicating whether [no clip].

public bool NoClip { get; set; }

Property Value

bool

true if [no clip]; otherwise, false.

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;
//Set clip path.
format.ClipPath = true;
//Set line limit.
format.LineLimit = true;
//Set line spacing.
format.LineSpacing = 1.1f;
//Set measure trailing spaces.
format.MeasureTrailingSpaces = true;
//Set no clip
format.NoClip = true;
//Set paragraph indent.
format.ParagraphIndent = 2.1f;
//Set right to left.
format.RightToLeft = false;
//Set word spacing.
format.WordSpacing = 1.5f;
//Set word wrap type.
format.WordWrap = PdfWordWrapType.Word;
//Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1
'Set clip path.
format.ClipPath = True
'Set line limit.
format.LineLimit = True
'Set line spacing.
format.LineSpacing = 1.1F
'Set measure trailing spaces.
format.MeasureTrailingSpaces = True
'Set no clip
format.NoClip = True
'Set paragraph indent.
format.ParagraphIndent = 2.1F
'Set right to left.
format.RightToLeft = False
'Set word spacing.
format.WordSpacing = 1.5F
'Set word wrap type.
format.WordWrap = PdfWordWrapType.Word
'Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

ParagraphIndent

Gets or sets the indent of the first line in the paragraph.

public float ParagraphIndent { get; set; }

Property Value

float

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
//Set paragraph indent.
format.ParagraphIndent = 2.1f;      
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;      
'Set paragraph indent.
format.ParagraphIndent = 2.1F      
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

SubSuperScript

Gets or sets value indicating whether the text is in subscript or superscript mode.

public PdfSubSuperScript SubSuperScript { get; set; }

Property Value

PdfSubSuperScript

The PdfSubSuperScript indicating whether the text is in subscript or superscript mode

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
//Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;      
'Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

TextDirection

Gets or sets the value that indicates text direction.

public PdfTextDirection TextDirection { get; set; }

Property Value

PdfTextDirection

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
format.TextDirection = PdfTextDirection.RightToLeft;       
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
'Set right to left.
format.TextDirection = PdfTextDirection.RightToLeft       
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

WordSpacing

Gets or sets value that indicates a size among the words in the text. Word spacing works the same way as character spacing but applies only to the space character, code 32.

public float WordSpacing { get; set; }

Property Value

float

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;        
//Set word spacing.
format.WordSpacing = 1.5f;        
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;       
'Set word spacing.
format.WordSpacing = 1.5F       
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Remarks

Default value is 0.

WordWrap

Gets or sets value indicating type of the text wrapping.

public PdfWordWrapType WordWrap { get; set; }

Property Value

PdfWordWrapType

The PdfWordWrapType indicating type of the text wrapping

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);
//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Set character spacing.
format.CharacterSpacing = 1;
//Set clip path.
format.ClipPath = true;
//Set line limit.
format.LineLimit = true;
//Set line spacing.
format.LineSpacing = 1.1f;
//Set measure trailing spaces.
format.MeasureTrailingSpaces = true;
//Set no clip
format.NoClip = true;
//Set paragraph indent.
format.ParagraphIndent = 2.1f;
//Set right to left.
format.RightToLeft = false;
//Set word spacing.
format.WordSpacing = 1.5f;
//Set word wrap type.
format.WordWrap = PdfWordWrapType.Word;
//Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript;
//Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, new RectangleF(0, 0, 200, 100), 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)
'Create a new PDF string format instance.
Dim format As PdfStringFormat = New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
'Set character spacing.
format.CharacterSpacing = 1
'Set clip path.
format.ClipPath = True
'Set line limit.
format.LineLimit = True
'Set line spacing.
format.LineSpacing = 1.1F
'Set measure trailing spaces.
format.MeasureTrailingSpaces = True
'Set no clip
format.NoClip = True
'Set paragraph indent.
format.ParagraphIndent = 2.1F
'Set right to left.
format.RightToLeft = False
'Set word spacing.
format.WordSpacing = 1.5F
'Set word wrap type.
format.WordWrap = PdfWordWrapType.Word
'Set sub/super script type.
format.SubSuperScript = PdfSubSuperScript.SubScript
'Draw string to PDF page.
graphics.DrawString("Hello World!", font, PdfBrushes.Black, New RectangleF(0, 0, 200, 100), format);
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)

Methods

Clone()

Clones the object.

public object Clone()

Returns

object

The new created object.

Examples

PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
//Clone the string format.
PdfStringFormat format1 = format.Clone() as PdfStringFormat;
'Create a new PDF string format instance.
Dim format As New PdfStringFormat()
'Set the text alignment.
format.Alignment = PdfTextAlignment.Center
'Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle
'Clone the string format.
Dim format1 As PdfStringFormat = TryCast(format.Clone(), PdfStringFormat)