DrawString(String,PdfFont,Single,PdfBrush,PointF) Method (PdfGraphics)
In This Topic
Draws the specified text string at the specified location with the specified
PdfBrush and
PdfFont objects.
Syntax
'Declaration
Public Overloads Sub DrawString( _
ByVal As System.String, _
ByVal As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont, _
ByVal As Single, _
ByVal As PdfBrush, _
ByVal As System.Drawing.PointF _
)
public void DrawString(
System.String ,
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont ,
float ,
PdfBrush ,
System.Drawing.PointF
)
public: void DrawString(
System.String ,
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont* ,
float ,
PdfBrush* ,
System.Drawing.PointF
)
public:
void DrawString(
System.String ,
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont^ ,
float ,
PdfBrush^ ,
System.Drawing.PointF
)
Parameters
- s
- String to draw.
- font
- PdfFont that defines the text format of the string.
- fontSize
- Font size.
- brush
- A PdfBrush that determines the color of the drawn text.
- location
- System.Drawing.PointF structure that specifies the text location.
Remarks
This method ignores carriage returns and new line characters.
Use overloaded method that takes rectangle, instead of point that specifies location, if carriage returns and new line characters should NOT be ignored.
Example
Here is an example that shows how to add text (not transparent and transparent, not rotated and rotated) to a PDF page:
''' <summary>
''' Adds text (not transparent and transparent, not rotated and rotated) to a PDF page.
''' </summary>
''' <param name="pdfFilename">The PDF filename.</param>
Public Shared Sub AddTextToPdfPage(pdfFilename As String)
' create new PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_16)
' add empty page (A4 size)
Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4)
' get PdfGraphics for PDF page
Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = page.GetGraphics()
' create a font that should be used for drawing a text
Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
' draw NOT transparent and NOT rotated text on PDF page
Dim redBrush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Red)
g.DrawString("Not transparent text", font, 30, redBrush, New System.Drawing.PointF(50, 250))
' draw transparent and NOT rotated text on PDF page
Dim transparentRedBrush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.FromArgb(64, 255, 0, 0))
g.DrawString("Transparent text", font, 30, transparentRedBrush, New System.Drawing.PointF(50, 350))
' draw NOT transparent and rotated text on PDF page
Dim blueBrush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Blue)
g.SaveGraphicsState()
Dim m As New Vintasoft.Imaging.AffineMatrix()
' rotate at 30 degress around (X=50, Y=450) point
m.RotateAt(30, 50, 450)
g.MultiplyTransform(m)
g.DrawString("Rotated text", font, 30, blueBrush, New System.Drawing.PointF(50, 450))
g.RestoreGraphicsState()
End Using
' save changes in PDF document
document.SaveChanges()
End Using
End Sub
/// <summary>
/// Adds text (not transparent and transparent, not rotated and rotated) to a PDF page.
/// </summary>
/// <param name="pdfFilename">The PDF filename.</param>
public static void AddTextToPdfPage(string pdfFilename)
{
// create new PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_16))
{
// add empty page (A4 size)
Vintasoft.Imaging.Pdf.Tree.PdfPage page = document.Pages.Add(
Vintasoft.Imaging.PaperSizeKind.A4);
// get PdfGraphics for PDF page
using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = page.GetGraphics())
{
// create a font that should be used for drawing a text
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
// draw NOT transparent and NOT rotated text on PDF page
Vintasoft.Imaging.Pdf.Drawing.PdfBrush redBrush =
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Red);
g.DrawString("Not transparent text", font, 30, redBrush, new System.Drawing.PointF(50, 250));
// draw transparent and NOT rotated text on PDF page
Vintasoft.Imaging.Pdf.Drawing.PdfBrush transparentRedBrush =
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.FromArgb(64, 255, 0, 0));
g.DrawString("Transparent text", font, 30, transparentRedBrush, new System.Drawing.PointF(50, 350));
// draw NOT transparent and rotated text on PDF page
Vintasoft.Imaging.Pdf.Drawing.PdfBrush blueBrush =
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Blue);
g.SaveGraphicsState();
Vintasoft.Imaging.AffineMatrix m = new Vintasoft.Imaging.AffineMatrix();
// rotate at 30 degress around (X=50, Y=450) point
m.RotateAt(30, 50, 450);
g.MultiplyTransform(m);
g.DrawString("Rotated text", font, 30, blueBrush, new System.Drawing.PointF(50, 450));
g.RestoreGraphicsState();
}
// save changes in PDF document
document.SaveChanges();
}
}
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also