VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging.Pdf.Drawing Namespace / PdfGraphics Class / DrawString Method / DrawString(String,PdfFont,Single,PdfBrush,Single,Single) Method
String to draw.
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont that defines the text format of the string.
Font size.
A PdfBrush that determines the color of the drawn text.
The x-coordinate of the bottom-left corner of the drawn text.
The y-coordinate of the bottom-left corner of the drawn text.
Example



In This Topic
    DrawString(String,PdfFont,Single,PdfBrush,Single,Single) Method
    In This Topic
    Draws the specified text string at the specified location with the specified PdfBrush and Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont objects.
    Syntax
    'Declaration
     
    Public Overloads Sub DrawString( _
       ByVal s As String, _
       ByVal font As PdfFont, _
       ByVal fontSize As Single, _
       ByVal brush As PdfBrush, _
       ByVal x As Single, _
       ByVal y As Single _
    ) 
    public void DrawString( 
       string s,
       PdfFont font,
       float fontSize,
       PdfBrush brush,
       float x,
       float y
    )
    public: void DrawString( 
       string* s,
       PdfFont* font,
       float fontSize,
       PdfBrush* brush,
       float x,
       float y
    ) 
    public:
    void DrawString( 
       String^ s,
       PdfFont^ font,
       float fontSize,
       PdfBrush^ brush,
       float x,
       float y
    ) 

    Parameters

    s
    String to draw.
    font
    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont that defines the text format of the string.
    fontSize
    Font size.
    brush
    A PdfBrush that determines the color of the drawn text.
    x
    The x-coordinate of the bottom-left corner of the drawn text.
    y
    The y-coordinate of the bottom-left corner of the drawn text.
    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
    This example 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: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also