Docotic.Pdf Library Help > Samples > Text > Text rendering mode

This sample shows how to specify text rendering mode using PdfCanvas.TextRenderingMode property.

The text rendering mode specifies whether drawing text causes glyph outlines to be stroked, filled, used as a clipping boundary, or some combination of the three.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class TextRenderingMode
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "TextRenderingMode.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                const string sampleText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                canvas.Pen.Color = new PdfRgbColor(255, 0, 0);
                canvas.Brush.Color = new PdfGrayColor(70);
                canvas.FontSize = 20;
                canvas.Pen.Width = 1;

                canvas.TextRenderingMode = PdfTextRenderingMode.FillAndStroke;
                canvas.DrawString(10, 50, sampleText);

                canvas.TextRenderingMode = PdfTextRenderingMode.Stroke;
                canvas.DrawString(10, 70, sampleText);

                canvas.TextRenderingMode = PdfTextRenderingMode.Fill;
                canvas.DrawString(10, 90, sampleText);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class TextRenderingMode
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "TextRenderingMode.pdf"

            Using pdf As New PdfDocument()

                Const sampleText As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas

                canvas.Pen.Color = New PdfRgbColor(255, 0, 0)
                canvas.Brush.Color = New PdfGrayColor(70)
                canvas.FontSize = 20
                canvas.Pen.Width = 1

                canvas.TextRenderingMode = PdfTextRenderingMode.FillAndStroke
                canvas.DrawString(10, 50, sampleText)

                canvas.TextRenderingMode = PdfTextRenderingMode.Stroke
                canvas.DrawString(10, 70, sampleText)

                canvas.TextRenderingMode = PdfTextRenderingMode.Fill
                canvas.DrawString(10, 90, sampleText)

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace