Docotic.Pdf Library Help > Samples > Text > Internationalization

This sample shows how to draw text in different languages.

Docotic.Pdf library can be used to draw text in any language. Note, that current canvas font should support characters in a text that is to be drawn.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class Internationalization
    {
        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.

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.FontSize = 12;

                canvas.Font = pdf.AddFont(PdfBuiltInFont.CourierBold);
                canvas.DrawString(10, 50, "Chinese(traditional): ");
                canvas.DrawString(10, 70, "Russian: ");
                canvas.DrawString(10, 90, "Portugal: ");

                // NOTE: PdfDocument.AddFont() overloads, which load font from the collection of system fonts,
                // are not supported in version for .NET Standard
                canvas.Font = pdf.AddFont("NSimSun");
                canvas.DrawString(180, 50, "????");
                canvas.Font.RemoveUnusedGlyphs();

                canvas.Font = pdf.AddFont("Times New Roman");
                canvas.DrawString(180, 70, "Ïðèâåò, ìèð");
                canvas.DrawString(180, 90, "Ola mundo");
                canvas.Font.RemoveUnusedGlyphs();

                pdf.Save("Internationalization.pdf");
            }

            Process.Start("Internationalization.pdf");
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Internationalization
        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.

            Using pdf As New PdfDocument()
                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas
                canvas.FontSize = 12

                canvas.Font = pdf.AddFont(PdfBuiltInFont.CourierBold)
                canvas.DrawString(10, 50, "Chinese(traditional): ")
                canvas.DrawString(10, 70, "Russian: ")
                canvas.DrawString(10, 90, "Portugal: ")

                ' NOTE: PdfDocument.AddFont() overloads, which load font from the collection of system fonts,
                ' are not supported in version for .NET Standard
                canvas.Font = pdf.AddFont("NSimSun")
                canvas.DrawString(180, 50, "????")
                canvas.Font.RemoveUnusedGlyphs()

                canvas.Font = pdf.AddFont("Times New Roman")
                canvas.DrawString(180, 70, "Ïðèâåò, ìèð")
                canvas.DrawString(180, 90, "Ola mundo")
                canvas.Font.RemoveUnusedGlyphs()

                pdf.Save("Internationalization.pdf")
            End Using

            Process.Start("Internationalization.pdf")
        End Sub
    End Class
End Namespace