[]
        
(Showing Draft Content)

C1.C1Pdf.C1PdfDocument.DrawString

DrawString Method

DrawString(string, Font, Brush, RectangleF, int, StringFormat)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc, int firstChar, StringFormat sf)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF, firstChar As Integer, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

Brush object that defines the color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

int firstChar

Index of the first character that will be rendered.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

Remarks

The sf contains properties that specify formatting options. Use the Alignment property to specify horizontal alignment and the LineAlignment property to specify vertical alignment.

Use the FormatFlags property to specify clipping and wrapping.

To render text in the vertical direction, use the DirectionVertical. By itself, this flag will cause text to render from the bottom to the top of the rectangle. Combined with the DirectionRightToLeft flags, it will cause text to render from the top to the bottom of the rectangle.

The DrawString method returns the index of the first character that was not printed because it did not fit the output rectangle. You can use this value to make text flow from page to page, or from one frame to another within a page.

Examples

The code below renders a long string into several pages, using the return value from the DrawString method to determine where to continue printing.

// render string spanning multiple pages
for (int start = 0; start < int.MaxValue;)
{
	// render as much as will fit into the rectangle
	start = _c1pdf.DrawString(text, font, Brushes.Black, rcPage, start);

	// move on to the next page
	_c1pdf.NewPage();
}

DrawString(string, Font, Color, RectangleF, int, StringFormat)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc, int firstChar, StringFormat sf)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF, firstChar As Integer, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

int firstChar

Index of the first character that will be rendered.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, RectangleF, int, StringFormat, float)

Draws the specified text string in the specified rectangle, with the specified Brush and Font, using the formatting attributes of the specified StringFormat object and specified character width coefficient.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc, int firstChar, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF, firstChar As Integer, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

The string to draw.

Font font

The Font used to draw the text.

Brush brush

The Brush specifying the text color.

RectangleF rc

The rectangle specifying the location of the text, in points from the top left corner of the page.

int firstChar

The index of the first character that will be rendered.

StringFormat sf

The StringFormat object specifying the formatting attributes applied to the text.

float widthCoeff

The width coefficient applied to characters. The default is 1.0, use 2.0 for double width and so on.

Returns
Type Description
int

The index of the first character that was not rendered because it did not fit in the specified rectangle.

DrawString(string, Font, Color, RectangleF, int, StringFormat, float)

Draws the specified text string in the specified rectangle, with the specified Brush and Font, using the formatting attributes of the specified StringFormat object and specified character width coefficient.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc, int firstChar, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF, firstChar As Integer, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

The string to draw.

Font font

The Font used to draw the text.

Color color

The text color.

RectangleF rc

The rectangle specifying the location of the text, in points from the top left corner of the page.

int firstChar

The index of the first character that will be rendered.

StringFormat sf

The StringFormat object specifying the formatting attributes applied to the text.

float widthCoeff

The width coefficient applied to characters. The default is 1.0, use 2.0 for double width and so on.

Returns
Type Description
int

The index of the first character that was not rendered because it did not fit in the specified rectangle.

DrawString(string, Font, Color, RectangleF, StringFormat)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc, StringFormat sf)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, RectangleF, StringFormat)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc, StringFormat sf)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, RectangleF, StringFormat, float)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, RectangleF, StringFormat, float)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, RectangleF, int)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc, int firstChar)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF, firstChar As Integer) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

int firstChar

Index of the first character that will be rendered.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, RectangleF, int)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc, int firstChar)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF, firstChar As Integer) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

int firstChar

Index of the first character that will be rendered.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, RectangleF)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects.

Declaration
public int DrawString(string text, Font font, Color color, RectangleF rc)
Public Function DrawString(text As String, font As Font, color As Color, rc As RectangleF) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

Remarks

This overload renders strings aligned to the top left corner of the specified rectangle, wrapping text as needed within the rectangle, without clipping, and in the horizontal direction. To change any of these defaults, use the overload that allows you to specify a StringFormat parameter.

DrawString(string, Font, Brush, RectangleF)

Draws the specified text string in the specified rectangle with the specified Brush and Font objects.

Declaration
public int DrawString(string text, Font font, Brush brush, RectangleF rc)
Public Function DrawString(text As String, font As Font, brush As Brush, rc As RectangleF) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

RectangleF rc

The rectangle structure that specifies the location of the drawn text, in points from the top left corner of the page.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

Remarks

This overload renders strings aligned to the top left corner of the specified rectangle, wrapping text as needed within the rectangle, without clipping, and in the horizontal direction. To change any of these defaults, use the overload that allows you to specify a StringFormat parameter.

DrawString(string, Font, Color, PointF, StringFormat)

Draws the specified text string at the specified point with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Color color, PointF pt, StringFormat sf)
Public Function DrawString(text As String, font As Font, color As Color, pt As PointF, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, PointF, StringFormat)

Draws the specified text string at the specified point with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object.

Declaration
public int DrawString(string text, Font font, Brush brush, PointF pt, StringFormat sf)
Public Function DrawString(text As String, font As Font, brush As Brush, pt As PointF, sf As StringFormat) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, PointF, StringFormat, float)

Draws the specified text string at the specified point with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object and specified width coefficient of text characters.

Declaration
public int DrawString(string text, Font font, Color color, PointF pt, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, color As Color, pt As PointF, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, PointF, StringFormat, float)

Draws the specified text string at the specified point with the specified Brush and Font objects using the formatting attributes of the specified StringFormat object and specified width coefficient of text characters.

Declaration
public int DrawString(string text, Font font, Brush brush, PointF pt, StringFormat sf, float widthCoeff)
Public Function DrawString(text As String, font As Font, brush As Brush, pt As PointF, sf As StringFormat, widthCoeff As Single) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points

StringFormat sf

StringFormat object that specifies formatting attributes applied to the drawn text.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, PointF)

Draws the specified text string at the specified point with the specified Brush and Font objects.

Declaration
public int DrawString(string text, Font font, Color color, PointF pt)
Public Function DrawString(text As String, font As Font, color As Color, pt As PointF) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points from the top left corner of the page.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, PointF)

Draws the specified text string at the specified point with the specified Brush and Font objects.

Declaration
public int DrawString(string text, Font font, Brush brush, PointF pt)
Public Function DrawString(text As String, font As Font, brush As Brush, pt As PointF) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points from the top left corner of the page.

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Color, PointF, float)

Draws the specified text string at the specified point with the specified Brush, Font objects and specified width coefficient of text characters.

Declaration
public int DrawString(string text, Font font, Color color, PointF pt, float widthCoeff = 1)
Public Function DrawString(text As String, font As Font, color As Color, pt As PointF, Optional widthCoeff As Single = 1) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Color color

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points from the top left corner of the page.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0..

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.

DrawString(string, Font, Brush, PointF, float)

Draws the specified text string at the specified point with the specified Brush, Font objects and specified width coefficient of text characters.

Declaration
public int DrawString(string text, Font font, Brush brush, PointF pt, float widthCoeff = 1)
Public Function DrawString(text As String, font As Font, brush As Brush, pt As PointF, Optional widthCoeff As Single = 1) As Integer
Parameters
Type Name Description
string text

String to draw.

Font font

Font object that defines the appearance and size of the drawn text.

Brush brush

The object that defines the color of the drawn text.

PointF pt

The point structure that specifies the location of the drawn text, in points from the top left corner of the page.

float widthCoeff

The width coefficient of text characters, by default 1.0, for double width 2.0..

Returns
Type Description
int

The index of first character that was not printed because it did not fit in the specified rectangle.