Class PdfStringFormat
Represents the text layout information on PDF
Inheritance
Implements
Namespace: Syncfusion.Pdf.Graphics
Assembly: Syncfusion.Pdf.UWP.dll
Syntax
public sealed class PdfStringFormat : Object, ICloneable
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.
Declaration
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
Declaration
public PdfStringFormat(PdfTextAlignment alignment)
Parameters
Type | Name | Description |
---|---|---|
PdfTextAlignment | alignment | 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
Declaration
public PdfStringFormat(PdfTextAlignment alignment, PdfVerticalAlignment lineAlignment)
Parameters
Type | Name | Description |
---|---|---|
PdfTextAlignment | alignment | The PdfTextAlignment represents the horizontal alignment of a text in PDF . |
PdfVerticalAlignment | lineAlignment | 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
Declaration
public PdfStringFormat(string columnFormat)
Parameters
Type | Name | Description |
---|---|---|
System.String | columnFormat | The column format. |
Properties
Alignment
Gets or sets the horizontal text alignment
Declaration
public PdfTextAlignment Alignment { get; set; }
Property Value
Type | Description |
---|---|
PdfTextAlignment | The PdfTextAlignment represents the horizontal alignment of a text in PDF |
Remarks
Default value: PdfTextAlignment.Left
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)
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.
Declaration
public float CharacterSpacing { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value is 0.
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)
ClipPath
Gets or sets a value indicating whether the text should be a part of the clipping path.
Declaration
public bool ClipPath { get; set; }
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);
//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.
Declaration
public bool ComplexScript { get; set; }
Property Value
Type |
---|
System.Boolean |
EnableBaseline
Gets or sets the baseline for line alignment.
Declaration
public bool EnableBaseline { get; set; }
Property Value
Type |
---|
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 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.
Declaration
public bool EnableNewLineIndent { get; set; }
Property Value
Type |
---|
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);
//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.
Declaration
public PdfVerticalAlignment LineAlignment { get; set; }
Property Value
Type | Description |
---|---|
PdfVerticalAlignment | The PdfVerticalAlignment represents the vertical alignment of a text in PDF |
Remarks
Default Value: PdfVerticalAlignment.Top
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)
LineLimit
Gets or sets a value indicating whether [line limit].
Declaration
public bool LineLimit { get; set; }
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);
//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.
Declaration
public float LineSpacing { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value is 0.
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)
MeasureTiltingSpace
Gets or sets a value indicating whether [measure tilting space].
Declaration
public bool MeasureTiltingSpace { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
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].
Declaration
public bool MeasureTrailingSpaces { get; set; }
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);
//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].
Declaration
public bool NoClip { get; set; }
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);
//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.
Declaration
public float ParagraphIndent { get; set; }
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);
//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.
Declaration
public PdfSubSuperScript SubSuperScript { get; set; }
Property Value
Type | Description |
---|---|
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.
Declaration
public PdfTextDirection TextDirection { get; set; }
Property Value
Type |
---|
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.
Declaration
public float WordSpacing { get; set; }
Property Value
Type |
---|
System.Single |
Remarks
Default value is 0.
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)
WordWrap
Gets or sets value indicating type of the text wrapping.
Declaration
public PdfWordWrapType WordWrap { get; set; }
Property Value
Type | Description |
---|---|
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.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.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)